Skip to content

Commit

Permalink
Merge pull request #18 from SerGreen/mi-a2-crashes
Browse files Browse the repository at this point in the history
Fix #16 crashes on some devices after puzzle skip
  • Loading branch information
SerGreen authored Jul 20, 2021
2 parents 37eb366 + c684915 commit d17e0a8
Show file tree
Hide file tree
Showing 13 changed files with 270 additions and 93 deletions.
28 changes: 28 additions & 0 deletions TWP Android/ActivityMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Android.Content.PM;
using Android.OS;
using Android.Views;
using System;
using TWP_Shared;

namespace TWP_Android
Expand All @@ -20,10 +21,37 @@ public class ActivityMain : Microsoft.Xna.Framework.AndroidGameActivity
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);

Android.Runtime.AndroidEnvironment.UnhandledExceptionRaiser += AndroidExceptionHandler;

var g = new TWPGame();
SetContentView((View) g.Services.GetService(typeof(View)));

g.Run();
}


#region Error handling
void AndroidExceptionHandler(object sender, Android.Runtime.RaiseThrowableEventArgs e)
{
e.Handled = true;
ShowMessageBox(
"Fatal Error",
e.Exception.Message + "\n\n" + e.Exception.StackTrace,
new EventHandler<Android.Content.DialogClickEventArgs>((sender, args) => { Android.OS.Process.KillProcess(Android.OS.Process.MyPid()); })
);
}

private void ShowMessageBox(string caption, string message, EventHandler<Android.Content.DialogClickEventArgs> buttonClickHandler = null)
{
new AlertDialog.Builder(this)
.SetNeutralButton("Close", buttonClickHandler)
.SetMessage(message)
.SetTitle(caption)
.Show();
}
#endregion

}
}

