Initial logic fix

This commit is contained in:
ZaneYork 2023-04-05 23:05:23 +08:00 committed by zhiyang7
parent 2801638122
commit d9440155ca
11 changed files with 139 additions and 37 deletions

BIN
build/Mono.Cecil.dll Normal file

Binary file not shown.

BIN
build/Newtonsoft.Json.dll Normal file

Binary file not shown.

BIN
build/Pintail.dll Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
build/TMXTile.dll Normal file

Binary file not shown.

View File

@ -34,7 +34,7 @@
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<AndroidUseSharedRuntime>false</AndroidUseSharedRuntime> <AndroidUseSharedRuntime>false</AndroidUseSharedRuntime>
<AndroidLinkMode>None</AndroidLinkMode> <AndroidLinkMode>SdkOnly</AndroidLinkMode>
<EmbedAssembliesIntoApk>True</EmbedAssembliesIntoApk> <EmbedAssembliesIntoApk>True</EmbedAssembliesIntoApk>
<AndroidManagedSymbols>false</AndroidManagedSymbols> <AndroidManagedSymbols>false</AndroidManagedSymbols>
<AndroidUseAapt2>true</AndroidUseAapt2> <AndroidUseAapt2>true</AndroidUseAapt2>
@ -84,19 +84,19 @@
<Reference Include="Mono.Security" /> <Reference Include="Mono.Security" />
<ProjectReference Include="..\SMAPI\SMAPI.csproj" /> <ProjectReference Include="..\SMAPI\SMAPI.csproj" />
<Reference Include="StardewValley"> <Reference Include="StardewValley">
<HintPath>..\..\..\Downloads\StardewValleyAndroidStuff\base_1.5.6.31\assemblies\StardewValley.dll</HintPath> <HintPath>..\..\..\Downloads\StardewValleyAndroidStuff\base_1.5.6.39\assemblies\StardewValley.dll</HintPath>
</Reference> </Reference>
<Reference Include="StardewValley.GameData"> <Reference Include="StardewValley.GameData">
<HintPath>..\..\..\Downloads\StardewValleyAndroidStuff\base_1.5.6.31\assemblies\StardewValley.GameData.dll</HintPath> <HintPath>..\..\..\Downloads\StardewValleyAndroidStuff\base_1.5.6.39\assemblies\StardewValley.GameData.dll</HintPath>
</Reference> </Reference>
<Reference Include="xTile"> <Reference Include="xTile">
<HintPath>..\..\..\Downloads\StardewValleyAndroidStuff\base_1.5.6.31\assemblies\xTile.dll</HintPath> <HintPath>..\..\..\Downloads\StardewValleyAndroidStuff\base_1.5.6.39\assemblies\xTile.dll</HintPath>
</Reference> </Reference>
<Reference Include="BmFont"> <Reference Include="BmFont">
<HintPath>..\..\..\Downloads\StardewValleyAndroidStuff\base_1.5.6.31\assemblies\BmFont.dll</HintPath> <HintPath>..\..\..\Downloads\StardewValleyAndroidStuff\base_1.5.6.39\assemblies\BmFont.dll</HintPath>
</Reference> </Reference>
<Reference Include="MonoGame.Framework"> <Reference Include="MonoGame.Framework">
<HintPath>..\..\..\Downloads\StardewValleyAndroidStuff\base_1.5.6.31\assemblies\MonoGame.Framework.dll</HintPath> <HintPath>..\..\..\Downloads\StardewValleyAndroidStuff\base_1.5.6.39\assemblies\MonoGame.Framework.dll</HintPath>
</Reference> </Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />

View File

