@ -1,4 +1,6 @@
using System.Diagnostics ;
using System.IO.Compression ;
using System.IO.Compression ;
using System.Runtime.InteropServices ;
using AM2RPortHelperLib ;
using AM2RPortHelperLib ;
using UndertaleModLib ;
using UndertaleModLib ;
using Xunit ;
using Xunit ;
@ -204,6 +206,7 @@ public class RawModsTests : IDisposable
Assert . True ( origFiles . SequenceEqual ( newFiles ) ) ;
Assert . True ( origFiles . SequenceEqual ( newFiles ) ) ;
break ;
break ;
}
}
default : throw new Exception ( "unwritten test case for new os?" ) ;
}
}
// If we didn't specify any, there should be no subdirectories at the end
// If we didn't specify any, there should be no subdirectories at the end
@ -302,6 +305,7 @@ public class RawModsTests : IDisposable
Assert . True ( origFiles . SequenceEqual ( newFiles ) ) ;
Assert . True ( origFiles . SequenceEqual ( newFiles ) ) ;
break ;
break ;
}
}
default : throw new Exception ( "unwritten test case for new os?" ) ;
}
}
// There should be exactly one subdir here
// There should be exactly one subdir here
@ -317,37 +321,6 @@ public class RawModsTests : IDisposable
//Otherwise there should be our stuff
//Otherwise there should be our stuff
Assert . True ( File . Exists ( newExtract + "/assets/" + deepSuffix . ToLower ( ) + origInput . ToLower ( ) ) ) ;
Assert . True ( File . Exists ( newExtract + "/assets/" + deepSuffix . ToLower ( ) + origInput . ToLower ( ) ) ) ;
}
}
[Theory]
[InlineData("./GameWin.zip")]
[InlineData("./GameLin.zip")]
[InlineData("./GameMac.zip")]
public void CheckThatLinuxPortHasProperIcons ( string inputZip )
{
var outputZip = testTempDir + Guid . NewGuid ( ) ;
var newExtract = testTempDir + Guid . NewGuid ( ) + "/" ;
// With default icons
void CheckIconsWithPath ( string? path )
{
File . Delete ( outputZip ) ;
RawMods . PortToLinux ( inputZip , outputZip , path , path ) ;
if ( Directory . Exists ( newExtract ) )
Directory . Delete ( newExtract , true ) ;
ZipFile . ExtractToDirectory ( outputZip , newExtract ) ;
var newIcon = File . ReadAllBytes ( newExtract + "/assets/icon.png" ) ;
var newSplash = File . ReadAllBytes ( newExtract + "/assets/splash.png" ) ;
Directory . CreateDirectory ( libTempDir ) ;
var oldIcon = File . ReadAllBytes ( RawMods . GetProperPathToBuiltinIcons ( nameof ( Resources . icon ) , path ) ) ;
var oldSplash = File . ReadAllBytes ( RawMods . GetProperPathToBuiltinIcons ( nameof ( Resources . splash ) , path ) ) ;
Assert . True ( newIcon . SequenceEqual ( oldIcon ) ) ;
Assert . True ( newSplash . SequenceEqual ( oldSplash ) ) ;
}
CheckIconsWithPath ( null ) ;
CheckIconsWithPath ( inputZip ) ;
}
# endregion
# endregion
@ -459,6 +432,7 @@ public class RawModsTests : IDisposable
Assert . True ( origFiles . SequenceEqual ( newFiles ) ) ;
Assert . True ( origFiles . SequenceEqual ( newFiles ) ) ;
break ;
break ;
}
}
default : throw new Exception ( "unwritten test case for new os?" ) ;
}
}
// There should be exactly one subdir here and it should end with .app
// There should be exactly one subdir here and it should end with .app
@ -479,12 +453,235 @@ public class RawModsTests : IDisposable
Assert . True ( File . Exists ( newExtract + "/" + appDir . Name + "/Contents/Resources/" + deepSuffix . ToLower ( ) + origInput . ToLower ( ) ) ) ;
Assert . True ( File . Exists ( newExtract + "/" + appDir . Name + "/Contents/Resources/" + deepSuffix . ToLower ( ) + origInput . ToLower ( ) ) ) ;
}
}
# endregion
#region PortInvalidZips
[Theory]
[Theory]
[InlineData("./GameWin.zip")]
[InlineData(Core.ModOS.Windows)]
[InlineData("./GameLin.zip")]
[InlineData(Core.ModOS.Linux)]
[InlineData("./GameMac.zip")]
[InlineData(Core.ModOS.Mac)]
public void CheckThatMacPortHasProperIcons ( string inputZip )
[InlineData(Core.ModOS.Android)]
public void PortInvalidZipsToOS ( Core . ModOS os )
{
Action < string? , string? > function = os switch
{
Core . ModOS . Windows = > ( input , outputFile ) = > RawMods . PortToWindows ( input , outputFile ) ,
Core . ModOS . Linux = > ( input , outputFile ) = > RawMods . PortToLinux ( input , outputFile ) ,
Core . ModOS . Mac = > ( input , outputFile ) = > RawMods . PortToMac ( input , outputFile ) ,
Core . ModOS . Android = > ( input , outputFile ) = > RawMods . PortToAndroid ( input , outputFile ) ,
_ = > throw new Exception ( "This should not have happened! new unhandled data!" )
} ;
Assert . Throws < ArgumentNullException > ( ( ) = > function . Invoke ( null , "/foo" ) ) ;
Assert . Throws < FileNotFoundException > ( ( ) = > function . Invoke ( "/foo" , "/foo" ) ) ;
Assert . Throws < ArgumentOutOfRangeException > ( ( ) = > function . Invoke ( "./GameLin.zip" , null ) ) ;
}
# endregion
#region PortToAndroid
[Theory]
[InlineData("./GameWin.zip", false, false, false, false)]
[InlineData("./GameLin.zip", false, false, false, false)]
[InlineData("./GameMac.zip", false, false, false, false)]
[InlineData("./GameWin.zip", true, true, true, true)]
[InlineData("./GameLin.zip", true, true, true, true)]
[InlineData("./GameMac.zip", true, true, true, true)]
public void PortZipToAndroid ( string inputZip , bool useSubdirectories , bool createWorkingDirectoryBeforeHand , bool useCustomSave , bool useInternet )
{
{
var origMod = RawMods . GetModOSOfRawZip ( inputZip ) ;
var outputZip = testTempDir + Guid . NewGuid ( ) ;
var origExtract = testTempDir + Guid . NewGuid ( ) ;
var newExtract = testTempDir + Guid . NewGuid ( ) + "/" ;
var deepSuffix = "Foobar/Foobar/Foo/Blag/" ;
var origInput = inputZip ;
if ( useSubdirectories )
{
string archiveDeepSuffix = deepSuffix ;
if ( origMod = = Core . ModOS . Linux )
archiveDeepSuffix = "assets/" + deepSuffix ;
else if ( origMod = = Core . ModOS . Mac )
archiveDeepSuffix = "AM2R.app/Contents/Resources/" + deepSuffix ;
File . Copy ( inputZip , testTempDir + inputZip + "_modified" ) ;
inputZip = testTempDir + inputZip + "_modified" ;
using ZipArchive archive = ZipFile . Open ( inputZip , ZipArchiveMode . Update ) ;
archive . CreateEntry ( archiveDeepSuffix + origInput ) ;
}
if ( createWorkingDirectoryBeforeHand )
Directory . CreateDirectory ( libTempDir + Path . GetFileNameWithoutExtension ( inputZip ) ) ;
RawMods . PortToAndroid ( inputZip , outputZip , null , null , useCustomSave , useInternet ) ;
// HACK: STORE'd files aren't compressed, thus the compressed size is the same as the normal
using ( var archive = ZipFile . OpenRead ( outputZip ) )
{
var entry = archive . GetEntry ( "assets/coolsong.ogg" ) ;
Assert . Equal ( entry . Length , entry . CompressedLength ) ;
}
ZipFile . ExtractToDirectory ( inputZip , origExtract ) ;
ZipFile . ExtractToDirectory ( outputZip , newExtract ) ;
switch ( origMod )
{
case Core . ModOS . Windows :
{
// File contents should be same between the zips except for all files being lowered now, data file being different, runner+dll not existing now, and splash being new
var origFiles = new DirectoryInfo ( origExtract ) . GetFiles ( ) . Select ( f = > f . Name . ToLower ( ) ) . ToList ( ) ;
origFiles . Remove ( "am2r.exe" ) ;
origFiles . Remove ( "d3dx9_43.dll" ) ;
origFiles . Remove ( "data.win" ) ;
origFiles . Add ( "game.droid" ) ;
origFiles . Remove ( "am2r.exe" ) ;
origFiles . Add ( "splash.png" ) ;
origFiles . Sort ( ) ;
var newFiles = new DirectoryInfo ( newExtract + "/assets" ) . GetFiles ( ) . Select ( f = > f . Name ) . ToList ( ) ;
newFiles . Sort ( ) ;
Assert . True ( origFiles . SequenceEqual ( newFiles ) ) ;
break ;
}
case Core . ModOS . Linux :
{
// File contents should be same between the zips except for data file being different
var origFiles = new DirectoryInfo ( origExtract + "/assets" ) . GetFiles ( ) . Select ( f = > f . Name ) . ToList ( ) ;
origFiles . Remove ( "game.unx" ) ;
origFiles . Add ( "game.droid" ) ;
origFiles . Sort ( ) ;
var newFiles = new DirectoryInfo ( newExtract + "/assets" ) . GetFiles ( ) . Select ( f = > f . Name ) . ToList ( ) ;
newFiles . Sort ( ) ;
Assert . True ( origFiles . SequenceEqual ( newFiles ) ) ;
break ;
}
case Core . ModOS . Mac :
{
// File contents should be the same between the zips except for data file being different and extra mac files
var origFiles = new DirectoryInfo ( origExtract + "/AM2R.app/Contents/Resources" ) . GetFiles ( ) . Select ( f = > f . Name ) . ToList ( ) ;
origFiles . Remove ( "game.ios" ) ;
origFiles . Add ( "game.droid" ) ;
origFiles . Remove ( "gamecontrollerdb.txt" ) ;
origFiles . Remove ( "yoyorunner.config" ) ;
origFiles . Sort ( ) ;
var newFiles = new DirectoryInfo ( newExtract + "/assets" ) . GetFiles ( ) . Select ( f = > f . Name ) . ToList ( ) ;
newFiles . Sort ( ) ;
Assert . True ( origFiles . SequenceEqual ( newFiles ) ) ;
break ;
}
default : throw new Exception ( "unwritten test case for new os?" ) ;
}
// TODO: check save folder - probably needs to be done by decompiling again. If one does this, then the "useInternet" check below should also get redone
if ( useCustomSave )
{
}
// HACK: ugly af, but works
if ( useInternet )
{
Assert . Contains ( "