Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Vlad-00003 committed Jan 23, 2020
1 parent 709edb0 commit 51075bd
Show file tree
Hide file tree
Showing 9 changed files with 159 additions and 126 deletions.
25 changes: 12 additions & 13 deletions Classes/CustomSkin.cs
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
using Newtonsoft.Json;
using RustWorkshopUploader.Localization;
using Steamworks;
using System;
using System;
using System.IO;
using System.Windows.Forms;
using Newtonsoft.Json;
using RustWorkshopUploader.Localization;
using Steamworks;

namespace RustWorkshopUploader.Classes
{
internal class CustomSkin
{
public string Description;
public ulong ItemId;
public string Title;

[JsonIgnore]
[JsonIgnore]
public string FilePath;

public ulong ItemId;
public string Title;

[JsonIgnore]
[JsonIgnore]
public string ItemIdString => ItemId.ToString();

[JsonIgnore]
public Manifest Manifest => Manifest.DefaultManifest.WithData(DateTime.UtcNow, SteamClient.SteamId);

[JsonIgnore]
[JsonIgnore]
public string ManifestText => JsonConvert.SerializeObject(Manifest, Formatting.Indented);

public override string ToString()
Expand All @@ -42,8 +41,7 @@ public void Save()
{
File.WriteAllText(FilePath, ToString());
}



public static CustomSkin FromFile(string path)
{
var text = File.ReadAllText(path);
Expand All @@ -56,7 +54,8 @@ public static CustomSkin FromFile(string path)
catch (Exception ex)
{
skin = new CustomSkin();
MessageBox.Show(string.Format(strings.CustomSkin_DeserializationFailed, path, ex), strings.Message_Error,
MessageBox.Show(string.Format(strings.CustomSkin_DeserializationFailed, path, ex),
strings.Message_Error,
MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
Expand Down
20 changes: 10 additions & 10 deletions Classes/Manifest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace RustWorkshopUploader.Classes
{
class Manifest
internal class Manifest
{
public int Version { get; set; }

Expand All @@ -15,18 +15,11 @@ class Manifest

public Group[] Groups { get; set; }

public Manifest WithData(DateTime publishDate, ulong authorId)
{
this.PublishDate = publishDate;
this.AuthorId = authorId;
return this;
}

public static Manifest DefaultManifest => new Manifest
{
Version = 3,
ItemType = "CustomItem",
Groups = new Group[]
Groups = new[]
{
new Group
{
Expand All @@ -51,6 +44,13 @@ public Manifest WithData(DateTime publishDate, ulong authorId)
}
};

public Manifest WithData(DateTime publishDate, ulong authorId)
{
PublishDate = publishDate;
AuthorId = authorId;
return this;
}

public class Group
{
public Dictionary<string, string> Textures { get; set; } = new Dictionary<string, string>();
Expand All @@ -76,4 +76,4 @@ public ColorEntry(float r, float g, float b)
public float b { get; set; }
}
}
}
}
10 changes: 10 additions & 0 deletions Form1.Designer.cs

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

92 changes: 48 additions & 44 deletions Form1.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
using RustWorkshopUploader.Classes;
using RustWorkshopUploader.Localization;
using RustWorkshopUploader.Properties;
using Steamworks;
using Steamworks.Ugc;
using System;
using System;
using System.Diagnostics;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Windows.Forms;
using RustWorkshopUploader.Classes;
using RustWorkshopUploader.Localization;
using RustWorkshopUploader.Properties;
using Steamworks;
using Steamworks.Ugc;

namespace RustWorkshopUploader
{
Expand Down Expand Up @@ -127,7 +127,7 @@ private void btnDo_Click(object sender, EventArgs e)

PublishToSteam();
}

private async void PublishToSteam()
{
ProgressBar.Value = 0;
Expand All @@ -150,7 +150,8 @@ private async void PublishToSteam()
if (!publishResult.Success)
{
ProgressBar.Value = 0;
MessageBox.Show(string.Format(strings.ErrorText, publishResult.Result), strings.Message_Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
MessageBox.Show(string.Format(strings.ErrorText, publishResult.Result), strings.Message_Error,
MessageBoxButtons.OK, MessageBoxIcon.Error);
SetStatus(true);
return;
}
Expand All @@ -175,7 +176,7 @@ private async void PublishToSteam()
UpdateTexts();
var result = MessageBox.Show(strings.Publish_OpenBrowser, strings.Message_Success, MessageBoxButtons.YesNo,
MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
if(result == DialogResult.Yes)
if (result == DialogResult.Yes)
Process.Start("http://steamcommunity.com/sharedfiles/filedetails/?id=" + Editing.ItemIdString);
SetStatus(true);
}
Expand All @@ -192,6 +193,43 @@ private void button1_Click(object sender, EventArgs e)
btnDo.Text = strings.BtnDo_Upload;
}

private void btnDo_EnabledChanged(object sender, EventArgs e)
{
if (btnDo.Enabled && Editing != null)
{
if (Editing.ItemId > 0)
btnDo.Text = strings.BtnDo_Update;
else
btnDo.Text = strings.BtnDo_Upload;
return;
}

btnDo.Text = strings.BtnDo_Uploading;
}

private new void Closed(object sender, FormClosedEventArgs e)
{
#if !DEBUG
if (MessageBox.Show(strings.AdvMessage, strings.AdvMessage_Title, MessageBoxButtons.YesNo) == DialogResult.Yes)
{
Process.Start("https://rustplugin.ru");
}
#endif
}

private void englishToolStripMenuItem_Click(object sender, EventArgs e)
{
Settings.Default.Culture =
sender == englishToolStripMenuItem ? new CultureInfo("en") : new CultureInfo("ru");
Settings.Default.Save();
Application.Restart();
}

private void quitToolStripMenuItem_Click(object sender, EventArgs e)
{
Application.Exit();
}

#region Field updates

private bool _updating;
Expand Down Expand Up @@ -233,47 +271,13 @@ private void txtWorkshopDesc_TextChanged(object sender, EventArgs e)
if (!_updating)
Editing.Description = txtWorkshopDesc.Text;
}

private void txtWorkshopName_TextChanged(object sender, EventArgs e)
{
if (!_updating)
Editing.Title = txtWorkshopName.Text;
}

#endregion

private void btnDo_EnabledChanged(object sender, EventArgs e)
{
if (btnDo.Enabled && Editing != null)
{
if (Editing.ItemId > 0)
btnDo.Text = strings.BtnDo_Update;
else
btnDo.Text = strings.BtnDo_Upload;
return;
}
btnDo.Text = strings.BtnDo_Uploading;
}
private new void Closed(object sender, FormClosedEventArgs e)
{
#if !DEBUG
if (MessageBox.Show(strings.AdvMessage, strings.AdvMessage_Title, MessageBoxButtons.YesNo) == DialogResult.Yes)
{
Process.Start("https://rustplugin.ru");
}
#endif
}

private void englishToolStripMenuItem_Click(object sender, EventArgs e)
{
Settings.Default.Culture = sender == englishToolStripMenuItem ? new CultureInfo("en") : new CultureInfo("ru");
Settings.Default.Save();
Application.Restart();
}

private void quitToolStripMenuItem_Click(object sender, EventArgs e)
{
Application.Exit();
}
}
}
Loading

0 comments on commit 51075bd

Please sign in to comment.