Skip to content

Commit

Permalink
Improve setup project to download sdl3
Browse files Browse the repository at this point in the history
  • Loading branch information
Booklordofthedings committed Feb 24, 2025
1 parent 0c703ec commit adc7174
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
1 change: 1 addition & 0 deletions Setup/BeefProj.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
FileVersion = 1
Dependencies = {corlib = "*", MiniZ = "*"}

[Project]
Name = "Setup"
Expand Down
2 changes: 1 addition & 1 deletion Setup/BeefSpace.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FileVersion = 1
Projects = {Setup = {Path = "."}}
Projects = {Setup = {Path = "."}, MiniZ = "*"}

[Workspace]
StartupProject = "Setup"
29 changes: 28 additions & 1 deletion Setup/src/Program.bf
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
namespace Setup;

using System;
using System.IO;
using System.Diagnostics;

using MiniZ;

class Program
{
public static void Main()
{
if(AttemptToDownload() case .Ok)
return;

}

public static Result<void> AttemptToDownload()
{
ProcessStartInfo info = scope .();
info.UseShellExecute = false;
info.SetFileNameAndArguments("curl -o sdl3.zip -L https://github.com/libsdl-org/SDL/releases/download/release-3.2.4/SDL3-devel-3.2.4-mingw.zip");
info.SetFileNameAndArguments("curl -o sdl3.zip -L https://github.com/libsdl-org/SDL/releases/download/release-3.2.4/SDL3-devel-3.2.4-VC.zip");

SpawnedProcess p = scope .();
if(p.Start(info) case .Err)
Expand All @@ -25,6 +29,29 @@ class Program

if(p.ExitCode != 0)
return .Err;

if(!Directory.Exists("../dist"))
if(Directory.CreateDirectory("../dist") case .Err)
return .Err;

MiniZ.ZipArchive archive = .();
if(!MiniZ.ZipReaderInitFile(&archive, "sdl3.zip", .CompressedData))
return .Err;

for(int32 i < (.)MiniZ.ZipReaderGetNumFiles(&archive))
{
MiniZ.ZipArchiveFileStat stats = .();
if(!MiniZ.ZipReaderFileStat(&archive, i, &stats))
continue;

if(String.Compare(&stats.mFilename, "SDL3-3.2.4/lib/x64/SDL3.dll".Length, "SDL3-3.2.4/lib/x64/SDL3.dll", "SDL3-3.2.4/lib/x64/SDL3.dll".Length, false) == 0)
MiniZ.ZipReaderExtractToFile(&archive, i, "../dist/SDL3.dll", .CompressedData);
else if(String.Compare(&stats.mFilename, "SDL3-3.2.4/lib/x64/SDL3.lib".Length, "SDL3-3.2.4/lib/x64/SDL3.lib", "SDL3-3.2.4/lib/x64/SDL3.lib".Length, false) == 0)
MiniZ.ZipReaderExtractToFile(&archive, i, "../dist/SDL3.lib", .CompressedData);
}

MiniZ.ZipReaderEnd(&archive);

return .Ok;
}
}

0 comments on commit adc7174

Please sign in to comment.