Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/matt-final'
Browse files Browse the repository at this point in the history
  • Loading branch information
RetroDriven committed Sep 19, 2022
2 parents 788b7aa + ed5e765 commit 36e24c0
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 149 deletions.
62 changes: 0 additions & 62 deletions ArcadeRomDownloader.cs

This file was deleted.

2 changes: 1 addition & 1 deletion CoreSelector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public static bool CheckForInternetConnection()

public void Download_Json()
{
string Json_URL = "https://raw.githubusercontent.com/mattpannella/pocket_core_autoupdate_net/develop/pocket_updater_cores.json";
string Json_URL = "https://raw.githubusercontent.com/mattpannella/pocket_core_autoupdate_net/main/pocket_updater_cores.json";
WebClient = new WebClient();
string Current_Dir = Directory.GetCurrentDirectory();
Console.WriteLine(Current_Dir);
Expand Down
14 changes: 14 additions & 0 deletions Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml;
using pannella.analoguepocket;

namespace Pocket_Updater
{
public partial class Settings : Form
{
SettingsManager _settings;
public Settings()
{
InitializeComponent();
Expand All @@ -21,11 +23,23 @@ public Settings()

//Tooltips
toolTip1.SetToolTip(pictureBox1, "This is an Optional setting to use a Personal GitHub Token to avoid Rate Limit Issues/Errors.");
ReadSettings();
}

public void ReadSettings()
{
string Current_Dir = Directory.GetCurrentDirectory();
_settings = new SettingsManager(Current_Dir + "\\pocket_updater_settings.json");
textBox1.Text = _settings.GetConfig().github_token;
}

private void Buttons_Save_Click(object sender, EventArgs e)
{
string value = textBox1.Text;
Config config = _settings.GetConfig();
config.github_token = value;
_settings.UpdateConfig(config);
_settings.SaveSettings();
MessageBox.Show("Settings Saved!", "Saved", MessageBoxButtons.OK, MessageBoxIcon.Information);
Close();
}
Expand Down
27 changes: 16 additions & 11 deletions Update_Pocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public partial class Update_Pocket : Form

private WebClient WebClient;
private PocketCoreUpdater _updater;
private ArcadeRomDownloader _romDownloader;
private SettingsManager _settings;

//Initialize Update Status Form Popup
Updater_Status form = new Updater_Status();
Expand All @@ -35,6 +35,8 @@ public Update_Pocket()

//Get USB Drives
PopulateDrives();
string Current_Dir = Directory.GetCurrentDirectory();
_settings = new SettingsManager(Current_Dir + "\\pocket_updater_settings.json");

//Tooltips
toolTip1.SetToolTip(Button_Refresh, "Refresh your Removable Drive List");
Expand Down Expand Up @@ -75,12 +77,6 @@ public void Download_Json(string Drive)

/* ------ STUFF MATT ADDED FOR EXAMPLE ------ */

//Call this method from a new button and you can run the arcade rom downloder
public void RunArcadeRomDownloadProcess()
{
_romDownloader.DownloadAll();
}

//Call this method from a new button and you can run the core updater
public async Task RunCoreUpdateProcess(string updatePath, string coresJsonPath)
{
Expand Down Expand Up @@ -116,12 +112,12 @@ private void updateCoresButton_Click(object sender, EventArgs e)
//infoTextBox.Clear();

string Location_Type = comboBox2.SelectedItem.ToString();
string Current_Dir = Directory.GetCurrentDirectory();
string github_token = _settings.GetConfig().github_token;

//Current Drive Updater
if (Location_Type == "Current Directory")
{
string Current_Dir = Directory.GetCurrentDirectory();

//Check for an Internet Connection
bool result = CheckForInternetConnection();

Expand All @@ -137,6 +133,10 @@ private void updateCoresButton_Click(object sender, EventArgs e)
Download_Json(Current_Dir);
_updater = new PocketCoreUpdater(Current_Dir, Current_Dir + "\\pocket_updater_cores.json");
_updater.DownloadAssets(true); //turns on the option to also download bios files
if(github_token != null)
{
_updater.SetGithubApiKey(github_token);
}

form.Show();

Expand Down Expand Up @@ -167,9 +167,14 @@ private void updateCoresButton_Click(object sender, EventArgs e)
if (drives.Where(data => data.Name == Pocket_Drive).Count() == 1)
{
Download_Json(pathToUpdate);
_updater = new PocketCoreUpdater(pathToUpdate, pathToUpdate+"\\pocket_updater_cores.json");
_updater.CoresFile = pathToUpdate;
// string Current_Dir = Directory.GetCurrentDirectory();
_updater = new PocketCoreUpdater(pathToUpdate, pathToUpdate+"\\pocket_updater_cores.json", Current_Dir);
//_updater.CoresFile = pathToUpdate;
_updater.DownloadAssets(true); //turns on the option to also download bios files
if (github_token != null)
{
_updater.SetGithubApiKey(github_token);
}

form.Show();

Expand Down
16 changes: 14 additions & 2 deletions lib/Updater/SettingsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,24 @@ public class SettingsManager
private Settings _settings;
private string _settingsFile;

public SettingsManager(string settingsFile, List<Core> cores)
public SettingsManager(string settingsFile, List<Core> cores = null)
{
_settings = new Settings();
if (File.Exists(settingsFile))
{
string json = File.ReadAllText(settingsFile);
_settings = JsonSerializer.Deserialize<Settings>(json);
}

//bandaid to fix old settings files
if(_settings.config == null) {
_settings.config = new Config();
}
_settingsFile = settingsFile;

_initializeCoreSettings(cores);
if(cores != null) {
_initializeCoreSettings(cores);
}

SaveSettings();
}
Expand Down Expand Up @@ -114,4 +121,9 @@ public Config GetConfig()
return _settings.config;
}

public void UpdateConfig(Config config)
{
_settings.config = config;
}

}
Loading

0 comments on commit 36e24c0

Please sign in to comment.