diff --git a/src/SMAPI/Mobile/FarmMigrationPatch.cs b/src/SMAPI/Mobile/FarmMigrationPatch.cs new file mode 100644 index 00000000..3de4ab42 --- /dev/null +++ b/src/SMAPI/Mobile/FarmMigrationPatch.cs @@ -0,0 +1,71 @@ +using System.IO; +using System.Reflection; +using Android.Support.V4.Provider; +using HarmonyLib; +using Java.IO; +using MonoMod.Utils; +using StardewModdingAPI; +using StardewValley; + +namespace System.Runtime.CompilerServices; + +public class FarmMigrationPatch +{ + public static void Apply() + { + var harmony = new Harmony("FarmMigrationPatch"); + + harmony.Patch( + original: typeof(StardewValley.MainActivity) + .GetMethod("DirectoryCopy", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static), + prefix: new HarmonyMethod(typeof(FarmMigrationPatch), nameof(DirectoryCopyPrefix)) + ); + } + + private static void DirectoryCopy(DocumentFile source, string dest, int depth) + { + if (!source.Exists()) return; + + if (source.IsDirectory) + { + if (!Directory.Exists(dest)) Directory.CreateDirectory(dest); + + DocumentFile[] array = source.ListFiles(); + foreach (DocumentFile documentFile in array) + { + if (depth == 0) + { + if (documentFile.IsDirectory) + { + if (documentFile.Name.Equals("Mods") || + documentFile.Name.Equals("smapi-internal") || + documentFile.Name.Equals("ErrorLogs")) + continue; + } + else + continue; + } + + string text = Path.Combine(dest, documentFile.Name); + if (!System.IO.File.Exists(text)) FarmMigrationPatch.DirectoryCopy(documentFile, text, depth + 1); + } + + return; + } + + Stream stream = SMainActivity.instance.ContentResolver.OpenInputStream(source.Uri); + FileOutputStream fileOutputStream = new FileOutputStream(dest); + byte[] array3 = new byte[1024]; + int num; + while ((num = stream.Read(array3)) > 0) fileOutputStream.Write(array3, 0, num); + + stream.Close(); + fileOutputStream.Close(); + } + + private static bool DirectoryCopyPrefix(DocumentFile source, string dest) + { + DirectoryCopy(source, dest, 0); + return false; + } +} diff --git a/src/SMAPI/SMainActivity.cs b/src/SMAPI/SMainActivity.cs index b7cb3746..f6b6555f 100644 --- a/src/SMAPI/SMainActivity.cs +++ b/src/SMAPI/SMainActivity.cs @@ -10,6 +10,7 @@ using StardewModdingAPI.Framework; using StardewValley; using System.Reflection; using System.Linq; +using System.Runtime.CompilerServices; using System.Threading.Tasks; using Android.Content; using Android.Support.V4.Provider; @@ -45,7 +46,7 @@ namespace StardewModdingAPI this.Window.SetFlags(WindowManagerFlags.Fullscreen, WindowManagerFlags.Fullscreen); this.Window.SetFlags(WindowManagerFlags.KeepScreenOn, WindowManagerFlags.KeepScreenOn); - // FarmMigrationPatch.Apply(); + FarmMigrationPatch.Apply(); SMainActivity.Instance = this; try @@ -178,8 +179,9 @@ namespace StardewModdingAPI Action ContinueGame = () => { this.Window.ClearFlags(WindowManagerFlags.NotTouchable); - this.IsDoingStorageMigration = false; - this.OnCreatePartTwo(); + SAlertDialogUtil.AlertMessage($"SMAPI migration is finished, please restart game to continue", "Confirm", + callback: type => { this.Finish(); }); + }; Task.Run(() => {