@ -30,13 +30,13 @@
<ItemGroup> <ItemGroup>
<Reference Include="MonoGame.Framework"> <Reference Include="MonoGame.Framework">
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\Downloads\StardewValleyAndroidStuff\base_1.5.6.31\assemblies\MonoGame.Framework.dll</HintPath> <HintPath>..\..\..\Downloads\StardewValleyAndroidStuff\base_1.5.6.39\assemblies\MonoGame.Framework.dll</HintPath>
</Reference> </Reference>
<Reference Include="StardewModdingAPI"> <Reference Include="StardewModdingAPI">
<HintPath>..\SMAPI\bin\Debug\StardewModdingAPI.dll</HintPath> <HintPath>..\SMAPI\bin\Debug\StardewModdingAPI.dll</HintPath>
</Reference> </Reference>
<Reference Include="StardewValley"> <Reference Include="StardewValley">
<HintPath>..\..\..\Downloads\StardewValleyAndroidStuff\base_1.5.6.31\assemblies\StardewValley.dll</HintPath> <HintPath>..\..\..\Downloads\StardewValleyAndroidStuff\base_1.5.6.39\assemblies\StardewValley.dll</HintPath>
</Reference> </Reference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@ -118,22 +118,22 @@
<ItemGroup Condition="$(DefineConstants.Contains('ANDROID_TARGET_GOOGLE'))"> <ItemGroup Condition="$(DefineConstants.Contains('ANDROID_TARGET_GOOGLE'))">
<Reference Include="StardewValley"> <Reference Include="StardewValley">
<HintPath>..\..\..\Downloads\StardewValleyAndroidStuff\base_1.5.6.31\assemblies\StardewValley.dll</HintPath> <HintPath>..\..\..\Downloads\StardewValleyAndroidStuff\base_1.5.6.39\assemblies\StardewValley.dll</HintPath>
</Reference> </Reference>
<Reference Include="StardewValley.GameData"> <Reference Include="StardewValley.GameData">
<HintPath>..\..\..\Downloads\StardewValleyAndroidStuff\base_1.5.6.31\assemblies\StardewValley.GameData.dll</HintPath> <HintPath>..\..\..\Downloads\StardewValleyAndroidStuff\base_1.5.6.39\assemblies\StardewValley.GameData.dll</HintPath>
</Reference> </Reference>
<Reference Include="xTile"> <Reference Include="xTile">
<HintPath>..\..\..\Downloads\StardewValleyAndroidStuff\base_1.5.6.31\assemblies\xTile.dll</HintPath> <HintPath>..\..\..\Downloads\StardewValleyAndroidStuff\base_1.5.6.39\assemblies\xTile.dll</HintPath>
</Reference> </Reference>
<Reference Include="BmFont"> <Reference Include="BmFont">
<HintPath>..\..\..\Downloads\StardewValleyAndroidStuff\base_1.5.6.31\assemblies\BmFont.dll</HintPath> <HintPath>..\..\..\Downloads\StardewValleyAndroidStuff\base_1.5.6.39\assemblies\BmFont.dll</HintPath>
</Reference> </Reference>
</ItemGroup> </ItemGroup>
<ItemGroup Condition="'$(BUILD_FOR_MOBILE)' != ''"> <ItemGroup Condition="'$(BUILD_FOR_MOBILE)' != ''">
<Reference Include="MonoGame.Framework"> <Reference Include="MonoGame.Framework">
<HintPath>..\..\..\Downloads\StardewValleyAndroidStuff\base_1.5.6.31\assemblies\MonoGame.Framework.dll</HintPath> <HintPath>..\..\..\Downloads\StardewValleyAndroidStuff\base_1.5.6.39\assemblies\MonoGame.Framework.dll</HintPath>
</Reference> </Reference>
<Reference Include="mscorlib" /> <Reference Include="mscorlib" />

View File

