Skip to content

Commit

Permalink
0.0.1-beta
Browse files Browse the repository at this point in the history
  • Loading branch information
FishiaT committed Nov 15, 2023
1 parent baae678 commit a1dfa95
Show file tree
Hide file tree
Showing 18 changed files with 1,384 additions and 1 deletion.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
# tModDownloader
A mod browser/downloader for tModLoader.
A mod browser/downloader for tModLoader and a dump of inefficient, unoptimized, slow and spagetti code.

tModDownloader is a standalone Steam Workshop mod browser/downloader written in C#. It works by parsing Steam Workshop HTML data and use `steamcmd` to download mods behind the scene.

## Compiling
To compile tModDownloader, you need .NET 6.0 SDK installed. After that just open `tModDownloader.sln` in Visual Studio and build the project. You need to put `steamcmd.exe` into a folder named `steamcmd` in the same directory as `tModDownloader.exe` to be able to download mods.

*Note: tModDownloader is Windows-only at the moment.
25 changes: 25 additions & 0 deletions tModDownloader.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.6.34031.178
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "tModDownloader", "tModDownloader\tModDownloader.csproj", "{AB78FE3B-2A6D-4FB3-9414-B97270D5EBE0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{AB78FE3B-2A6D-4FB3-9414-B97270D5EBE0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AB78FE3B-2A6D-4FB3-9414-B97270D5EBE0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AB78FE3B-2A6D-4FB3-9414-B97270D5EBE0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AB78FE3B-2A6D-4FB3-9414-B97270D5EBE0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {6CABEAF6-DE2D-4571-B71F-9CD12088CC5F}
EndGlobalSection
EndGlobal
7 changes: 7 additions & 0 deletions tModDownloader/Config.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace tModDownloader
{
public static class Config
{
public static List<ModItem> selectedMods = new List<ModItem>();
}
}
113 changes: 113 additions & 0 deletions tModDownloader/DownloadForm.Designer.cs

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

76 changes: 76 additions & 0 deletions tModDownloader/DownloadForm.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,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.";
}
}
}
}
120 changes: 120 additions & 0 deletions tModDownloader/DownloadForm.resx
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
Loading

0 comments on commit a1dfa95

Please sign in to comment.