4 changes: 2 additions & 2 deletions TWP Android/Properties/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.sergreen.thewitnesspuzzles" android:versionName="1.0.9" android:installLocation="preferExternal" android:versionCode="9">
<uses-sdk android:targetSdkVersion="28" />
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.sergreen.thewitnesspuzzles" android:versionName="1.0.10" android:installLocation="preferExternal" android:versionCode="11">
<uses-sdk android:targetSdkVersion="29" />
<application android:label="The Witness Puzzles" android:icon="@drawable/Icon"></application>
</manifest>
22 changes: 18 additions & 4 deletions TWP Android/TWP Android.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\Xamarin.Legacy.OpenTK.1.0.0\build\Xamarin.Legacy.OpenTK.props" Condition="Exists('..\packages\Xamarin.Legacy.OpenTK.1.0.0\build\Xamarin.Legacy.OpenTK.props')" />
<Import Project="$(MSBuildExtensionsPath)\MonoGame\v3.0\MonoGame.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\MonoGame\v3.0\MonoGame.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
Expand All @@ -19,14 +20,16 @@
<AndroidSupportedAbis>armeabi-v7a%3bx86</AndroidSupportedAbis>
<AndroidStoreUncompressedFileExtensions>.m4a</AndroidStoreUncompressedFileExtensions>
<MandroidI18n />
<TargetFrameworkVersion>v9.0</TargetFrameworkVersion>
<TargetFrameworkVersion>v10.0</TargetFrameworkVersion>
<MonoGamePlatform>Android</MonoGamePlatform>
<AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
<AndroidUseLatestPlatformSdk>false</AndroidUseLatestPlatformSdk>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<DebugType>portable</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\$(MonoGamePlatform)\$(Platform)\$(Configuration)\</OutputPath>
<DefineConstants>DEBUG;TRACE;ANDROID</DefineConstants>
Expand All @@ -45,7 +48,7 @@
</AndroidSigningStorePass>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<DebugType>portable</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\$(MonoGamePlatform)\$(Platform)\$(Configuration)\</OutputPath>
<DefineConstants>TRACE;ANDROID</DefineConstants>
Expand All @@ -58,11 +61,15 @@
<BundleAssemblies>false</BundleAssemblies>
<AndroidLinkSkip>
</AndroidLinkSkip>
<AndroidEnableProfiledAot>false</AndroidEnableProfiledAot>
<AndroidKeyStore>false</AndroidKeyStore>
<AndroidSigningKeyStore>
</AndroidSigningKeyStore>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>
<ItemGroup>
<Reference Include="Mono.Android" />
<Reference Include="mscorlib" />
<Reference Include="OpenTK-1.0" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
Expand All @@ -77,6 +84,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
<None Include="Resources\AboutResources.txt" />
<None Include="Assets\AboutAssets.txt" />
</ItemGroup>
Expand Down Expand Up @@ -111,6 +119,12 @@
<Import Project="..\TWP Shared\TWP Shared.projitems" Label="Shared" />
<Import Project="$(MSBuildExtensionsPath)\Novell\Novell.MonoDroid.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath)\MonoGame\v3.0\MonoGame.Content.Builder.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Xamarin.Legacy.OpenTK.1.0.0\build\Xamarin.Legacy.OpenTK.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Xamarin.Legacy.OpenTK.1.0.0\build\Xamarin.Legacy.OpenTK.props'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
4 changes: 4 additions & 0 deletions TWP Android/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Xamarin.Legacy.OpenTK" version="1.0.0" targetFramework="monoandroid10.0" />
</packages>
6 changes: 3 additions & 3 deletions TWP Desktop/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyDescription("Puzzle game, inspired by Jonathan Blow's game 'The Witness'")]
[assembly: AssemblyCompany("SerGreen")]
[assembly: AssemblyCopyright("SerGreen - 2017")]
[assembly: AssemblyCopyright("SerGreen - 2017-2021")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand All @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.9.0")]
[assembly: AssemblyFileVersion("1.0.9.0")]
[assembly: AssemblyVersion("1.0.10.0")]
[assembly: AssemblyFileVersion("1.0.10.0")]
13 changes: 9 additions & 4 deletions TWP Shared/GameScreens/AboutGameScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class AboutGameScreen : GameScreen

SpriteFont fntBig, fntSmall;
Texture2D texPixel;

string[] text =
{
"DISCLAIMER",
Expand All @@ -32,9 +32,14 @@ public class AboutGameScreen : GameScreen
"All rights to The Witness and its sound assets ",
"belong to Jonathan Blow and Thekla Inc.",
"",
"SerGreen 2017-2020",
"v1.0.9"
};
"SerGreen 2017-2021",
"v" +
#if WINDOWS
System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(3)
#else
Android.App.Application.Context.PackageManager.GetPackageInfo(Android.App.Application.Context.PackageName, 0).VersionName
#endif
};
Rectangle textArea;
int lineHeight;
float textScale;
Expand Down
40 changes: 40 additions & 0 deletions TWP Shared/Support Classes/Storage/ExternalStorage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security;
using System.Security.Permissions;
using System.Text;

namespace TWP_Shared
{
public class ExternalStorage : IStorageProvider
{
private readonly string BASE_DIR;

public ExternalStorage()
{
#if WINDOWS
BASE_DIR = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "My Games", "TWP");
#else
//BASE_DIR = Path.Combine(Android.OS.Environment.ExternalStorageDirectory.Path, "TWP");
BASE_DIR = Android.App.Application.Context.GetExternalFilesDir(null).AbsolutePath;
#endif
}

public bool FileExists(string path) => File.Exists(Path.Combine(BASE_DIR, path));
public bool DirectoryExists(string path) => Directory.Exists(Path.Combine(BASE_DIR, path));
public void CreateDirectory(string path) => Directory.CreateDirectory(Path.Combine(BASE_DIR, path));

public FileStream OpenFile(string path, FileMode mode) => File.Open(Path.Combine(BASE_DIR, path), mode);
public void MoveFile(string sourcePath, string destinationPath) => File.Move(Path.Combine(BASE_DIR, sourcePath), Path.Combine(BASE_DIR, destinationPath));
public void DeleteFile(string path) => File.Delete(Path.Combine(BASE_DIR, path));

public string[] GetFileNames(string searchPattern)
{
string[] files = Directory.GetFiles(BASE_DIR, searchPattern);
Array.Sort<string>(files, (a, b) => File.GetLastWriteTimeUtc(b).CompareTo(File.GetLastWriteTimeUtc(a)));
return files.Select(x => Path.GetFileName(x)).ToArray();
}
}
}
Loading

0 comments on commit d17e0a8

Please sign in to comment.