Skip to content

Commit

Permalink
Added feature to open in Genshin Optimizer
Browse files Browse the repository at this point in the history
  • Loading branch information
Cupcak3 committed Feb 2, 2024
1 parent 5ba2fce commit 6d48bb1
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 40 deletions.
7 changes: 6 additions & 1 deletion InventoryKamera/data/GOOD.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,13 @@ private void WriteToJson(string outputFile)
{
using (var streamWriter = new StreamWriter(outputFile))
{
streamWriter.WriteLine(JsonConvert.SerializeObject(this).ToString());
streamWriter.WriteLine(ToString());
}
}

public override string ToString()
{
return JsonConvert.SerializeObject(this).ToString();
}
}
}
52 changes: 26 additions & 26 deletions InventoryKamera/ui/main/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 23 additions & 13 deletions InventoryKamera/ui/main/MainForm.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using InventoryKamera.ui;
using Microsoft.WindowsAPICodePack.Dialogs;
using Newtonsoft.Json;
using NHotkey;
using NHotkey.WindowsForms;
using Octokit;
Expand Down Expand Up @@ -251,11 +252,12 @@ private void StartButton_Clicked(object sender, EventArgs e)
Logger.Info("Exported data");

UserInterface.SetProgramStatus("Finished");
OpenOptimizerDialog(good);
}
catch (ThreadAbortException)
{
// Workers can get stuck if the thread is aborted or an exception is raised
if (!(data is null)) data.StopImageProcessorWorkers();
data?.StopImageProcessorWorkers();
UserInterface.SetProgramStatus("Scan stopped");
}
catch (NotImplementedException ex)
Expand All @@ -265,7 +267,7 @@ private void StartButton_Clicked(object sender, EventArgs e)
catch (Exception ex)
{
// Workers can get stuck if the thread is aborted or an exception is raised
if (!(data is null)) data.StopImageProcessorWorkers();
data?.StopImageProcessorWorkers();
while (ex.InnerException != null) ex = ex.InnerException;
UserInterface.AddError(ex.ToString());
UserInterface.SetProgramStatus("Scan aborted", ok: false);
Expand Down Expand Up @@ -295,6 +297,24 @@ private void StartButton_Clicked(object sender, EventArgs e)
}
}

private void OpenOptimizerDialog(GOOD data, bool skip = false)
{
if (!skip)
{
var message = "Scan complete! Would you like to upload the database to Genshin Optimizer?";
var result = MessageBox.Show(message, "Scan Complete", MessageBoxButtons.YesNo);
if (result == DialogResult.No)
return;
}
var t = new Thread(() => Clipboard.SetText(data.ToString()));
t.SetApartmentState(ApartmentState.STA);
t.Start();
t.Join();
MessageBox.Show("Content copied to your clipboard! Paste the content into the textbox when prompted.", "Data Copied", MessageBoxButtons.OK);
Process.Start(new ProcessStartInfo("https://frzyc.github.io/genshin-optimizer/#/setting") { UseShellExecute = true });

}

private void Github_Label_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
Process.Start("https://github.com/Andrewthe13th/Inventory_Kamera/");
Expand Down Expand Up @@ -490,8 +510,6 @@ private void ExportFolderMenuItem_Click(object sender, EventArgs e)
}
}



private void MainForm_Shown(object sender, EventArgs e)
{
CheckForKameraUpdates();
Expand Down Expand Up @@ -570,15 +588,7 @@ private void CheckForGenshinUpdates()

private void Export_Button_Click(object sender, EventArgs e)
{

var good = new GOOD(data);

if (data.Inventory.Size > 0 || data.Characters.Count > 0)
{
good.WriteToJSON(OutputPath_TextBox.Text);
Logger.Info("Manually exported data");
Process.Start($@"{OutputPath_TextBox.Text}");
}
OpenOptimizerDialog(new GOOD(data), true);
}

private void MainForm_Activate()
Expand Down

0 comments on commit 6d48bb1

Please sign in to comment.