Skip to content

Commit

Permalink
direct upload
Browse files Browse the repository at this point in the history
  • Loading branch information
SamuelTulach committed Aug 21, 2020
1 parent 4bffee1 commit e1f50eb
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 21 deletions.
1 change: 1 addition & 0 deletions localization/Czech.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"SettingsForm_Language": "Jazyk",
"SettingsForm_Save": "Uložit",
"SettingsForm_Open": "Otevřit soubor nastavení",
"SettingsForm_DirectUpload": "Nahrát soubor ihned",
"UploadForm_Info": "Informace o souboru",
"UploadForm_Upload": "Nahrát",
"UploadForm_Cancel": "Zrušit",
Expand Down
1 change: 1 addition & 0 deletions localization/English.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"SettingsForm_Language": "Language",
"SettingsForm_Save": "Save",
"SettingsForm_Open": "Open settings file",
"SettingsForm_DirectUpload": "Direct file upload",
"UploadForm_Info": "File information",
"UploadForm_Upload": "Upload",
"UploadForm_Cancel": "Cancel",
Expand Down
1 change: 1 addition & 0 deletions uploader/uploader/LocalizationBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class LocalizationBase
public string SettingsForm_Language = "Language";
public string SettingsForm_Save = "Save";
public string SettingsForm_Open = "Open settings file";
public string SettingsForm_DirectUpload = "Direct file upload";

public string UploadForm_Info = "File information";
public string UploadForm_Upload = "Upload";
Expand Down
1 change: 1 addition & 0 deletions uploader/uploader/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class Settings
{
public string ApiKey = "";
public string Language = "";
public bool DirectUpload = false;

public static string GetSettingsFilename()
{
Expand Down
20 changes: 16 additions & 4 deletions uploader/uploader/SettingsForm.Designer.cs

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

5 changes: 4 additions & 1 deletion uploader/uploader/SettingsForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ private void SettingsForm_Load(object sender, EventArgs e)
var settings = Settings.LoadSettings();

apiTextbox.Text = settings.ApiKey;
directCheckbox.Checked = settings.DirectUpload;

var languages = LocalizationHelper.GetLanguages();
languageCombo.Items.Clear();
Expand All @@ -56,6 +57,7 @@ private void SettingsForm_Load(object sender, EventArgs e)
saveButton.Text = LocalizationHelper.Base.SettingsForm_Save;
openButton.Text = LocalizationHelper.Base.SettingsForm_Open;
this.Text = LocalizationHelper.Base.SettingsForm_Title;
directCheckbox.Text = LocalizationHelper.Base.SettingsForm_DirectUpload;

//LocalizationHelper.Export();
}
Expand All @@ -80,7 +82,8 @@ private void saveButton_Click(object sender, EventArgs e)
var settings = new Settings
{
ApiKey = apiTextbox.Text,
Language = languageCombo.Text
Language = languageCombo.Text,
DirectUpload = directCheckbox.Checked
};

Settings.SaveSettings(settings);
Expand Down
45 changes: 35 additions & 10 deletions uploader/uploader/UploadForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,17 @@ private void Finish(bool resetText)
uploadButton.Text = LocalizationHelper.Base.UploadForm_Upload;
}

private void CloseWindow()
{
if (InvokeRequired)
{
this.Invoke(new Action(() => CloseWindow()));
return;
}

this.Close();
}

private void Upload()
{
if (string.IsNullOrEmpty(_settings.ApiKey))
Expand Down Expand Up @@ -98,6 +109,8 @@ private void Upload()
{
var reportLink = reportJson.permalink.ToString();
Process.Start(reportLink);

if (_settings.DirectUpload) CloseWindow();
}
catch (RuntimeBinderException)
{
Expand All @@ -116,6 +129,8 @@ private void Upload()
{
var scanLink = scanJson.permalink.ToString();
Process.Start(scanLink);

if (_settings.DirectUpload) CloseWindow();
}
catch (RuntimeBinderException)
{
Expand All @@ -129,6 +144,20 @@ private void Upload()
Finish(true);
}

private void StartUploadThread()
{
if (_uploadThread != null && _uploadThread.IsAlive)
{
_uploadThread.Abort();
uploadButton.Text = LocalizationHelper.Base.UploadForm_Upload;
return;
}
uploadButton.Text = LocalizationHelper.Base.UploadForm_Cancel;

_uploadThread = new Thread(Upload);
_uploadThread.Start();
}

private void UploadForm_Load(object sender, EventArgs e)
{
mdTextbox.Text = Utils.GetMD5(_fileName);
Expand All @@ -138,20 +167,16 @@ private void UploadForm_Load(object sender, EventArgs e)
settingsGroup.Text = LocalizationHelper.Base.UploadForm_Info;
uploadButton.Text = LocalizationHelper.Base.UploadForm_Upload;
statusLabel.Text = LocalizationHelper.Base.Message_Idle;
}

private void uploadButton_Click(object sender, EventArgs e)
{
if (_uploadThread != null && _uploadThread.IsAlive)
if (_settings.DirectUpload)
{
_uploadThread.Abort();
uploadButton.Text = LocalizationHelper.Base.UploadForm_Upload;
return;
StartUploadThread();
}
uploadButton.Text = LocalizationHelper.Base.UploadForm_Cancel;
}

_uploadThread = new Thread(Upload);
_uploadThread.Start();
private void uploadButton_Click(object sender, EventArgs e)
{
StartUploadThread();
}

private void UploadForm_FormClosing(object sender, FormClosingEventArgs e)
Expand Down
4 changes: 2 additions & 2 deletions uploader/uploader/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="8.0.3" targetFramework="net472" />
<package id="RestSharp" version="106.11.2" targetFramework="net472" />
<package id="Newtonsoft.Json" version="12.0.3" targetFramework="net46" />
<package id="RestSharp" version="106.11.4" targetFramework="net46" />
</packages>
8 changes: 4 additions & 4 deletions uploader/uploader/uploader.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\darkui\DarkUI.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="RestSharp, Version=106.11.2.0, Culture=neutral, PublicKeyToken=598062e77f915f75, processorArchitecture=MSIL">
<HintPath>..\packages\RestSharp.106.11.2\lib\net452\RestSharp.dll</HintPath>
<Reference Include="RestSharp, Version=106.11.4.0, Culture=neutral, PublicKeyToken=598062e77f915f75, processorArchitecture=MSIL">
<HintPath>..\packages\RestSharp.106.11.4\lib\net452\RestSharp.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand Down

0 comments on commit e1f50eb

Please sign in to comment.