Skip to content

Commit

Permalink
Merge pull request #61 from kylefmohr/osx-python-fixes
Browse files Browse the repository at this point in the history
Fix a couple OSX/Linux issues, remove dependency on Python
  • Loading branch information
blake502 authored May 5, 2024
2 parents 5535d96 + 1458c0d commit 70647de
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 71 deletions.
16 changes: 0 additions & 16 deletions balatro-mobile-maker/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,4 @@ internal static class Constants
public const string SevenzipOSXLink = "https://www.7-zip.org/a/7z2403-mac.tar.xz";


//Python Links
//Win (Embedded)
public const string PythonWinX64Link = "https://www.python.org/ftp/python/3.12.3/python-3.12.3-embed-amd64.zip";
public const string PythonWinX86Link = "https://www.python.org/ftp/python/3.12.3/python-3.12.3-embed-win32.zip";
public const string PythonWinArm64Link = "https://www.python.org/ftp/python/3.12.3/python-3.12.3-embed-arm64.zip";
//TODO: Multiplatform Python


public const string PythonScript =
@"import zipfile
existing_zip = zipfile.ZipFile('balatro-base.zip', 'a')
new_file_path = 'game.love'
existing_zip.write(new_file_path, arcname='Payload/Balatro.app/game.love')
existing_zip.close()";


}
52 changes: 13 additions & 39 deletions balatro-mobile-maker/Platform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,23 @@ public static void useSevenZip(string args)
if (isOSX)
{
if (!fileExists("7zz"))
{
RunCommand("tar", "-xf 7zip.tar.xz");
RunCommand("chmod", "+x 7zz");
}

RunCommand("7zz", args);
RunCommand("./7zz", args);
}

if (isLinux)
{
if (!fileExists("7zzs"))
{
RunCommand("tar", "-xf 7zip.tar.xz");
RunCommand("chmod", "+x 7zzs");
}

RunCommand("7zzs", args);
RunCommand("./7zzs", args);
}
}

Expand Down Expand Up @@ -146,19 +152,6 @@ public static void useOpenJDK(string args)
}
}

//Uses Python with args
public static void usePython(string args)
{
if (isWindows)
RunCommand("python\\python.exe", args);

//TODO: Don't assume python is already installed and in the system path!!!
if (isOSX)
RunCommand("python", args);

if (isLinux)
RunCommand("python", args);
}
public static string getOpenJDKDownloadLink()
{
if (isWindows)
Expand Down Expand Up @@ -192,25 +185,6 @@ public static string getOpenJDKDownloadLink()
return "";
}

public static string getPythonDownloadLink()
{
if (isWindows)
{
if (isX64)
return Constants.PythonWinX64Link;
if (isX86) //May not be supported, but included for now
return Constants.PythonWinX86Link;
if (isArm64)
return Constants.PythonWinArm64Link;
}

//TODO: Download Python!!! At the moment, we're assuming OSX and Linux users already have Python installed, and in their path.
if (isOSX) { /*...*/ }

if (isLinux) { /*...*/ }

return "";
}

public static string getGameSaveLocation()
{
Expand All @@ -219,11 +193,11 @@ public static string getGameSaveLocation()

//TODO: Test Linux location
if (isLinux)
return "~/.local/share/Steam/steamapps/compatdata/2379780/pfx/drive_c/users/steamuser/AppData/Roaming/Balatro";
return Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + "/.local/share/Steam/steamapps/compatdata/2379780/pfx/drive_c/users/steamuser/AppData/Roaming/Balatro";

//TODO: Implement
//if (isOSX)
// return "uhhh";
if (isOSX)
return Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + "/Library/Application Support/Balatro";

return ".";
}
Expand Down Expand Up @@ -268,10 +242,10 @@ public static bool tryLocateGame()

//TODO: Test OSX and Linux locations!!!
if (isOSX)
location = "~/Library/Application Support/Steam/steamapps/common/Balatro/Balatro.app/Contents/Resources/Balatro.love";
location = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + "/Library/Application Support/Steam/steamapps/common/Balatro/Balatro.app/Contents/Resources/Balatro.love";

if (isLinux)
location = "~/.local/share/Steam/steamapps/common/Balatro/Balatro.exe";
location = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + "/.local/share/Steam/steamapps/common/Balatro/Balatro.exe";


//Attempt to copy Balatro from Steam directory
Expand Down
17 changes: 13 additions & 4 deletions balatro-mobile-maker/Tools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Net;
using static balatro_mobile_maker.Program;
using System.Diagnostics;
using System.IO.Compression;

namespace balatro_mobile_maker;
internal class Tools
Expand All @@ -16,7 +17,6 @@ public enum ProcessTools
SevenZip,
ADB,
Java,
Python
}

public static void useTool(ProcessTools tool, string args)
Expand All @@ -26,9 +26,6 @@ public static void useTool(ProcessTools tool, string args)
case ProcessTools.ADB:
Platform.useADB(args);
break;
case ProcessTools.Python:
Platform.usePython(args);
break;
case ProcessTools.Java:
Platform.useOpenJDK(args);
break;
Expand Down Expand Up @@ -227,4 +224,16 @@ public static bool AskQuestion(string question)

return input == "y";
}

public static void ModifyZip()
{
string existingZipFile = "balatro-base.zip";
string newFilePath = "game.love";
string arcname = "Payload/Balatro.app/game.love";

using (ZipArchive archive = ZipFile.Open(existingZipFile, ZipArchiveMode.Update))
{
archive.CreateEntryFromFile(newFilePath, arcname);
}
}
}
14 changes: 2 additions & 12 deletions balatro-mobile-maker/View.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,7 @@ public void Begin()
//Downloading tools. Handled in threads to allow simultaneous downloads
Thread[] downloadThreads =
[
//TODO: Platform specific file downloads for Python!! This will download the Windows X64 version on all platforms! Moving forward without correcting this assumes Python is installed and in the Path for OSX and Linux!!!
new Thread(() => { Platform.download7Zip(); }),
new Thread(() => { TryDownloadFile("Python", PythonWinX64Link, "python.zip"); }),

new Thread(() => { TryDownloadFile("iOS Base", IosBaseLink, "balatro-base.ipa"); })
];

Expand Down Expand Up @@ -250,14 +247,9 @@ public void Begin()
if (_iosBuild)
{
#region Packing IPA
Log("Extracting Python");
tryDelete("python");
useTool(ProcessTools.SevenZip, "x python.zip -opython");


Log("Repacking iOS app...");
tryDelete("ios.py");
System.IO.File.WriteAllText("ios.py", Constants.PythonScript);
useTool(ProcessTools.Python, "ios.py");
ModifyZip();

fileMove("balatro-base.zip", "balatro.ipa");
#endregion
Expand Down Expand Up @@ -382,7 +374,6 @@ public static void Cleanup()
tryDelete("balatro-aligned-debugSigned.apk.idsig");
tryDelete("balatro-unsigned.apk");
tryDelete("platform-tools.zip");
tryDelete("python.zip");
tryDelete("ios.py");
tryDelete("balatro.zip");
tryDelete("game.love");
Expand All @@ -399,7 +390,6 @@ public static void Cleanup()

tryDelete("platform-tools");
tryDelete("jdk-21.0.3+9");
tryDelete("python");
tryDelete("Balatro-APK-Patch");//TODO: remove when Android build changes
//tryDelete("icons");//TODO: enable when Android build changes
tryDelete("Balatro");
Expand Down

0 comments on commit 70647de

Please sign in to comment.