-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDownloadForm.cs
76 lines (73 loc) · 3.37 KB
/
DownloadForm.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
using System.ComponentModel;
using System.Diagnostics;
using System.Net;
namespace tModDownloader
{
public partial class DownloadForm : Form
{
string currentDir = Environment.CurrentDirectory;
public DownloadForm(string saveDirectory)
{
InitializeComponent();
progressBar1.Maximum = 100;
progressBar1.Style = ProgressBarStyle.Blocks;
InitiateDownload(saveDirectory);
}
private async void InitiateDownload(string saveDirectory)
{
var totalMods = Config.selectedMods.Count;
var downloaded = 0;
var percentPerMods = 100 / totalMods;
var currentDir = Environment.CurrentDirectory;
logRTB.Text += "Save Directory: " + saveDirectory + "\n";
foreach (ModItem item in Config.selectedMods)
{
progressLabel.Text = downloaded + "/" + totalMods + " downloaded.";
logRTB.Text += "Downloading mod " + item.Title + "...\n";
string cliargs = "+login anonymous +workshop_download_item 1281930 " + item.ID + " +exit";
Process scmd = new Process();
scmd.StartInfo.FileName = Path.Combine(currentDir, "steamcmd", "steamcmd.exe");
scmd.StartInfo.Arguments = cliargs;
scmd.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
scmd.StartInfo.CreateNoWindow = true;
scmd.Start();
await scmd.WaitForExitAsync();
if (scmd.ExitCode == 0)
{
downloaded += 1;
progressBar1.Value += percentPerMods;
}
else
{
MessageBox.Show("An error occured while trying to download " + item.Title + ". Aborting...", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
break;
}
}
if (downloaded == totalMods)
{
logRTB.Text += "Copying mod files to save directory...\n";
progressBar1.Style = ProgressBarStyle.Marquee;
progressBar1.MarqueeAnimationSpeed = 50;
var workshopDir = Path.Combine(currentDir, "steamcmd", "steamapps", "workshop", "content", "1281930");
foreach(string dir in Directory.GetDirectories(workshopDir))
{
var modDir = Path.Combine(workshopDir, dir);
List<float> verList = new List<float>();
foreach(string i in Directory.GetDirectories(modDir))
{
verList.Add(float.Parse(new DirectoryInfo(i).Name));
}
Console.WriteLine(verList.Max().ToString());
var realModDir = Path.Combine(workshopDir, dir, verList.Max().ToString());
foreach(string file in Directory.GetFiles(realModDir, "*.tmod"))
{
logRTB.Text += "Copying " + Path.GetFileName(file) + " (" + verList.Max().ToString() + ")...\n";
File.Copy(file, Path.Combine(saveDirectory, Path.GetFileName(file)));
}
}
logRTB.Text += "Done.\nYou may now close this window.";
statusLabel.Text = "You may now close this window.";
}
}
}
}