From 73f5247e4632c6a24b80c41c809b24d84cee0b14 Mon Sep 17 00:00:00 2001 From: RetroDriven Date: Sat, 11 May 2024 22:52:07 -0400 Subject: [PATCH] Internet Connection Checks --- Controls/Image_Packs/Image_Packs.cs | 23 +- Controls/Manage_Cores/ManageCores.cs | 63 +++-- Controls/Organize_Cores/Organize_Cores.cs | 76 +++-- Controls/Update_Pocket/Update_Pocket.cs | 326 +++++++++++++--------- Forms/Main/Form1.Designer.cs | 77 ++--- Forms/Main/Form1.cs | 51 ++-- 6 files changed, 382 insertions(+), 234 deletions(-) diff --git a/Controls/Image_Packs/Image_Packs.cs b/Controls/Image_Packs/Image_Packs.cs index 30770ed..3344dba 100644 --- a/Controls/Image_Packs/Image_Packs.cs +++ b/Controls/Image_Packs/Image_Packs.cs @@ -28,8 +28,10 @@ public Image_Packs() //Preferences Get_Preferences_Json(); - GetPacks(); - + if (Check_Internet()) + { + GetPacks(); + } } public void PopulateDrives() { @@ -246,5 +248,22 @@ private void Save_Preferences_Json() Updater_Preferences.Save_Updater_Json(Entries, Json_File); } } + public static bool Check_Internet() + { + try + { + using (var client = new WebClient()) + { + using (var stream = client.OpenRead("http://www.google.com")) + { + return true; + } + } + } + catch + { + return false; + } + } } } diff --git a/Controls/Manage_Cores/ManageCores.cs b/Controls/Manage_Cores/ManageCores.cs index 1da87ac..5977c09 100644 --- a/Controls/Manage_Cores/ManageCores.cs +++ b/Controls/Manage_Cores/ManageCores.cs @@ -37,33 +37,47 @@ public ManageCores() //dataGridView1.RefreshEdit(); //dataGridView1.Refresh(); - //Get Cores - _ = LoadCores(); + if (Check_Internet()) + { + //Get Cores + _ = LoadCores(); + } + //_readChecklist(); + Button_Save.Enabled = true; } private void Button_Save_Click(object sender, EventArgs e) { - try + if (!Check_Internet()) { - Button_Save.Enabled = false; - _readChecklist(); - _settingsManager.Save(); - ServiceHelper.ReloadSettings(); - Message_Box form = new Message_Box(); - form.label1.Text = "Core Selection Has Been Saved!"; + form.label1.Text = "No Internet Connection Detected!"; form.Show(); - - Button_Save.Enabled = true; } - catch (Exception ex) + else { - Message_Box form = new Message_Box(); - form.label1.Text = ex.Message; - form.Show(); - Button_Save.Enabled = true; + try + { + Button_Save.Enabled = false; + _readChecklist(); + _settingsManager.Save(); + ServiceHelper.ReloadSettings(); + + Message_Box form = new Message_Box(); + form.label1.Text = "Core Selection Has Been Saved!"; + form.Show(); + + Button_Save.Enabled = true; + } + catch (Exception ex) + { + Message_Box form = new Message_Box(); + form.label1.Text = ex.Message; + form.Show(); + Button_Save.Enabled = true; + } } } public void _readChecklist() @@ -187,5 +201,22 @@ private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) bool currentValue = (bool)dataGridView1[0, e.RowIndex].Value; dataGridView1[0, e.RowIndex].Value = !currentValue; } + public static bool Check_Internet() + { + try + { + using (var client = new WebClient()) + { + using (var stream = client.OpenRead("http://www.google.com")) + { + return true; + } + } + } + catch + { + return false; + } + } } } \ No newline at end of file diff --git a/Controls/Organize_Cores/Organize_Cores.cs b/Controls/Organize_Cores/Organize_Cores.cs index e8493c2..549f460 100644 --- a/Controls/Organize_Cores/Organize_Cores.cs +++ b/Controls/Organize_Cores/Organize_Cores.cs @@ -49,33 +49,42 @@ private void Save_Click(object sender, EventArgs e) //Enable Preserve Platform Folder try { - Pannella.Models.Settings.Config config = ServiceHelper.SettingsService.GetConfig(); - config.preserve_platforms_folder = true; - ServiceHelper.SettingsService.UpdateConfig(config); - ServiceHelper.SettingsService.Save(); - Save_Preferences_Json(); - - var Json_Dir = Path.Combine(Pocket_Drive.Text, "Platforms"); - foreach (DataGridViewRow row in dataGridView1.Rows) + if (!Check_Internet()) { - string Row_Name = row.Cells[0].Value.ToString(); - //System.Diagnostics.Debug.WriteLine(Row_Name); - string Row_Category = row.Cells[1].Value.ToString(); - //System.Diagnostics.Debug.WriteLine(Row_Category); - string filename = row.Tag as String; - CoreInfo info = platforms[filename]; - - info.platform.name = Row_Name; - info.platform.category = Row_Category; - - var options = new JsonSerializerOptions { WriteIndented = true }; - string fullPath = Path.Combine(Json_Dir, filename); - File.WriteAllText(fullPath, JsonSerializer.Serialize(info, options)); + Message_Box form = new Message_Box(); + form.label1.Text = "No Internet Connection Detected!"; + form.Show(); + } + else + { + Pannella.Models.Settings.Config config = ServiceHelper.SettingsService.GetConfig(); + config.preserve_platforms_folder = true; + ServiceHelper.SettingsService.UpdateConfig(config); + ServiceHelper.SettingsService.Save(); + Save_Preferences_Json(); + + var Json_Dir = Path.Combine(Pocket_Drive.Text, "Platforms"); + foreach (DataGridViewRow row in dataGridView1.Rows) + { + string Row_Name = row.Cells[0].Value.ToString(); + //System.Diagnostics.Debug.WriteLine(Row_Name); + string Row_Category = row.Cells[1].Value.ToString(); + //System.Diagnostics.Debug.WriteLine(Row_Category); + string filename = row.Tag as String; + CoreInfo info = platforms[filename]; + + info.platform.name = Row_Name; + info.platform.category = Row_Category; + + var options = new JsonSerializerOptions { WriteIndented = true }; + string fullPath = Path.Combine(Json_Dir, filename); + File.WriteAllText(fullPath, JsonSerializer.Serialize(info, options)); + } + + Message_Box form = new Message_Box(); + form.label1.Text = "Core Organization Saved!"; + form.Show(); } - - Message_Box form = new Message_Box(); - form.label1.Text = "Core Organization Saved!"; - form.Show(); } catch (IOException ioex) { @@ -265,5 +274,22 @@ private void Save_Preferences_Json() Updater_Preferences.Save_Updater_Json(Entries, Json_File); } } + public static bool Check_Internet() + { + try + { + using (var client = new WebClient()) + { + using (var stream = client.OpenRead("http://www.google.com")) + { + return true; + } + } + } + catch + { + return false; + } + } } } diff --git a/Controls/Update_Pocket/Update_Pocket.cs b/Controls/Update_Pocket/Update_Pocket.cs index 79ecad1..1fc9672 100644 --- a/Controls/Update_Pocket/Update_Pocket.cs +++ b/Controls/Update_Pocket/Update_Pocket.cs @@ -12,6 +12,7 @@ using Microsoft.VisualBasic; using Pocket_Updater.Properties; using System.Runtime; +using System.Net.NetworkInformation; namespace Pocket_Updater.Controls { @@ -39,12 +40,17 @@ public Update_Pocket() string Current_Dir = Directory.GetCurrentDirectory(); _settings = new SettingsService(Current_Dir); - setupUpdater(Current_Dir, Current_Dir); - Update.Enabled = false; + //Check for Internet + if (Check_Internet()) + { + setupUpdater(Current_Dir, Current_Dir); + + //Read Settings Json file + ReadSettingsAsync(); + } - //Read Settings Json file - ReadSettingsAsync(); + Update.Enabled = false; //Preferences Get_Preferences_Json(); @@ -88,40 +94,50 @@ private void updater_StatusUpdated(object sender, Pannella.Models.StatusUpdatedE private async void Update_Click(object sender, EventArgs e) { - textBox1.Clear(); - Button_Save.Enabled = false; + if (!Check_Internet()) + { + Message_Box form = new Message_Box(); + form.label1.Text = "No Internet Connection Detected!"; + form.Show(); + } + else + { - Update.Enabled = false; + textBox1.Clear(); + Button_Save.Enabled = false; - Save_Settings("No"); + Update.Enabled = false; - Current_Dir = Directory.GetCurrentDirectory(); + Save_Settings("No"); - try - { - string Location_Type = comboBox2.SelectedItem.ToString(); - string github_token = ServiceHelper.SettingsService.GetConfig().github_token; + Current_Dir = Directory.GetCurrentDirectory(); - // where are we updating to - if (Location_Type == "Current Directory") + try + { + string Location_Type = comboBox2.SelectedItem.ToString(); + string github_token = ServiceHelper.SettingsService.GetConfig().github_token; + + // where are we updating to + if (Location_Type == "Current Directory") + { + await UpdateCurrentDirectory(github_token, Current_Dir); + } + else if (Location_Type == "Removable Storage") + { + await UpdateRemoveableStorage(github_token, Current_Dir); + } + } + catch (Exception ex) { - await UpdateCurrentDirectory(github_token, Current_Dir); + Message_Box form = new Message_Box(); + form.label1.Text = ex.ToString(); + form.Show(); } - else if (Location_Type == "Removable Storage") + finally { - await UpdateRemoveableStorage(github_token, Current_Dir); + Button_Save.Enabled = true; } } - catch (Exception ex) - { - Message_Box form = new Message_Box(); - form.label1.Text = ex.ToString(); - form.Show(); - } - finally - { - Button_Save.Enabled = true; - } } private void updater_ProgressUpdated(object sender, DownloadProgressEventArgs e) @@ -546,125 +562,135 @@ private async void Button_Save_Click(object sender, EventArgs e) private async void Save_Settings(string ShowBox) { - //string value = Alternate_Location.Text; - Pannella.Models.Settings.Config config = ServiceHelper.SettingsService.GetConfig(); - - //GitHub Token - //config.github_token = value; - - //Alternate Arcade Files - if (Toggle_Alternatives.Checked == true) + if (!Check_Internet()) { - config.skip_alternative_assets = true; + Message_Box form = new Message_Box(); + form.label1.Text = "No Internet Connection Detected!"; + form.Show(); } else { - config.skip_alternative_assets = false; - } - //Alternate Download Location - if (Toggle_Alternate.Checked == true) - { - config.use_custom_archive = true; + //string value = Alternate_Location.Text; + Pannella.Models.Settings.Config config = ServiceHelper.SettingsService.GetConfig(); - ServiceHelper.SettingsService.GetConfig().archives[1].url = Alternate_Location.Text; - } - else - { - config.use_custom_archive = false; - } + //GitHub Token + //config.github_token = value; - //Download Pocket Firmware - if (Toggle_Firmware.Checked == true) - { - config.download_firmware = true; - } - else - { - config.download_firmware = false; - } - //Download Assets - if (Toggle_Assets.Checked == true) - { - config.download_assets = true; - } - else - { - config.download_assets = false; - } - //Preserve Core Images - if (Toggle_Platforms.Checked == true) - { - config.preserve_platforms_folder = true; - } - else - { - config.preserve_platforms_folder = false; - } - //Delete Skipped Cores - if (Toggle_Skipped.Checked == true) - { - config.delete_skipped_cores = true; - } - else - { - config.delete_skipped_cores = false; - } - //Build Jsons - if (Toggle_Jsons.Checked == true) - { - config.build_instance_jsons = true; - } - else - { - config.build_instance_jsons = false; - } - //Jotego Rename - if (Toggle_Jotego.Checked == true) - { - config.fix_jt_names = true; - } - else - { - config.fix_jt_names = false; - } - //CRC Check - if (Toggle_CRC.Checked == true) - { - config.crc_check = true; - } - else - { - config.crc_check = false; - } - //Backup Saves - if (Toggle_Backup_Saves.Checked == true) - { - config.backup_saves = true; - } - else - { - config.backup_saves = false; - } + //Alternate Arcade Files + if (Toggle_Alternatives.Checked == true) + { + config.skip_alternative_assets = true; + } + else + { + config.skip_alternative_assets = false; + } - //Save Sttings - SettingsService _settings; - string Current_Dir = Directory.GetCurrentDirectory(); - _settings = new SettingsService(Current_Dir); + //Alternate Download Location + if (Toggle_Alternate.Checked == true) + { + config.use_custom_archive = true; - _settings.UpdateConfig(config); - _settings.Save(); - //ServiceHelper.SettingsService.UpdateConfig(config); - //ServiceHelper.SettingsService.Save(); + ServiceHelper.SettingsService.GetConfig().archives[1].url = Alternate_Location.Text; + } + else + { + config.use_custom_archive = false; + } + //Download Pocket Firmware + if (Toggle_Firmware.Checked == true) + { + config.download_firmware = true; + } + else + { + config.download_firmware = false; + } + //Download Assets + if (Toggle_Assets.Checked == true) + { + config.download_assets = true; + } + else + { + config.download_assets = false; + } + //Preserve Core Images + if (Toggle_Platforms.Checked == true) + { + config.preserve_platforms_folder = true; + } + else + { + config.preserve_platforms_folder = false; + } + //Delete Skipped Cores + if (Toggle_Skipped.Checked == true) + { + config.delete_skipped_cores = true; + } + else + { + config.delete_skipped_cores = false; + } + //Build Jsons + if (Toggle_Jsons.Checked == true) + { + config.build_instance_jsons = true; + } + else + { + config.build_instance_jsons = false; + } + //Jotego Rename + if (Toggle_Jotego.Checked == true) + { + config.fix_jt_names = true; + } + else + { + config.fix_jt_names = false; + } + //CRC Check + if (Toggle_CRC.Checked == true) + { + config.crc_check = true; + } + else + { + config.crc_check = false; + } + //Backup Saves + if (Toggle_Backup_Saves.Checked == true) + { + config.backup_saves = true; + } + else + { + config.backup_saves = false; + } - //Show Message Box - if (ShowBox == "Yes") - { + //Save Sttings + SettingsService _settings; + string Current_Dir = Directory.GetCurrentDirectory(); + _settings = new SettingsService(Current_Dir); - Message_Box form = new Message_Box(); - form.label1.Text = "Settings Saved!"; - form.Show(); + _settings.UpdateConfig(config); + _settings.Save(); + //ServiceHelper.SettingsService.UpdateConfig(config); + //ServiceHelper.SettingsService.Save(); + + + //Show Message Box + if (ShowBox == "Yes") + { + + Message_Box form = new Message_Box(); + form.label1.Text = "Settings Saved!"; + form.Show(); + } } } @@ -741,6 +767,8 @@ private void Save_Preferences_Json() } private void setupUpdater(string path, string config_path) { + try + { ServiceHelper.Initialize(path, config_path, updater_StatusUpdated, _updater_UpdateProcessComplete, true); _updater = new CoreUpdaterService( ServiceHelper.UpdateDirectory, @@ -750,8 +778,32 @@ private void setupUpdater(string path, string config_path) ServiceHelper.CoresService ); - _updater.StatusUpdated += updater_StatusUpdated; - _updater.UpdateProcessComplete += _updater_UpdateProcessComplete; + _updater.StatusUpdated += updater_StatusUpdated; + _updater.UpdateProcessComplete += _updater_UpdateProcessComplete; + } + catch(Exception ex) + { + Message_Box form = new Message_Box(); + form.label1.Text = ex.ToString(); + form.Show(); + } + } + public static bool Check_Internet() + { + try + { + using (var client = new WebClient()) + { + using (var stream = client.OpenRead("http://www.google.com")) + { + return true; + } + } + } + catch + { + return false; + } } } } diff --git a/Forms/Main/Form1.Designer.cs b/Forms/Main/Form1.Designer.cs index 4c8c27e..2f278d8 100644 --- a/Forms/Main/Form1.Designer.cs +++ b/Forms/Main/Form1.Designer.cs @@ -59,12 +59,12 @@ private void InitializeComponent() guna2BorderlessForm1 = new Guna.UI2.WinForms.Guna2BorderlessForm(components); guna2DragControl1 = new Guna.UI2.WinForms.Guna2DragControl(components); Panel_Top = new Guna.UI2.WinForms.Guna2Panel(); + No_Internet = new Guna.UI2.WinForms.Guna2Button(); guna2HtmlLabel1 = new Guna.UI2.WinForms.Guna2HtmlLabel(); guna2ControlBox1 = new Guna.UI2.WinForms.Guna2ControlBox(); guna2ControlBox2 = new Guna.UI2.WinForms.Guna2ControlBox(); guna2ControlBox3 = new Guna.UI2.WinForms.Guna2ControlBox(); Update_Available = new Guna.UI2.WinForms.Guna2Button(); - No_Internet = new Guna.UI2.WinForms.Guna2Button(); guna2ResizeForm1 = new Guna.UI2.WinForms.Guna2ResizeForm(components); Panel_Menu = new Panel(); flowLayoutPanel1 = new FlowLayoutPanel(); @@ -109,12 +109,12 @@ private void InitializeComponent() Panel_Top.BackColor = Color.FromArgb(24, 25, 26); Panel_Top.BorderColor = Color.Transparent; Panel_Top.BorderRadius = 22; + Panel_Top.Controls.Add(No_Internet); Panel_Top.Controls.Add(guna2HtmlLabel1); Panel_Top.Controls.Add(guna2ControlBox1); Panel_Top.Controls.Add(guna2ControlBox2); Panel_Top.Controls.Add(guna2ControlBox3); Panel_Top.Controls.Add(Update_Available); - Panel_Top.Controls.Add(No_Internet); Panel_Top.CustomizableEdges = customizableEdges23; Panel_Top.Dock = DockStyle.Top; Panel_Top.Location = new Point(0, 0); @@ -123,6 +123,34 @@ private void InitializeComponent() Panel_Top.Size = new Size(1399, 46); Panel_Top.TabIndex = 28; // + // No_Internet + // + No_Internet.Anchor = AnchorStyles.Right; + No_Internet.AutoRoundedCorners = true; + No_Internet.BorderRadius = 14; + No_Internet.Cursor = Cursors.Hand; + No_Internet.CustomizableEdges = customizableEdges13; + No_Internet.DefaultAutoSize = true; + No_Internet.DisabledState.BorderColor = Color.FromArgb(192, 0, 0); + No_Internet.DisabledState.CustomBorderColor = Color.FromArgb(192, 0, 0); + No_Internet.DisabledState.FillColor = Color.FromArgb(192, 0, 0); + No_Internet.DisabledState.ForeColor = SystemColors.ControlLightLight; + No_Internet.Enabled = false; + No_Internet.FillColor = Color.FromArgb(192, 0, 0); + No_Internet.FocusedColor = Color.FromArgb(192, 0, 0); + No_Internet.Font = new Font("Segoe UI", 11F, FontStyle.Bold, GraphicsUnit.Point); + No_Internet.ForeColor = Color.White; + No_Internet.HoverState.FillColor = Color.FromArgb(192, 0, 0); + No_Internet.Location = new Point(596, 7); + No_Internet.Margin = new Padding(100, 20, 3, 3); + No_Internet.Name = "No_Internet"; + No_Internet.PressedColor = Color.FromArgb(192, 0, 0); + No_Internet.ShadowDecoration.CustomizableEdges = customizableEdges14; + No_Internet.Size = new Size(271, 31); + No_Internet.TabIndex = 4; + No_Internet.Text = "No Internet Connection Detected!"; + No_Internet.Visible = false; + // // guna2HtmlLabel1 // guna2HtmlLabel1.Anchor = AnchorStyles.Left; @@ -139,14 +167,14 @@ private void InitializeComponent() // guna2ControlBox1.Anchor = AnchorStyles.Top | AnchorStyles.Right; guna2ControlBox1.ControlBoxType = Guna.UI2.WinForms.Enums.ControlBoxType.MinimizeBox; - guna2ControlBox1.CustomizableEdges = customizableEdges13; + guna2ControlBox1.CustomizableEdges = customizableEdges15; guna2ControlBox1.FillColor = Color.Transparent; guna2ControlBox1.HoverState.BorderColor = Color.FromArgb(59, 62, 78); guna2ControlBox1.HoverState.FillColor = Color.FromArgb(59, 62, 78); guna2ControlBox1.IconColor = Color.White; guna2ControlBox1.Location = new Point(1301, 7); guna2ControlBox1.Name = "guna2ControlBox1"; - guna2ControlBox1.ShadowDecoration.CustomizableEdges = customizableEdges14; + guna2ControlBox1.ShadowDecoration.CustomizableEdges = customizableEdges16; guna2ControlBox1.Size = new Size(28, 28); guna2ControlBox1.TabIndex = 0; // @@ -154,14 +182,14 @@ private void InitializeComponent() // guna2ControlBox2.Anchor = AnchorStyles.Top | AnchorStyles.Right; guna2ControlBox2.ControlBoxType = Guna.UI2.WinForms.Enums.ControlBoxType.MaximizeBox; - guna2ControlBox2.CustomizableEdges = customizableEdges15; + guna2ControlBox2.CustomizableEdges = customizableEdges17; guna2ControlBox2.FillColor = Color.Transparent; guna2ControlBox2.HoverState.BorderColor = Color.FromArgb(59, 62, 78); guna2ControlBox2.HoverState.FillColor = Color.FromArgb(59, 62, 78); guna2ControlBox2.IconColor = Color.White; guna2ControlBox2.Location = new Point(1332, 7); guna2ControlBox2.Name = "guna2ControlBox2"; - guna2ControlBox2.ShadowDecoration.CustomizableEdges = customizableEdges16; + guna2ControlBox2.ShadowDecoration.CustomizableEdges = customizableEdges18; guna2ControlBox2.Size = new Size(28, 28); guna2ControlBox2.TabIndex = 1; // @@ -169,7 +197,7 @@ private void InitializeComponent() // guna2ControlBox3.Anchor = AnchorStyles.Top | AnchorStyles.Right; guna2ControlBox3.Animated = true; - guna2ControlBox3.CustomizableEdges = customizableEdges17; + guna2ControlBox3.CustomizableEdges = customizableEdges19; guna2ControlBox3.FillColor = Color.Transparent; guna2ControlBox3.Font = new Font("Segoe UI", 9F, FontStyle.Regular, GraphicsUnit.Point); guna2ControlBox3.HoverState.BorderColor = Color.FromArgb(59, 62, 78); @@ -177,7 +205,7 @@ private void InitializeComponent() guna2ControlBox3.IconColor = Color.White; guna2ControlBox3.Location = new Point(1363, 7); guna2ControlBox3.Name = "guna2ControlBox3"; - guna2ControlBox3.ShadowDecoration.CustomizableEdges = customizableEdges18; + guna2ControlBox3.ShadowDecoration.CustomizableEdges = customizableEdges20; guna2ControlBox3.Size = new Size(28, 28); guna2ControlBox3.TabIndex = 2; // @@ -187,7 +215,7 @@ private void InitializeComponent() Update_Available.AutoRoundedCorners = true; Update_Available.BorderRadius = 14; Update_Available.Cursor = Cursors.Hand; - Update_Available.CustomizableEdges = customizableEdges19; + Update_Available.CustomizableEdges = customizableEdges21; Update_Available.DefaultAutoSize = true; Update_Available.DisabledState.BorderColor = Color.DarkGray; Update_Available.DisabledState.CustomBorderColor = Color.DarkGray; @@ -198,38 +226,13 @@ private void InitializeComponent() Update_Available.Location = new Point(1088, 7); Update_Available.Margin = new Padding(100, 20, 3, 3); Update_Available.Name = "Update_Available"; - Update_Available.ShadowDecoration.CustomizableEdges = customizableEdges20; + Update_Available.ShadowDecoration.CustomizableEdges = customizableEdges22; Update_Available.Size = new Size(190, 31); Update_Available.TabIndex = 3; Update_Available.Text = "App Update Available!"; Update_Available.Visible = false; Update_Available.Click += Update_Available_Click; // - // No_Internet - // - No_Internet.Anchor = AnchorStyles.Right; - No_Internet.AutoRoundedCorners = true; - No_Internet.BorderRadius = 14; - No_Internet.Cursor = Cursors.Hand; - No_Internet.CustomizableEdges = customizableEdges21; - No_Internet.DefaultAutoSize = true; - No_Internet.DisabledState.BorderColor = Color.DarkGray; - No_Internet.DisabledState.CustomBorderColor = Color.DarkGray; - No_Internet.DisabledState.FillColor = Color.FromArgb(169, 169, 169); - No_Internet.DisabledState.ForeColor = Color.FromArgb(141, 141, 141); - No_Internet.Enabled = false; - No_Internet.FillColor = Color.FromArgb(192, 0, 0); - No_Internet.Font = new Font("Segoe UI", 11F, FontStyle.Bold, GraphicsUnit.Point); - No_Internet.ForeColor = Color.White; - No_Internet.Location = new Point(596, 7); - No_Internet.Margin = new Padding(100, 20, 3, 3); - No_Internet.Name = "No_Internet"; - No_Internet.ShadowDecoration.CustomizableEdges = customizableEdges22; - No_Internet.Size = new Size(271, 31); - No_Internet.TabIndex = 4; - No_Internet.Text = "No Internet Connection Detected!"; - No_Internet.Visible = false; - // // guna2ResizeForm1 // guna2ResizeForm1.TargetForm = this; @@ -493,12 +496,11 @@ private void InitializeComponent() update_Pocket1.Pocket_Drive = null; update_Pocket1.Size = new Size(1136, 660); update_Pocket1.TabIndex = 0; - update_Pocket1.Load += update_Pocket1_Load; // // image_Packs1 // image_Packs1.BackColor = Color.FromArgb(59, 62, 78); - image_Packs1.Current_Dir = "\\\\?\\C:\\Users\\jsavage\\AppData\\Local\\Microsoft\\VisualStudio\\17.0_1fa20820\\WinFormsDesigner\\421upsnr.pvw"; + image_Packs1.Current_Dir = ""; image_Packs1.Dock = DockStyle.Fill; image_Packs1.ForeColor = SystemColors.ControlLightLight; image_Packs1.Location = new Point(0, 25); @@ -580,7 +582,6 @@ private void InitializeComponent() Margin = new Padding(2); Name = "Form1"; StartPosition = FormStartPosition.CenterScreen; - Load += Form1_Load_1; Panel_Top.ResumeLayout(false); Panel_Top.PerformLayout(); Panel_Menu.ResumeLayout(false); diff --git a/Forms/Main/Form1.cs b/Forms/Main/Form1.cs index 68fc294..15565e2 100644 --- a/Forms/Main/Form1.cs +++ b/Forms/Main/Form1.cs @@ -1,8 +1,10 @@ using Pannella; using Pocket_Updater.Forms.Message_Box; using System.Diagnostics; +using System.Globalization; using System.Net; using System.Net.Http.Headers; +using System.Net.NetworkInformation; using System.Text.Json; namespace Pocket_Updater @@ -17,19 +19,26 @@ public Form1() { InitializeComponent(); - //Check for Internet Connection and App Updates - try + if (Check_Internet()) { - using (WebClient client2 = new WebClient()) + //Check for App Updates + try { - _ = CheckVersion_Load(); + using (WebClient client2 = new WebClient()) + { + _ = CheckVersion_Load(); + } + } + catch + { + Message_Box form = new Message_Box(); + form.label1.Text = "Failed to check for App Updates!"; + form.Show(); } } - catch + else { - Message_Box form = new Message_Box(); - form.label1.Text = "Failed to check for App Updates!"; - form.Show(); + No_Internet.Visible = true; } } @@ -83,15 +92,13 @@ async static Task CheckVersion() } catch (HttpRequestException e) { + Message_Box form = new Message_Box(); + form.label1.Text = e.ToString(); + form.Show(); return false; } } - - private void Form1_Load_1(object sender, EventArgs e) - { - - } private void Update_Pocket_Click(object sender, EventArgs e) { Hide_Controls(); @@ -158,10 +165,22 @@ private void About_Click(object sender, EventArgs e) Hide_Controls(); about1.Visible = true; } - - private void update_Pocket1_Load(object sender, EventArgs e) + public static bool Check_Internet() { - + try + { + using (var client = new WebClient()) + { + using (var stream = client.OpenRead("http://www.google.com")) + { + return true; + } + } + } + catch + { + return false; + } } } }