Skip to content

Commit

Permalink
Internet Connection Checks
Browse files Browse the repository at this point in the history
  • Loading branch information
RetroDriven committed May 12, 2024
1 parent c8c87b8 commit 73f5247
Show file tree
Hide file tree
Showing 6 changed files with 382 additions and 234 deletions.
23 changes: 21 additions & 2 deletions Controls/Image_Packs/Image_Packs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ public Image_Packs()
//Preferences
Get_Preferences_Json();

GetPacks();

if (Check_Internet())
{
GetPacks();
}
}
public void PopulateDrives()
{
Expand Down Expand Up @@ -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;
}
}
}
}
63 changes: 47 additions & 16 deletions Controls/Manage_Cores/ManageCores.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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;
}
}
}
}
76 changes: 51 additions & 25 deletions Controls/Organize_Cores/Organize_Cores.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
}
}
}
}
Loading

0 comments on commit 73f5247

Please sign in to comment.