@ -5,14 +5,20 @@ using Android.OS;
using Android.Views; using Android.Views;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using StardewModdingAPI.Framework; using StardewModdingAPI.Framework;
using StardewValley; using StardewValley;
using System.Reflection; using System.Reflection;
using System.Linq; using System.Linq;
using System.Threading.Tasks;
using Android.Content;
using Android.Support.V4.Provider;
using Java.IO;
using File = Java.IO.File; using File = Java.IO.File;
using Newtonsoft.Json; using Newtonsoft.Json;
using Java.Lang; using Java.Lang;
using Java.Util; using Java.Util;
using Bundle = Android.OS.Bundle;
using Exception = System.Exception; using Exception = System.Exception;
using Thread = System.Threading.Thread; using Thread = System.Threading.Thread;
@ -28,15 +34,13 @@ namespace StardewModdingAPI
private System.Action _callback; private System.Action _callback;
private static bool ErrorDetected; private static bool ErrorDetected;
private static bool Migrating = false;
protected override void OnCreate(Bundle bundle) protected override void OnCreate(Bundle bundle)
{ {
MainActivity.instance = this; MainActivity.instance = this;
base.RequestWindowFeature(WindowFeatures.NoTitle); base.RequestWindowFeature(WindowFeatures.NoTitle);
if (Build.VERSION.SdkInt >= BuildVersionCodes.P) if (Build.VERSION.SdkInt >= BuildVersionCodes.P) this.Window.Attributes.LayoutInDisplayCutoutMode = LayoutInDisplayCutoutMode.ShortEdges;
{
this.Window.Attributes.LayoutInDisplayCutoutMode = LayoutInDisplayCutoutMode.ShortEdges;
}
this.Window.SetFlags(WindowManagerFlags.Fullscreen, WindowManagerFlags.Fullscreen); this.Window.SetFlags(WindowManagerFlags.Fullscreen, WindowManagerFlags.Fullscreen);
this.Window.SetFlags(WindowManagerFlags.KeepScreenOn, WindowManagerFlags.KeepScreenOn); this.Window.SetFlags(WindowManagerFlags.KeepScreenOn, WindowManagerFlags.KeepScreenOn);
@ -46,7 +50,6 @@ namespace StardewModdingAPI
{ {
File errorLog = this.FilesDir.ListFiles().FirstOrDefault(f => f.IsDirectory && f.Name == "error")?.ListFiles().FirstOrDefault(f => f.Name.EndsWith(".dat")); File errorLog = this.FilesDir.ListFiles().FirstOrDefault(f => f.IsDirectory && f.Name == "error")?.ListFiles().FirstOrDefault(f => f.Name.EndsWith(".dat"));
if (errorLog != null) if (errorLog != null)
{
try try
{ {
Handler handler = new Handler((msg) => throw new RuntimeException()); Handler handler = new Handler((msg) => throw new RuntimeException());
@ -68,7 +71,6 @@ namespace StardewModdingAPI
catch (Exception) catch (Exception)
{ {
} }
}
} }
catch catch
{ {
@ -83,6 +85,8 @@ namespace StardewModdingAPI
{ {
try try
{ {
if (!this.CheckSMAPIMigration()) return;
new SGameConsole(); new SGameConsole();
Program.Main(null); Program.Main(null);
@ -95,10 +99,7 @@ namespace StardewModdingAPI
Constants.RewriteMissing = settings.RewriteMissing; Constants.RewriteMissing = settings.RewriteMissing;
} }
if (string.IsNullOrWhiteSpace(modPath)) if (string.IsNullOrWhiteSpace(modPath)) modPath = "Mods";
{
modPath = "Mods";
}
this.core = new SCore(System.IO.Path.Combine(EarlyConstants.StardewValleyBasePath, modPath), false, false); this.core = new SCore(System.IO.Path.Combine(EarlyConstants.StardewValleyBasePath, modPath), false, false);
this.core.RunInteractively(); this.core.RunInteractively();
@ -129,7 +130,120 @@ namespace StardewModdingAPI
} }
} }
public void PromptForPermissionsIfNecessary(System.Action callback = null) private void ShowMigrationPicker()
{
Intent intent = new Intent("android.intent.action.OPEN_DOCUMENT_TREE");
intent.AddFlags(ActivityFlags.GrantReadUriPermission);
this.StartActivityForResult(intent, 1235);
}
public bool CheckSMAPIMigration()
{
string storagePath = this.GetExternalFilesDir(null).AbsolutePath;
if (Migrating) return false;
if (Directory.Exists(storagePath + "/smapi-internal"))
return true;
Migrating = true;
SAlertDialogUtil.AlertMessage($"SMAPI needs to locate StardewValley folder's content to continue", "Confirm",
callback: type => { this.ShowMigrationPicker(); });
return false;
}
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
base.OnActivityResult(requestCode, resultCode, data);
if (requestCode != 1235)
return;
this.RunOnUiThread((System.Action)(() =>
{
if (resultCode == Result.Ok)
this.CopySMAPIData(data.Data);
else
this.CheckSMAPIMigration();
}));
}
private void CopySMAPIData(Android.Net.Uri folderUri)
{
if (!folderUri.LastPathSegment.EndsWith(":StardewValley"))
this.CheckSMAPIMigration();
else
{
Android.Content.Context context = Application.Context;
string storagePath = context.GetExternalFilesDir(null).AbsolutePath;
this.Window.SetFlags(WindowManagerFlags.NotTouchable, WindowManagerFlags.NotTouchable);
System.Action ContinueGame = () =>
{
this.Window.ClearFlags(WindowManagerFlags.NotTouchable);
this.IsDoingStorageMigration = false;
this.OnCreatePartTwo();
};
Task.Run(() =>
{
try
{
DocumentFile source = DocumentFile.FromTreeUri(context, folderUri);
if (!source.Exists())
return;
if (source.IsDirectory)
{
if (!Directory.Exists(storagePath))
Directory.CreateDirectory(storagePath);
foreach (DocumentFile listFile in source.ListFiles())
{
string destPath;
if (listFile.IsDirectory)
{
if (listFile.Name.StartsWith("smapi-internal") || listFile.Name.StartsWith("ErrorLogs") || listFile.Name.StartsWith("Mods"))
destPath = Path.Combine(storagePath, listFile.Name);
else
destPath = Path.Combine(storagePath, "/Saves", listFile.Name);
if (!System.IO.File.Exists(destPath)) SMainActivity.DirectoryCopy(listFile, destPath);
}
}
}
}
catch (System.Exception ex)
{
string exMessage = ex.Message;
}
this.RunOnUiThread(ContinueGame);
});
}
}
private static void DirectoryCopy(DocumentFile source, string dest)
{
if (!source.Exists())
return;
if (source.IsDirectory)
{
if (!Directory.Exists(dest))
Directory.CreateDirectory(dest);
foreach (DocumentFile listFile in source.ListFiles())
{
string str = Path.Combine(dest, listFile.Name);
if (!System.IO.File.Exists(str))
DirectoryCopy(listFile, str);
}
}
else
{
Stream stream = MainActivity.instance.ContentResolver.OpenInputStream(source.Uri);
FileOutputStream fileOutputStream = new FileOutputStream(dest);
byte[] numArray = new byte[1024];
int len;
while ((len = stream.Read((Span<byte>)numArray)) > 0)
fileOutputStream.Write(numArray, 0, len);
stream.Close();
fileOutputStream.Close();
}
}
public new void PromptForPermissionsIfNecessary(System.Action callback = null)
{ {
if (this.HasPermissions) if (this.HasPermissions)
{ {
@ -150,13 +264,9 @@ namespace StardewModdingAPI
{ {
this.LogPermissions(); this.LogPermissions();
if (this.HasPermissions) if (this.HasPermissions)
{
this.OnCreatePartTwo(); this.OnCreatePartTwo();
}
else else
{
this.PromptForPermissionsWithReasonFirst(); this.PromptForPermissionsWithReasonFirst();
}
} }
private string[] requiredPermissions => new string[4] private string[] requiredPermissions => new string[4]
@ -174,10 +284,8 @@ namespace StardewModdingAPI
List<string> stringList = new List<string>(); List<string> stringList = new List<string>();
string[] requiredPermissions = this.requiredPermissions; string[] requiredPermissions = this.requiredPermissions;
for (int index = 0; index < requiredPermissions.Length; ++index) for (int index = 0; index < requiredPermissions.Length; ++index)
{
if (this.PackageManager.CheckPermission(requiredPermissions[index], this.PackageName) != Permission.Granted) if (this.PackageManager.CheckPermission(requiredPermissions[index], this.PackageName) != Permission.Granted)
stringList.Add(requiredPermissions[index]); stringList.Add(requiredPermissions[index]);
}
return stringList.ToArray(); return stringList.ToArray();
} }
@ -204,9 +312,7 @@ namespace StardewModdingAPI
string languageCode = Locale.Default.Language.Substring(0, 2); string languageCode = Locale.Default.Language.Substring(0, 2);
int num = 0; int num = 0;
if (requestCode == 0) if (requestCode == 0)
{
for (int index = 0; index < grantResults.Length; ++index) for (int index = 0; index < grantResults.Length; ++index)
{
if (grantResults[index] == Permission.Granted) if (grantResults[index] == Permission.Granted)
++num; ++num;
else if (grantResults[index] == Permission.Denied) else if (grantResults[index] == Permission.Denied)
@ -214,20 +320,16 @@ namespace StardewModdingAPI
this.PromptForPermissions(); this.PromptForPermissions();
return; return;
} }
}
}
if (num != permissions.Length) if (num != permissions.Length)
return; return;
if (this._callback != null) if (this._callback != null)
{ {
this._callback(); this._callback();
this._callback = (System.Action)null; this._callback = null;
} }
else else
{
this.OnCreatePartTwo(); this.OnCreatePartTwo();
}
} }
} }
} }