From ed5e765eb2358429fe1c8825f5d44a8bc1d79943 Mon Sep 17 00:00:00 2001 From: Matt Pannella Date: Sun, 18 Sep 2022 20:48:34 -0400 Subject: [PATCH] adding github token and settings --- ArcadeRomDownloader.cs | 62 ---------------------------------- CoreSelector.cs | 2 +- Settings.cs | 14 ++++++++ Update_Pocket.cs | 27 +++++++++------ lib/Updater/SettingsManager.cs | 5 +++ lib/Updater/Updater.cs | 8 +++-- 6 files changed, 42 insertions(+), 76 deletions(-) delete mode 100644 ArcadeRomDownloader.cs diff --git a/ArcadeRomDownloader.cs b/ArcadeRomDownloader.cs deleted file mode 100644 index 11eca3e..0000000 --- a/ArcadeRomDownloader.cs +++ /dev/null @@ -1,62 +0,0 @@ -using System; -using System.Collections.Generic; -using pannella.analoguepocket; -using System.Text.Json; -namespace Pocket_Updater -{ - public class ArcadeRomDownloader - { - private string _misterDB = "some_url_or_path_to_mister_db"; - private string _mameSetArchiveUrlBase = "http://archive.org/path/to/mame-set/"; - public string CoresFile { get; set; } - - public ArcadeRomDownloader(string coresFile) - { - //constructor. do stuff here to initialize, if needed - //maybe call DownloadDB()? - CoresFile = coresFile; - } - - public void DownloadDB() - { - //download the mister rom db from _misterDB - } - - //this is probably the function that we would call from the UI to download the rom(s) from the mame set for every core - public void DownloadAll() - { - //loop through each core and call GetRomsForCore(coreName) for each one - List cores = _readCoresFile(); - foreach (Core c in cores) - { - GetRomsForCore(c.platform); - } - } - - //download roms for just one specific core - public void GetRomsForCore(string coreName) - { - //use the coreName to check the _misterDB for a list of available roms - //loop through each rom and call _downloadRom() - } - - private void _downloadRom(string romName) - { - //download file from mame set - //url = _mameSetArchiveUrlBase + romName - } - - private List _readCoresFile() - { - string json = File.ReadAllText(CoresFile); - List? coresList = JsonSerializer.Deserialize>(json); - if (coresList != null) - { - return coresList; - } - - return null; - } - - } -} \ No newline at end of file diff --git a/CoreSelector.cs b/CoreSelector.cs index 2c8688a..799f08f 100644 --- a/CoreSelector.cs +++ b/CoreSelector.cs @@ -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); diff --git a/Settings.cs b/Settings.cs index f203724..3919b44 100644 --- a/Settings.cs +++ b/Settings.cs @@ -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(); @@ -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(); } diff --git a/Update_Pocket.cs b/Update_Pocket.cs index 8a205d3..b8bb168 100644 --- a/Update_Pocket.cs +++ b/Update_Pocket.cs @@ -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(); @@ -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"); @@ -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) { @@ -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(); @@ -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(); @@ -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(); diff --git a/lib/Updater/SettingsManager.cs b/lib/Updater/SettingsManager.cs index 3db304f..ae99bf7 100644 --- a/lib/Updater/SettingsManager.cs +++ b/lib/Updater/SettingsManager.cs @@ -121,4 +121,9 @@ public Config GetConfig() return _settings.config; } + public void UpdateConfig(Config config) + { + _settings.config = config; + } + } diff --git a/lib/Updater/Updater.cs b/lib/Updater/Updater.cs index 3966392..22135ea 100644 --- a/lib/Updater/Updater.cs +++ b/lib/Updater/Updater.cs @@ -47,7 +47,7 @@ public class PocketCoreUpdater /// /// The directory to install/update openFPGA cores in. /// Path to cores json file - public PocketCoreUpdater(string updateDirectory, string coresFile = null) + public PocketCoreUpdater(string updateDirectory, string coresFile = null, string settingsPath = null) { UpdateDirectory = updateDirectory; @@ -61,7 +61,11 @@ public PocketCoreUpdater(string updateDirectory, string coresFile = null) } LoadCores(); - SettingsFile = Path.Combine(updateDirectory, "pocket_updater_settings.json"); + if(settingsPath != null) { + SettingsFile = Path.Combine(settingsPath, "pocket_updater_settings.json"); + } else { + SettingsFile = Path.Combine(updateDirectory, "pocket_updater_settings.json"); + } LoadSettings(); }