Switch away from using inbuilt settings and use a json

This commit is contained in:
Chax
2024-10-05 17:09:12 +02:00
parent 426d99e519
commit eb88d746c1
13 changed files with 671 additions and 344 deletions

27
ADB.cs
View File

@@ -1,4 +1,5 @@
using JR.Utils.GUI.Forms;
using AndroidSideloader.Utilities;
using JR.Utils.GUI.Forms;
using System;
using System.Diagnostics;
using System.IO;
@@ -8,6 +9,7 @@ namespace AndroidSideloader
{
internal class ADB
{
private static readonly SettingsManager settings = SettingsManager.Instance;
private static readonly Process adb = new Process();
public static string adbFolderPath = Path.Combine(Path.GetPathRoot(Environment.SystemDirectory), "RSL", "platform-tools");
public static string adbFilePath = Path.Combine(adbFolderPath, "adb.exe");
@@ -18,9 +20,9 @@ namespace AndroidSideloader
// Replacing "adb" from command if the user added it
command = command.Replace("adb", "");
Properties.Settings.Default.ADBFolder = adbFolderPath;
Properties.Settings.Default.ADBPath = adbFilePath;
Properties.Settings.Default.Save();
settings.ADBFolder = adbFolderPath;
settings.ADBPath = adbFilePath;
settings.Save();
if (DeviceID.Length > 1)
{
command = $" -s {DeviceID} {command}";
@@ -68,7 +70,7 @@ namespace AndroidSideloader
}
}
if (error.Contains("ADB_VENDOR_KEYS") && !Properties.Settings.Default.adbdebugwarned)
if (error.Contains("ADB_VENDOR_KEYS") && !settings.AdbDebugWarned)
{
ADBDebugWarning();
}
@@ -137,7 +139,7 @@ namespace AndroidSideloader
adb.WaitForExit();
}
}
if (error.Contains("ADB_VENDOR_KEYS") && Properties.Settings.Default.adbdebugwarned)
if (error.Contains("ADB_VENDOR_KEYS") && settings.AdbDebugWarned)
{
ADBDebugWarning();
}
@@ -188,7 +190,7 @@ namespace AndroidSideloader
}
}
if (error.Contains("ADB_VENDOR_KEYS") && Properties.Settings.Default.adbdebugwarned)
if (error.Contains("ADB_VENDOR_KEYS") && settings.AdbDebugWarned)
{
ADBDebugWarning();
}
@@ -204,8 +206,8 @@ namespace AndroidSideloader
DialogResult dialogResult = FlexibleMessageBox.Show(Program.form, "On your headset, click on the Notifications Bell, and then select the USB Detected notification to enable Connections.", "ADB Debugging not enabled.", MessageBoxButtons.OKCancel);
if (dialogResult == DialogResult.Cancel)
{
// Properties.Settings.Default.adbdebugwarned = true;
Properties.Settings.Default.Save();
// settings.adbdebugwarned = true;
settings.Save();
}
});
}
@@ -246,7 +248,6 @@ namespace AndroidSideloader
public static bool wirelessadbON;
public static ProcessOutput Sideload(string path, string packagename = "")
{
ProcessOutput ret = new ProcessOutput();
ret += RunAdbCommandToString($"install -g \"{path}\"");
string out2 = ret.Output + ret.Error;
@@ -254,7 +255,7 @@ namespace AndroidSideloader
{
_ = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), $"Rookie Backups");
_ = Logger.Log(out2);
if (out2.Contains("offline") && !Properties.Settings.Default.nodevicemode)
if (out2.Contains("offline") && !settings.NodeviceMode)
{
DialogResult dialogResult2 = FlexibleMessageBox.Show(Program.form, "Device is offline. Press Yes to reconnect, or if you don't wish to connect and just want to download the game (requires unchecking \"Delete games after install\" from settings menu) then press No.", "Device offline.", MessageBoxButtons.YesNoCancel);
}
@@ -262,11 +263,11 @@ namespace AndroidSideloader
{
ret.Error = string.Empty;
ret.Output = string.Empty;
if (!Properties.Settings.Default.AutoReinstall)
if (!settings.AutoReinstall)
{
bool cancelClicked = false;
if (!Properties.Settings.Default.AutoReinstall)
if (!settings.AutoReinstall)
{
Program.form.Invoke((MethodInvoker)(() =>
{

View File

@@ -194,6 +194,7 @@
</Compile>
<Compile Include="FlexibleMessageBox.cs" />
<Compile Include="RoundedRectangleF.cs" />
<Compile Include="Settings.cs" />
<Compile Include="Sideloader\GetDependencies.cs" />
<Compile Include="Splash.cs">
<SubType>Form</SubType>
@@ -249,6 +250,7 @@
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SelectFolder.cs" />
<Compile Include="Utilities\SettingsManager.cs" />
<Compile Include="Utilities\StringUtilities.cs" />
<Compile Include="Utilities\GeneralUtilities.cs" />
<Compile Include="Utilities\UpdateGameData.cs" />

File diff suppressed because it is too large Load Diff

View File

@@ -1,4 +1,5 @@
using System;
using AndroidSideloader.Utilities;
using System;
using System.IO;
using System.Security.Permissions;
using System.Windows.Forms;
@@ -7,6 +8,7 @@ namespace AndroidSideloader
{
internal static class Program
{
private static readonly SettingsManager settings = SettingsManager.Instance;
/// <summary>
/// The main entry point for the application.
/// </summary>
@@ -19,12 +21,6 @@ namespace AndroidSideloader
currentDomain.UnhandledException += new UnhandledExceptionEventHandler(CrashHandler);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
if (AndroidSideloader.Properties.Settings.Default.UpdateSettings)
{
AndroidSideloader.Properties.Settings.Default.Upgrade();
AndroidSideloader.Properties.Settings.Default.UpdateSettings = false;
AndroidSideloader.Properties.Settings.Default.Save();
}
form = new MainForm();
Application.Run(form);
//form.Show();
@@ -41,9 +37,9 @@ namespace AndroidSideloader
string date_time = DateTime.Now.ToString("dddd, MMMM dd @ hh:mmtt (UTC)");
File.WriteAllText(Sideloader.CrashLogPath, $"Date/Time of crash: {date_time}\nMessage: {e.Message}\nInner Message: {innerExceptionMessage}\nData: {e.Data}\nSource: {e.Source}\nTargetSite: {e.TargetSite}\nStack Trace: \n{e.StackTrace}\n\n\nDebuglog: \n\n\n");
// If a debuglog exists we append it to the crashlog.
if (File.Exists(Properties.Settings.Default.CurrentLogPath))
if (File.Exists(settings.CurrentLogPath))
{
File.AppendAllText(Sideloader.CrashLogPath, File.ReadAllText($"{Properties.Settings.Default.CurrentLogPath}"));
File.AppendAllText(Sideloader.CrashLogPath, File.ReadAllText($"{settings.CurrentLogPath}"));
}
}
}

View File

@@ -1,4 +1,5 @@
using System;
using AndroidSideloader.Utilities;
using System;
using System.IO;
using System.Windows.Forms;
@@ -6,6 +7,7 @@ namespace AndroidSideloader
{
public partial class QuestForm : Form
{
private static readonly SettingsManager settings = SettingsManager.Instance;
public static int length = 0;
public static string[] result;
public bool settingsexist = false;
@@ -85,27 +87,26 @@ namespace AndroidSideloader
{
if (DeleteShots.Checked)
{
Properties.Settings.Default.delsh = true;
Properties.Settings.Default.Save();
settings.Delsh = true;
settings.Save();
}
if (!DeleteShots.Checked)
{
Properties.Settings.Default.delsh = false;
Properties.Settings.Default.Save();
settings.Delsh = false;
settings.Save();
}
}
private void QuestForm_Load(object sender, EventArgs e)
{
DeleteShots.Checked = Properties.Settings.Default.delsh;
GlobalUsername.Text = Properties.Settings.Default.GlobalUsername;
DeleteShots.Checked = settings.Delsh;
GlobalUsername.Text = settings.GlobalUsername;
}
private void DeleteButton_Click(object sender, EventArgs e)
{
_ = MessageBox.Show("Ok, Deleted your custom settings file.\nIf you would like to re-enable return here and apply settings again");
File.Delete($"{Properties.Settings.Default.MainDir}\\Config.Json");
File.Delete($"{settings.MainDir}\\Config.Json");
}
private void questPics_Click(object sender, EventArgs e)
{
@@ -181,8 +182,8 @@ namespace AndroidSideloader
private void GlobalUsername_TextChanged(object sender, EventArgs e)
{
btnApplyUsername.Enabled = GlobalUsername.TextLength > 0;
Properties.Settings.Default.GlobalUsername = GlobalUsername.Text;
Properties.Settings.Default.Save();
settings.GlobalUsername = GlobalUsername.Text;
settings.Save();
}
}
}

View File

@@ -1,4 +1,5 @@
using JR.Utils.GUI.Forms;
using AndroidSideloader.Utilities;
using JR.Utils.GUI.Forms;
using System;
using System.Diagnostics;
using System.IO;
@@ -10,6 +11,7 @@ namespace AndroidSideloader
{
internal class RCLONE
{
private static readonly SettingsManager settings = SettingsManager.Instance;
// Kill RCLONE Processes that were started from Rookie by looking for child processes.
public static void killRclone()
{
@@ -84,9 +86,9 @@ namespace AndroidSideloader
}
string logcmd = Utilities.StringUtilities.RemoveEverythingBeforeFirst(command, "rclone.exe");
if (logcmd.Contains($"\"{Properties.Settings.Default.CurrentLogPath}\""))
if (logcmd.Contains($"\"{settings.CurrentLogPath}\""))
{
logcmd = logcmd.Replace($"\"{Properties.Settings.Default.CurrentLogPath}\"", $"\"{Properties.Settings.Default.CurrentLogName}\"");
logcmd = logcmd.Replace($"\"{settings.CurrentLogPath}\"", $"\"{settings.CurrentLogName}\"");
}
if (logcmd.Contains(Environment.CurrentDirectory))
@@ -122,7 +124,7 @@ namespace AndroidSideloader
{
Program.form.Invoke(() =>
{
_ = FlexibleMessageBox.Show(Program.form, $"There isn't enough disk space to download this game.\r\nPlease ensure you have at least 200MB more the game size available in {Properties.Settings.Default.downloadDir} and try again.",
_ = FlexibleMessageBox.Show(Program.form, $"There isn't enough disk space to download this game.\r\nPlease ensure you have at least 200MB more the game size available in {settings.DownloadDir} and try again.",
"NOT ENOUGH SPACE",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
@@ -179,9 +181,9 @@ namespace AndroidSideloader
}
string logcmd = Utilities.StringUtilities.RemoveEverythingBeforeFirst(command, "rclone.exe");
if (logcmd.Contains($"\"{Properties.Settings.Default.CurrentLogPath}\""))
if (logcmd.Contains($"\"{settings.CurrentLogPath}\""))
{
logcmd = logcmd.Replace($"\"{Properties.Settings.Default.CurrentLogPath}\"", $"\"{Properties.Settings.Default.CurrentLogName}\"");
logcmd = logcmd.Replace($"\"{settings.CurrentLogPath}\"", $"\"{settings.CurrentLogName}\"");
}
if (logcmd.Contains(Environment.CurrentDirectory))
@@ -254,9 +256,9 @@ namespace AndroidSideloader
rclone.StartInfo.StandardOutputEncoding = Encoding.UTF8;
string logcmd = Utilities.StringUtilities.RemoveEverythingBeforeFirst(command, "rclone.exe");
if (logcmd.Contains($"\"{Properties.Settings.Default.CurrentLogPath}\""))
if (logcmd.Contains($"\"{settings.CurrentLogPath}\""))
{
logcmd = logcmd.Replace($"\"{Properties.Settings.Default.CurrentLogPath}\"", $"\"{Properties.Settings.Default.CurrentLogName}\"");
logcmd = logcmd.Replace($"\"{settings.CurrentLogPath}\"", $"\"{settings.CurrentLogName}\"");
}
if (logcmd.Contains(Environment.CurrentDirectory))
@@ -296,7 +298,7 @@ namespace AndroidSideloader
{
Program.form.Invoke(() =>
{
_ = FlexibleMessageBox.Show(Program.form, $"There isn't enough disk space to download this game.\r\nPlease ensure you have at least 2x the game size available in {Properties.Settings.Default.downloadDir} and try again.",
_ = FlexibleMessageBox.Show(Program.form, $"There isn't enough disk space to download this game.\r\nPlease ensure you have at least 2x the game size available in {settings.DownloadDir} and try again.",
"NOT ENOUGH SPACE",
MessageBoxButtons.OK,
MessageBoxIcon.Error);

28
Settings.cs Normal file
View File

@@ -0,0 +1,28 @@
namespace AndroidSideloader.Properties {
// This class allows you to handle specific events on the settings class:
// The SettingChanging event is raised before a setting's value is changed.
// The PropertyChanged event is raised after a setting's value is changed.
// The SettingsLoaded event is raised after the setting values are loaded.
// The SettingsSaving event is raised before the setting values are saved.
internal sealed partial class Settings {
public Settings() {
// // To add event handlers for saving and changing settings, uncomment the lines below:
//
// this.SettingChanging += this.SettingChangingEventHandler;
//
// this.SettingsSaving += this.SettingsSavingEventHandler;
//
}
private void SettingChangingEventHandler(object sender, System.Configuration.SettingChangingEventArgs e) {
// Add code to handle the SettingChangingEvent event here.
}
private void SettingsSavingEventHandler(object sender, System.ComponentModel.CancelEventArgs e) {
// Add code to handle the SettingsSaving event here.
}
}
}

View File

@@ -1,4 +1,5 @@
using JR.Utils.GUI.Forms;
using AndroidSideloader.Utilities;
using JR.Utils.GUI.Forms;
using System;
using System.Diagnostics;
using System.IO;
@@ -9,6 +10,7 @@ namespace AndroidSideloader
{
public partial class SettingsForm : Form
{
private static readonly SettingsManager _settings = SettingsManager.Instance;
public SettingsForm()
{
InitializeComponent();
@@ -17,34 +19,34 @@ namespace AndroidSideloader
private void SettingsForm_Load(object sender, EventArgs e)
{
CenterToParent();
intSettings();
intToolTips();
initSettings();
initToolTips();
}
//Init form objects with values from settings
private void intSettings()
private void initSettings()
{
checkForUpdatesCheckBox.Checked = Properties.Settings.Default.checkForUpdates;
enableMessageBoxesCheckBox.Checked = Properties.Settings.Default.enableMessageBoxes;
deleteAfterInstallCheckBox.Checked = Properties.Settings.Default.deleteAllAfterInstall;
updateConfigCheckBox.Checked = Properties.Settings.Default.autoUpdateConfig;
userJsonOnGameInstall.Checked = Properties.Settings.Default.userJsonOnGameInstall;
nodevicemodeBox.Checked = Properties.Settings.Default.nodevicemode;
bmbfBox.Checked = Properties.Settings.Default.BMBFchecked;
AutoReinstBox.Checked = Properties.Settings.Default.AutoReinstall;
trailersOn.Checked = Properties.Settings.Default.TrailersOn;
chkSingleThread.Checked = Properties.Settings.Default.singleThreadMode;
virtualFilesystemCompatibilityCheckbox.Checked = Properties.Settings.Default.virtualFilesystemCompatibility;
bandwidthLimitTextBox.Text = Properties.Settings.Default.bandwidthLimit.ToString();
Console.WriteLine("Opened Settins Form");
checkForUpdatesCheckBox.Checked = _settings.CheckForUpdates;
enableMessageBoxesCheckBox.Checked = _settings.EnableMessageBoxes;
deleteAfterInstallCheckBox.Checked = _settings.DeleteAllAfterInstall;
updateConfigCheckBox.Checked = _settings.AutoUpdateConfig;
userJsonOnGameInstall.Checked = _settings.UserJsonOnGameInstall;
nodevicemodeBox.Checked = _settings.NodeviceMode;
bmbfBox.Checked = _settings.BMBFChecked;
AutoReinstBox.Checked = _settings.AutoReinstall;
trailersOn.Checked = _settings.TrailersOn;
chkSingleThread.Checked = _settings.SingleThreadMode;
virtualFilesystemCompatibilityCheckbox.Checked = _settings.VirtualFilesystemCompatibility;
bandwidthLimitTextBox.Text = _settings.BandwidthLimit.ToString();
if (nodevicemodeBox.Checked)
{
deleteAfterInstallCheckBox.Checked = false;
deleteAfterInstallCheckBox.Enabled = false;
}
chkUseDownloadedFiles.Checked = Properties.Settings.Default.useDownloadedFiles;
chkUseDownloadedFiles.Checked = _settings.UseDownloadedFiles;
}
private void intToolTips()
private void initToolTips()
{
ToolTip checkForUpdatesToolTip = new ToolTip();
checkForUpdatesToolTip.SetToolTip(checkForUpdatesCheckBox, "If this is checked, the software will check for available updates");
@@ -58,7 +60,8 @@ namespace AndroidSideloader
public void btnUploadDebug_click(object sender, EventArgs e)
{
if (File.Exists($"{Properties.Settings.Default.CurrentLogPath}"))
var _settings = SettingsManager.Instance;
if (File.Exists($"{_settings.CurrentLogPath}"))
{
string UUID = SideloaderUtilities.UUID();
string debugLogPath = $"{Environment.CurrentDirectory}\\{UUID}.log";
@@ -71,12 +74,12 @@ namespace AndroidSideloader
}
}
public void btnResetDebug_click(object sender, EventArgs e)
{
if (File.Exists($"{Properties.Settings.Default.CurrentLogPath}"))
var _settings = SettingsManager.Instance;
if (File.Exists($"{_settings.CurrentLogPath}"))
{
File.Delete($"{Properties.Settings.Default.CurrentLogPath}");
File.Delete($"{_settings.CurrentLogPath}");
}
if (File.Exists($"{Environment.CurrentDirectory}\\debuglog.txt"))
@@ -85,16 +88,16 @@ namespace AndroidSideloader
}
}
//Apply settings
private void applyButton_Click(object sender, EventArgs e)
{
var _settings = SettingsManager.Instance;
string input = bandwidthLimitTextBox.Text;
Regex regex = new Regex(@"^\d+(\.\d+)?$");
if (regex.IsMatch(input) && float.TryParse(input, out float bandwidthLimit))
{
Properties.Settings.Default.bandwidthLimit = bandwidthLimit;
Properties.Settings.Default.Save();
_settings.BandwidthLimit = bandwidthLimit;
_settings.Save();
this.Close();
}
else
@@ -105,49 +108,68 @@ namespace AndroidSideloader
private void checkForUpdatesCheckBox_CheckedChanged(object sender, EventArgs e)
{
Properties.Settings.Default.checkForUpdates = checkForUpdatesCheckBox.Checked;
Properties.Settings.Default.Save();
var _settings = SettingsManager.Instance;
_settings.CheckForUpdates = checkForUpdatesCheckBox.Checked;
_settings.Save();
}
private void chkUseDownloadedFiles_CheckedChanged(object sender, EventArgs e)
{
Properties.Settings.Default.useDownloadedFiles = chkUseDownloadedFiles.Checked;
Properties.Settings.Default.Save();
var _settings = SettingsManager.Instance;
_settings.UseDownloadedFiles = chkUseDownloadedFiles.Checked;
_settings.Save();
}
private void enableMessageBoxesCheckBox_CheckedChanged(object sender, EventArgs e)
{
Properties.Settings.Default.enableMessageBoxes = enableMessageBoxesCheckBox.Checked;
Properties.Settings.Default.Save();
var _settings = SettingsManager.Instance;
_settings.EnableMessageBoxes = enableMessageBoxesCheckBox.Checked;
_settings.Save();
}
private void resetSettingsButton_Click(object sender, EventArgs e)
{
Properties.Settings.Default.Reset();
Properties.Settings.Default.customDownloadDir = false;
Properties.Settings.Default.customBackupDir = false;
MainForm.backupFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), $"Rookie Backups");
Properties.Settings.Default.downloadDir = Environment.CurrentDirectory.ToString();
Properties.Settings.Default.createPubMirrorFile = true;
intSettings();
Properties.Settings.Default.Save();
var _settings = SettingsManager.Instance;
// Reset the specific properties
_settings.CustomDownloadDir = false;
_settings.CustomBackupDir = false;
// Set backup folder and download directory
MainForm.backupFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Rookie Backups");
_settings.DownloadDir = Environment.CurrentDirectory;
_settings.CreatePubMirrorFile = true;
// Optionally, call initSettings if it needs to initialize anything based on these settings
initSettings();
// Save the updated settings
_settings.Save();
}
private void deleteAfterInstallCheckBox_CheckedChanged(object sender, EventArgs e)
{
Properties.Settings.Default.deleteAllAfterInstall = deleteAfterInstallCheckBox.Checked;
var _settings = SettingsManager.Instance;
_settings.DeleteAllAfterInstall = deleteAfterInstallCheckBox.Checked;
_settings.Save();
}
private void updateConfigCheckBox_CheckedChanged(object sender, EventArgs e)
{
Properties.Settings.Default.autoUpdateConfig = updateConfigCheckBox.Checked;
if (Properties.Settings.Default.autoUpdateConfig == true) {
Properties.Settings.Default.createPubMirrorFile = true;
var _settings = SettingsManager.Instance;
_settings.AutoUpdateConfig = updateConfigCheckBox.Checked;
if (_settings.AutoUpdateConfig)
{
_settings.CreatePubMirrorFile = true;
}
_settings.Save();
}
private void userJsonOnGameInstall_CheckedChanged(object sender, EventArgs e)
{
Properties.Settings.Default.userJsonOnGameInstall = userJsonOnGameInstall.Checked;
var _settings = SettingsManager.Instance;
_settings.UserJsonOnGameInstall = userJsonOnGameInstall.Checked;
_settings.Save();
}
private void SettingsForm_KeyPress(object sender, KeyPressEventArgs e)
@@ -170,6 +192,7 @@ namespace AndroidSideloader
Close();
}
}
protected override bool ProcessDialogKey(Keys keyData)
{
if (Form.ModifierKeys == Keys.None && keyData == Keys.Escape)
@@ -182,38 +205,35 @@ namespace AndroidSideloader
private void nodevicemodeBox_CheckedChanged(object sender, EventArgs e)
{
Properties.Settings.Default.nodevicemode = nodevicemodeBox.Checked;
var _settings = SettingsManager.Instance;
_settings.NodeviceMode = nodevicemodeBox.Checked;
if (!nodevicemodeBox.Checked)
{
deleteAfterInstallCheckBox.Checked = true;
Properties.Settings.Default.deleteAllAfterInstall = true;
_settings.DeleteAllAfterInstall = true;
deleteAfterInstallCheckBox.Enabled = true;
}
else
{
deleteAfterInstallCheckBox.Checked = false;
Properties.Settings.Default.deleteAllAfterInstall = false;
_settings.DeleteAllAfterInstall = false;
deleteAfterInstallCheckBox.Enabled = false;
}
Properties.Settings.Default.Save();
_settings.Save();
}
private void bmbfBox_CheckedChanged(object sender, EventArgs e)
{
Properties.Settings.Default.BMBFchecked = bmbfBox.Checked;
Properties.Settings.Default.Save();
var _settings = SettingsManager.Instance;
_settings.BMBFChecked = bmbfBox.Checked;
_settings.Save();
}
private void AutoReinstBox_CheckedChanged(object sender, EventArgs e)
{
Properties.Settings.Default.AutoReinstall = AutoReinstBox.Checked;
Properties.Settings.Default.Save();
}
private void trailersOn_CheckedChanged(object sender, EventArgs e)
{
Properties.Settings.Default.TrailersOn = trailersOn.Checked;
Properties.Settings.Default.Save();
var _settings = SettingsManager.Instance;
_settings.AutoReinstall = AutoReinstBox.Checked;
_settings.Save();
}
private void AutoReinstBox_Click(object sender, EventArgs e)
@@ -230,7 +250,13 @@ namespace AndroidSideloader
AutoReinstBox.Checked = false;
}
}
}
private void trailersOn_CheckedChanged(object sender, EventArgs e)
{
var _settings = SettingsManager.Instance;
_settings.TrailersOn = trailersOn.Checked;
_settings.Save();
}
private void btnOpenDebug_Click(object sender, EventArgs e)
@@ -245,9 +271,10 @@ namespace AndroidSideloader
{
if (downloadDirectorySetter.ShowDialog() == DialogResult.OK)
{
Properties.Settings.Default.customDownloadDir = true;
Properties.Settings.Default.downloadDir = downloadDirectorySetter.SelectedPath;
Properties.Settings.Default.Save();
var _settings = SettingsManager.Instance;
_settings.CustomDownloadDir = true;
_settings.DownloadDir = downloadDirectorySetter.SelectedPath;
_settings.Save();
}
}
@@ -255,33 +282,41 @@ namespace AndroidSideloader
{
if (backupDirectorySetter.ShowDialog() == DialogResult.OK)
{
Properties.Settings.Default.customBackupDir = true;
Properties.Settings.Default.backupDir = backupDirectorySetter.SelectedPath;
MainForm.backupFolder = Properties.Settings.Default.backupDir;
Properties.Settings.Default.Save();
var _settings = SettingsManager.Instance;
_settings.CustomBackupDir = true;
_settings.BackupDir = backupDirectorySetter.SelectedPath;
MainForm.backupFolder = _settings.BackupDir;
_settings.Save();
}
}
private void chkSingleThread_CheckedChanged(object sender, EventArgs e)
{
Properties.Settings.Default.singleThreadMode = chkSingleThread.Checked;
var _settings = SettingsManager.Instance;
_settings.SingleThreadMode = chkSingleThread.Checked;
_settings.Save();
}
private void virtualFilesystemCompatibilityCheckbox_CheckedChanged(object sender, EventArgs e)
{
Properties.Settings.Default.virtualFilesystemCompatibility = virtualFilesystemCompatibilityCheckbox.Checked;
Properties.Settings.Default.Save();
var _settings = SettingsManager.Instance;
_settings.VirtualFilesystemCompatibility = virtualFilesystemCompatibilityCheckbox.Checked;
_settings.Save();
}
private void openDownloadDirectory_Click(object sender, EventArgs e)
{
string pathToOpen = Properties.Settings.Default.customDownloadDir ? $"{Properties.Settings.Default.downloadDir}" : $"{Environment.CurrentDirectory}";
var _settings = SettingsManager.Instance;
string pathToOpen = _settings.CustomDownloadDir ? _settings.DownloadDir : Environment.CurrentDirectory;
MainForm.OpenDirectory(pathToOpen);
}
private void openBackupDirectory_Click(object sender, EventArgs e)
{
string pathToOpen = Properties.Settings.Default.customBackupDir ? $"{Path.Combine((Properties.Settings.Default.backupDir), $"Rookie Backups")}" : $"{Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), $"Rookie Backups")}";
var _settings = SettingsManager.Instance;
string pathToOpen = _settings.CustomBackupDir
? Path.Combine(_settings.BackupDir, "Rookie Backups")
: Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Rookie Backups");
MainForm.OpenDirectory(pathToOpen);
}
@@ -298,5 +333,4 @@ namespace AndroidSideloader
}
}
}
}
}

View File

@@ -7,11 +7,13 @@ using System.Net;
using System.Text.RegularExpressions;
using System.Drawing;
using System.Windows.Forms;
using AndroidSideloader.Utilities;
namespace AndroidSideloader
{
internal class Sideloader
{
private static readonly SettingsManager settings = SettingsManager.Instance;
public static string TempFolder = Path.Combine(Environment.CurrentDirectory, "temp");
public static string CrashLogPath = "crashlog.txt";
@@ -87,8 +89,8 @@ namespace AndroidSideloader
string replacement = "";
string pattern = "adb";
replacement = ADB.DeviceID.Length > 1
? $"{Properties.Settings.Default.ADBPath} -s {ADB.DeviceID}"
: $"{Properties.Settings.Default.ADBPath}";
? $"{settings.ADBPath} -s {ADB.DeviceID}"
: $"{settings.ADBPath}";
Regex rgx = new Regex(pattern);
string result = rgx.Replace(cmd, replacement);
Program.form.changeTitle($"Running {result}");
@@ -165,13 +167,13 @@ namespace AndroidSideloader
public static void BackupGame(string packagename)
{
if (!Properties.Settings.Default.customBackupDir)
if (!settings.CustomBackupDir)
{
MainForm.backupFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), $"Rookie Backups");
}
else
{
MainForm.backupFolder = Path.Combine((Properties.Settings.Default.backupDir), $"Rookie Backups");
MainForm.backupFolder = Path.Combine((settings.BackupDir), $"Rookie Backups");
}
if (!Directory.Exists(MainForm.backupFolder))
{
@@ -219,26 +221,26 @@ namespace AndroidSideloader
apkPath = apkPath.Remove(apkPath.Length - 1);
apkPath = apkPath.Remove(0, 8); //remove package:
apkPath = apkPath.Remove(apkPath.Length - 1);
if (File.Exists($"{Properties.Settings.Default.ADBFolder}\\base.apk"))
if (File.Exists($"{settings.ADBFolder}\\base.apk"))
{
File.Delete($"{Properties.Settings.Default.ADBFolder}\\base.apk");
File.Delete($"{settings.ADBFolder}\\base.apk");
}
if (File.Exists($"{Properties.Settings.Default.MainDir}\\{packageName}\\{packageName}.apk"))
if (File.Exists($"{settings.MainDir}\\{packageName}\\{packageName}.apk"))
{
File.Delete($"{Properties.Settings.Default.MainDir}\\{packageName}\\{packageName}.apk");
File.Delete($"{settings.MainDir}\\{packageName}\\{packageName}.apk");
}
output += ADB.RunAdbCommandToString("pull " + apkPath); //pull apk
if (Directory.Exists($"{Properties.Settings.Default.MainDir}\\{packageName}"))
if (Directory.Exists($"{settings.MainDir}\\{packageName}"))
{
Directory.Delete($"{Properties.Settings.Default.MainDir}\\{packageName}", true);
Directory.Delete($"{settings.MainDir}\\{packageName}", true);
}
_ = Directory.CreateDirectory($"{Properties.Settings.Default.MainDir}\\{packageName}");
_ = Directory.CreateDirectory($"{settings.MainDir}\\{packageName}");
File.Move($"{Properties.Settings.Default.ADBFolder}\\base.apk", $"{Properties.Settings.Default.MainDir}\\{packageName}\\{packageName}.apk");
File.Move($"{settings.ADBFolder}\\base.apk", $"{settings.MainDir}\\{packageName}\\{packageName}.apk");
return output;
}

View File

@@ -1,4 +1,5 @@
using System;
using AndroidSideloader.Utilities;
using System;
using System.IO;
using System.Management;
using System.Security.Cryptography;
@@ -8,6 +9,7 @@ namespace AndroidSideloader
{
internal class SideloaderUtilities
{
private static readonly SettingsManager settings = SettingsManager.Instance;
public static bool CheckFolderIsObb(string path)
{
string[] files = Directory.GetFiles(path);
@@ -26,7 +28,7 @@ namespace AndroidSideloader
private static string uuid = null;
public static string UUID()
{
uuid = Properties.Settings.Default.UUID;
uuid = settings.UUID;
if (string.IsNullOrEmpty(uuid) != true)
{
return uuid;
@@ -40,8 +42,8 @@ namespace AndroidSideloader
uuid = BitConverter.ToString(bytes).Replace("-", "");
Properties.Settings.Default.UUID = uuid;
Properties.Settings.Default.Save();
settings.UUID = uuid;
settings.Save();
return uuid;
}

View File

@@ -17,7 +17,7 @@ namespace AndroidSideloader
public static class Logger
{
private static readonly object lockObject = new object();
private static string logFilePath = Properties.Settings.Default.CurrentLogPath;
private static string logFilePath = settings.CurrentLogPath;
public static bool Log(string text, LogLevel logLevel = LogLevel.INFO, bool ret = true)
{

View File

@@ -0,0 +1,264 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Diagnostics;
using System.Drawing;
using System.IO;
namespace AndroidSideloader.Utilities
{
public class SettingsManager : IDisposable
{
private static readonly Lazy<SettingsManager> _instance = new Lazy<SettingsManager>(() => new SettingsManager());
private static readonly string settingsFilePath = Path.Combine(
AppDomain.CurrentDomain.BaseDirectory,
"settings.json");
// Custom converters for special types
public class FontConverter : JsonConverter<Font>
{
public override Font ReadJson(JsonReader reader, Type objectType, Font existingValue, bool hasExistingValue, JsonSerializer serializer)
{
var jo = JObject.Load(reader);
string fontFamily = jo["FontFamily"]?.Value<string>() ?? "Microsoft Sans Serif";
float fontSize = jo["Size"]?.Value<float>() ?? 11.25f;
return new Font(fontFamily, fontSize);
}
public override void WriteJson(JsonWriter writer, Font value, JsonSerializer serializer)
{
writer.WriteStartObject();
writer.WritePropertyName("FontFamily");
writer.WriteValue(value.FontFamily.Name);
writer.WritePropertyName("Size");
writer.WriteValue(value.Size);
writer.WriteEndObject();
}
}
public class ColorConverter : JsonConverter<Color>
{
public override Color ReadJson(JsonReader reader, Type objectType, Color existingValue, bool hasExistingValue, JsonSerializer serializer)
{
var jo = JObject.Load(reader);
int a = jo["A"]?.Value<int>() ?? 255;
int r = jo["R"]?.Value<int>() ?? 0;
int g = jo["G"]?.Value<int>() ?? 0;
int b = jo["B"]?.Value<int>() ?? 0;
return Color.FromArgb(a, r, g, b);
}
public override void WriteJson(JsonWriter writer, Color value, JsonSerializer serializer)
{
writer.WriteStartObject();
writer.WritePropertyName("A");
writer.WriteValue(value.A);
writer.WritePropertyName("R");
writer.WriteValue(value.R);
writer.WritePropertyName("G");
writer.WriteValue(value.G);
writer.WritePropertyName("B");
writer.WriteValue(value.B);
writer.WriteEndObject();
}
}
[JsonConverter(typeof(FontConverter))]
public Font FontStyle { get; set; } = new Font("Microsoft Sans Serif", 11.25f);
[JsonConverter(typeof(FontConverter))]
public Font BigFontStyle { get; set; } = new Font("Microsoft Sans Serif", 14f);
[JsonConverter(typeof(ColorConverter))]
public Color FontColor { get; set; } = Color.White;
[JsonConverter(typeof(ColorConverter))]
public Color ComboBoxColor { get; set; } = Color.FromArgb(25, 25, 25);
[JsonConverter(typeof(ColorConverter))]
public Color SubButtonColor { get; set; } = Color.FromArgb(25, 25, 25);
[JsonConverter(typeof(ColorConverter))]
public Color TextBoxColor { get; set; } = Color.FromArgb(25, 25, 25);
[JsonConverter(typeof(ColorConverter))]
public Color ButtonColor { get; set; } = Color.Black;
[JsonConverter(typeof(ColorConverter))]
public Color BackColor { get; set; } = Color.FromArgb(1, 1, 1);
public bool CheckForUpdates { get; set; } = true;
public bool EnableMessageBoxes { get; set; } = true;
public bool FirstRun { get; set; } = true;
public bool DeleteAllAfterInstall { get; set; } = true;
public bool AutoUpdateConfig { get; set; } = true;
public bool UserJsonOnGameInstall { get; set; } = false;
public bool CallUpgrade { get; set; } = true;
public string BackPicturePath { get; set; } = string.Empty;
public bool SpoofGames { get; set; } = false;
public bool ResignAPKs { get; set; } = false;
public string IPAddress { get; set; } = string.Empty;
public string InstalledApps { get; set; } = string.Empty;
public string ADBPath { get; set; } = string.Empty;
public string MainDir { get; set; } = string.Empty;
public bool Delsh { get; set; } = false;
public string CurrPckg { get; set; } = string.Empty;
public string ADBFolder { get; set; } = string.Empty;
public bool WirelessADB { get; set; } = false;
public string CurrentGamename { get; set; } = string.Empty;
public bool PackageNameToCB { get; set; } = false;
public bool DownUpHeld { get; set; } = false;
public string CurrentLogPath { get; set; } = string.Empty;
public string CurrentLogName { get; set; } = string.Empty;
public string CurrentCrashPath { get; set; } = string.Empty;
public string CurrentCrashName { get; set; } = string.Empty;
public bool AdbDebugWarned { get; set; } = false;
public bool NodeviceMode { get; set; } = false;
public bool BMBFChecked { get; set; } = true;
public string GamesList { get; set; } = string.Empty;
public bool UploadedGameList { get; set; } = false;
public string GlobalUsername { get; set; } = string.Empty;
public DateTime LastTimeShared { get; set; } = new DateTime(1969, 4, 20, 16, 20, 0);
public bool AutoReinstall { get; set; } = false;
public string NonAppPackages { get; set; } = string.Empty;
public DateTime LastLaunch { get; set; } = new DateTime(1969, 4, 20, 16, 20, 0);
public string SubmittedUpdates { get; set; } = string.Empty;
public bool ListUpped { get; set; } = false;
public DateTime LastLaunch2 { get; set; } = new DateTime(1969, 4, 20, 16, 20, 0);
public bool Wired { get; set; } = false;
public string AppPackages { get; set; } = string.Empty;
public bool TrailersOn { get; set; } = false;
public string DownloadDir { get; set; } = string.Empty;
public bool CustomDownloadDir { get; set; } = false;
public bool CustomBackupDir { get; set; } = false;
public string BackupDir { get; set; } = string.Empty;
public bool SingleThreadMode { get; set; } = true;
public bool VirtualFilesystemCompatibility { get; set; } = false;
public bool UpdateSettings { get; set; } = true;
public string UUID { get; set; } = Guid.NewGuid().ToString();
public bool CreatePubMirrorFile { get; set; } = true;
public bool UseDownloadedFiles { get; set; } = false;
public float BandwidthLimit { get; set; } = 0f;
private SettingsManager()
{
Load();
}
public static SettingsManager Instance => _instance.Value;
public void Save()
{
try
{
var settings = new JsonSerializerSettings
{
Formatting = Formatting.Indented,
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
};
var json = JsonConvert.SerializeObject(this, settings);
File.WriteAllText(settingsFilePath, json);
}
catch (Exception ex)
{
Console.WriteLine($"Error saving settings: {ex.Message}");
}
}
private void Load()
{
Debug.WriteLine("Loading settings...");
if (!File.Exists(settingsFilePath))
{
CreateDefaultSettings();
return;
}
try
{
var json = File.ReadAllText(settingsFilePath);
var settings = new JsonSerializerSettings
{
Error = (sender, args) =>
{
Debug.WriteLine($"Error deserializing setting: {args.ErrorContext.Error.Message}");
args.ErrorContext.Handled = true;
}
};
JsonConvert.PopulateObject(json, this, settings);
}
catch (Exception ex)
{
Debug.WriteLine($"Error loading settings: {ex.Message}");
CreateDefaultSettings();
}
}
private void CreateDefaultSettings()
{
FontStyle = new Font("Microsoft Sans Serif", 11.25f);
BigFontStyle = new Font("Microsoft Sans Serif", 14f);
FontColor = Color.White;
ComboBoxColor = Color.FromArgb(25, 25, 25);
SubButtonColor = Color.FromArgb(25, 25, 25);
TextBoxColor = Color.FromArgb(25, 25, 25);
ButtonColor = Color.Black;
BackColor = Color.FromArgb(1, 1, 1);
CheckForUpdates = true;
EnableMessageBoxes = true;
FirstRun = true;
DeleteAllAfterInstall = true;
AutoUpdateConfig = true;
UserJsonOnGameInstall = false;
CallUpgrade = true;
BackPicturePath = string.Empty;
SpoofGames = false;
ResignAPKs = false;
IPAddress = string.Empty;
InstalledApps = string.Empty;
ADBPath = string.Empty;
MainDir = string.Empty;
Delsh = false;
CurrPckg = string.Empty;
ADBFolder = string.Empty;
WirelessADB = false;
CurrentGamename = string.Empty;
PackageNameToCB = false;
DownUpHeld = false;
CurrentLogPath = string.Empty;
CurrentLogName = string.Empty;
CurrentCrashPath = string.Empty;
CurrentCrashName = string.Empty;
AdbDebugWarned = false;
NodeviceMode = false;
BMBFChecked = true;
GamesList = string.Empty;
UploadedGameList = false;
GlobalUsername = string.Empty;
LastTimeShared = new DateTime(1969, 4, 20, 16, 20, 0);
AutoReinstall = false;
NonAppPackages = string.Empty;
LastLaunch = new DateTime(1969, 4, 20, 16, 20, 0);
SubmittedUpdates = string.Empty;
ListUpped = false;
LastLaunch2 = new DateTime(1969, 4, 20, 16, 20, 0);
Wired = false;
AppPackages = string.Empty;
TrailersOn = false;
DownloadDir = string.Empty;
CustomDownloadDir = false;
CustomBackupDir = false;
BackupDir = string.Empty;
SingleThreadMode = true;
VirtualFilesystemCompatibility = false;
UpdateSettings = true;
UUID = Guid.NewGuid().ToString();
CreatePubMirrorFile = true;
UseDownloadedFiles = false;
BandwidthLimit = 0f;
Save();
Debug.WriteLine("Default settings created.");
}
public void Dispose()
{
FontStyle?.Dispose();
BigFontStyle?.Dispose();
}
}
}

View File

@@ -101,7 +101,7 @@ namespace AndroidSideloader.Utilities
errorMessageShown = true;
Program.form.Invoke(new Action(() =>
{
_ = FlexibleMessageBox.Show(Program.form, $"Not enough space to extract archive.\r\nMake sure your {Path.GetPathRoot(Properties.Settings.Default.downloadDir)} drive has at least double the space of the game, then try again.",
_ = FlexibleMessageBox.Show(Program.form, $"Not enough space to extract archive.\r\nMake sure your {Path.GetPathRoot(settings.downloadDir)} drive has at least double the space of the game, then try again.",
"NOT ENOUGH SPACE",
MessageBoxButtons.OK,
MessageBoxIcon.Error);