-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForm1.cs
294 lines (246 loc) · 10.1 KB
/
Form1.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
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
{
public partial class FrmMain : Form
{
private CustomSkin _editing;
private string _folderPath;
public FrmMain()
{
InitializeComponent();
txtWorkshopId.Maximum = ulong.MaxValue;
Directory.CreateDirectory(Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + "CustomSkins");
}
private string ManifestPath => _folderPath + Path.DirectorySeparatorChar + "manifest.txt";
private void SetStatus(bool editing)
{
txtWorkshopId.Enabled = editing;
txtWorkshopDesc.Enabled = editing;
txtWorkshopName.Enabled = editing;
btnDo.Enabled = editing;
button1.Enabled = editing;
}
private static Image FromFile(string path)
{
var bytes = File.ReadAllBytes(path);
var ms = new MemoryStream(bytes);
var img = Image.FromStream(ms);
return img;
}
private void btnSelectFolder_Click(object sender, EventArgs e)
{
var openDialog = new OpenFileDialog {Filter = @"Image Files(*.PNG)|*.PNG"};
if (openDialog.ShowDialog() != DialogResult.OK)
return;
Image image;
try
{
image = FromFile(openDialog.FileName);
}
catch
{
MessageBox.Show(strings.Select_UnableToOpen, strings.Message_Error, MessageBoxButtons.OK,
MessageBoxIcon.Error);
SetStatus(false);
return;
}
if (image.Width != 512 && image.Height != 512)
{
MessageBox.Show(strings.Select_WrongResolution, strings.Message_Error, MessageBoxButtons.OK,
MessageBoxIcon.Error);
SetStatus(false);
return;
}
pictureBox2.Image = image;
pictureBox2.Invalidate();
_folderPath = string.Format("{1}{0}CustomSkins{0}Skin_{2}", Path.DirectorySeparatorChar,
Directory.GetCurrentDirectory(), Path.GetFileNameWithoutExtension(openDialog.FileName));
if (!Directory.Exists(_folderPath))
Directory.CreateDirectory(_folderPath);
if (File.Exists(_folderPath + Path.DirectorySeparatorChar + "icon.png"))
File.Delete(_folderPath + Path.DirectorySeparatorChar + "icon.png");
File.Copy(openDialog.FileName, _folderPath + Path.DirectorySeparatorChar + "icon.png");
var dataPath = GetDataPath(_folderPath);
_editing = File.Exists(dataPath) ? CustomSkin.FromFile(dataPath) : new CustomSkin();
_editing.FilePath = dataPath;
SetStatus(true);
UpdateTexts();
}
private string GetDataPath(string path)
{
var folderName = Path.GetFullPath(path).TrimEnd(Path.DirectorySeparatorChar);
var projectName = Path.GetFileName(folderName);
return Path.GetFullPath(Path.Combine(path, $"..\\{projectName}.data"));
}
private void btnDo_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(_folderPath))
{
MessageBox.Show(strings.Do_NoImage, strings.Message_Error, MessageBoxButtons.OK,
MessageBoxIcon.Error);
return;
}
if (string.IsNullOrEmpty(txtWorkshopName.Text))
{
MessageBox.Show(strings.Do_NoName, strings.Message_Error, MessageBoxButtons.OK,
MessageBoxIcon.Error);
return;
}
if (string.IsNullOrEmpty(txtWorkshopDesc.Text))
{
MessageBox.Show(strings.Do_NoDescription, strings.Message_Error, MessageBoxButtons.OK,
MessageBoxIcon.Error);
return;
}
if (!File.Exists(ManifestPath))
File.WriteAllText(ManifestPath, _editing.ManifestText);
PublishToSteam();
}
private async void PublishToSteam()
{
ProgressBar.Value = 0;
SetStatus(false);
var editor = _editing.ItemId == 0UL ? Editor.NewMicrotransactionFile : new Editor(_editing.ItemId);
ProgressBar.Value = 20;
editor = editor.ForAppId(Program.RustAppId).WithContent(_folderPath)
.WithPreviewFile(_folderPath + Path.DirectorySeparatorChar + "icon.png")
.WithTitle(_editing.Title).WithTag("Version3").WithTag("Skin")
.WithPublicVisibility().WithDescription(_editing.Description);
ProgressBar.Value = 40;
var publishResult = await editor.SubmitAsync();
ProgressBar.Value = 60;
if (!publishResult.Success)
{
ProgressBar.Value = 0;
if(publishResult.NeedsWorkshopAgreement)
{
if (MessageBox.Show(string.Format(strings.ErrorText, strings.NeedsWorkshopAgreement),
strings.Message_Error, MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.Yes)
{
Process.Start($"https://steamcommunity.com/workshop/workshoplegalagreement/?l={(IsEnglish ?"english":"russian") }");
}
}
else
{
MessageBox.Show(string.Format(strings.ErrorText, publishResult.Result), strings.Message_Error,
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
SetStatus(true);
return;
}
ProgressBar.Value = 85;
var item = await SteamUGC.QueryFileAsync(publishResult.FileId);
if (item == null)
{
ProgressBar.Value = 0;
MessageBox.Show(strings.Publish_RetreiveFailed, strings.Message_Error, MessageBoxButtons.OK,
MessageBoxIcon.Error);
SetStatus(true);
return;
}
ProgressBar.Value = 100;
_editing.Title = item.Value.Title;
_editing.Description = item.Value.Description;
_editing.ItemId = item.Value.Id;
_editing.Save();
UpdateTexts();
var result = MessageBox.Show(strings.Publish_OpenBrowser, strings.Message_Success, MessageBoxButtons.YesNo,
MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
if (result == DialogResult.Yes)
Process.Start("http://steamcommunity.com/sharedfiles/filedetails/?id=" + _editing.ItemIdString);
SetStatus(true);
}
private void txtWorkshopId_DoubleClick(object sender, EventArgs e)
{
if (txtWorkshopId.Value == 0) return;
//steam://url/CommunityFilePage/<PublishedFileId_t>
Process.Start("http://steamcommunity.com/sharedfiles/filedetails/?id=" + txtWorkshopId.Text);
}
private void button1_Click(object sender, EventArgs e)
{
txtWorkshopId.Value = 0ul;
btnDo.Text = strings.BtnDo_Upload;
}
private void btnDo_EnabledChanged(object sender, EventArgs e)
{
if (btnDo.Enabled && _editing != null)
{
btnDo.Text = _editing.ItemId > 0 ? strings.BtnDo_Update : 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 bool IsEnglish => Settings.Default.Culture.Name == "en";
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;
private void UpdateTexts()
{
_updating = true;
txtWorkshopId.Value = _editing.ItemId;
txtWorkshopName.Text = _editing.Title;
txtWorkshopDesc.Text = _editing.Description;
txtFolder.Text = _folderPath;
if (_editing.ItemId > 0)
btnDo.Text = strings.BtnDo_Update;
else
btnDo.Text = strings.BtnDo_Upload;
_updating = false;
}
private void txtWorkshopId_ValueChanged(object sender, EventArgs e)
{
if (txtWorkshopId.Value != 0)
{
txtWorkshopId.ForeColor = Color.Blue;
txtWorkshopId.Font = new Font("Microsoft Sans Serif", 8, FontStyle.Underline);
}
else
{
txtWorkshopId.ForeColor = Color.Black;
txtWorkshopId.Font = new Font("Microsoft Sans Serif", 8, FontStyle.Regular);
}
if (!_updating)
_editing.ItemId = decimal.ToUInt64(txtWorkshopId.Value);
}
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
}
}