Skip to content

Commit

Permalink
Merge branch 'NetStandard' of https://github.com/vchelaru/FlatRedBall
Browse files Browse the repository at this point in the history
…into NetStandard
  • Loading branch information
vchelaru committed Apr 2, 2024
2 parents a6eeed6 + 9c414be commit 6c076e6
Show file tree
Hide file tree
Showing 12 changed files with 136 additions and 36 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/Engine.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
name: Build Engine DLLs

on:
push:
branches: [ "NetStandard" ]
pull_request:
branches: [ "NetStandard" ]
workflow_dispatch:

jobs:
build:
Expand Down
7 changes: 2 additions & 5 deletions .github/workflows/glue.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
name: FlatRedBall Editor

on:
push:
branches: [ "NetStandard" ]
pull_request:
branches: [ "NetStandard" ]
workflow_dispatch:

jobs:
build:
Expand Down Expand Up @@ -49,7 +46,7 @@ jobs:
- name: Build
run: dotnet build -c ${{ matrix.configuration }} 'FlatRedBall\FRBDK\Glue\Glue with All.sln'

- name: Zip and upload templates
- name: Zip and upload FRBDK
env: # Or as an environment variable
username: ${{ secrets.FTPUSERNAME }}
password: ${{ secrets.FTPPASSWORD }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ public void Inflate(float horizontalAmount, float verticalAmount)
Bottom -= verticalAmount;
}

public bool IsPointInside(float x, float y)
{
return x >= Left && x <= Right && y <= Top && y >= Bottom;
}

public override string ToString()
{
return "Top:" + Top + " Left:" + Left + " Bottom:" + Bottom + " Right:" + Right;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,13 @@
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.IO.Compression.FileSystem" />
<Reference Include="System.IO.Compression.ZipFile, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<HintPath>..\packages\System.IO.Compression.ZipFile.4.3.0\lib\net46\System.IO.Compression.ZipFile.dll</HintPath>
<Private>True</Private>
<Private>True</Private>
</Reference>
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;
using FlatRedBall.IO;
using Ionic.Zip;

namespace BuildServerUploaderConsole.Processes
{
Expand Down Expand Up @@ -54,7 +58,7 @@ public CopyFrbdkAndPluginsToReleaseFolder(IResults results)
_excludeFiles.Add(@"Thumbs.db");
}

public override void ExecuteStep()
public override async Task ExecuteStepAsync()
{
//Create Directory
var frbdkForZipDirectory = DirectoryHelper.FrbdkForZipReleaseDirectory;
Expand All @@ -71,11 +75,14 @@ public override void ExecuteStep()
CopyDirectory(DirectoryHelper.FrbdkDirectory + extraTool, "Copied" + extraTool, subdirectoryName:extraTool);
}

if(Directory.Exists(DirectoryHelper.GumBuildDirectory))
{
// todo - this doesn't exist on github actions
CopyDirectory(DirectoryHelper.GumBuildDirectory, "Copied Gum", "Gum");
}
// Gum can't be built on github actions because it fails with dotnetbuild - something to do with
// it being net 4.7.1 or maybe XNA? So instead...
//if(Directory.Exists(DirectoryHelper.GumBuildDirectory))
//{
// CopyDirectory(DirectoryHelper.GumBuildDirectory, "Copied Gum", "Gum");
//}
// ... we'll download the file:
await DownloadGum();



Expand Down Expand Up @@ -103,6 +110,49 @@ public override void ExecuteStep()
CopyDirectory(DirectoryHelper.GluePublishDestinationFolder, "Copied " + DirectoryHelper.GluePublishDestinationFolder);
CopyDirectory(DirectoryHelper.FrbdkDirectory + GlueRegularBuildDestinationFolder + @"Plugins\", "Copied plugins to Glue", @"\Plugins\");

// save the run FlatRedBall batch file:
System.IO.File.WriteAllText(path:frbdkForZipDirectory + "Run FlatRedBall.bat", contents: @"START """" ""%~dp0Xna 4 Tools\GlueFormsCore.exe""");

}

async Task DownloadGum()
{
string url = "http://files.flatredball.com/content/Tools/Gum/Gum.zip"; // Replace with your actual URL
string targetDirectory = Path.Combine(_destDirectory, "Gum");
string zipFilePath = Path.Combine(targetDirectory, "Gum.zip");
string unzipDirectory = targetDirectory;

Results.WriteMessage($"Downloading Gum from {url}");

if(!System.IO.Directory.Exists(targetDirectory))
{
Directory.CreateDirectory(targetDirectory);
}

using (var client = new HttpClient())
{
// Download the file
using (var response = await client.GetAsync(url))
{
using (Stream stream = await response.Content.ReadAsStreamAsync())
{
using (FileStream fileStream = new FileStream(zipFilePath, FileMode.Create, FileAccess.Write, FileShare.None))
{
await stream.CopyToAsync(fileStream);
}
}
}

Results.WriteMessage($"Unzipping Gum from {zipFilePath}");

// Unzip the file
System.IO.Compression.ZipFile.ExtractToDirectory(zipFilePath, unzipDirectory);

// delete the zip - we don't need it anymore and it bloats the ultimate file:
System.IO.File.Delete(zipFilePath);

Results.WriteMessage($"Gum unzipped to {unzipDirectory}");
}
}

private void CopyDirectory(string sourceDirectory, string successfulMessage, string subdirectoryName = null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,23 @@ public static string CheckoutDirectory

public static string FrbdkDirectory => FlatRedBallDirectory + "FRBDK/";

static string GithubFilePath =>
System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "GitHub");

public static string GumRootDirectory
{
get
{
return FileManager.MakeAbsolute("../../../../../../../Gum/");
string defaultGumFilePath = System.IO.Path.Combine(GithubFilePath, "Gum\\");
if(System.IO.Directory.Exists(defaultGumFilePath))
{
// This makes the BuildServerUploader portable
return defaultGumFilePath;
}
else
{
return FileManager.MakeAbsolute("../../../../../../../Gum/");
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace BuildServerUploaderConsole.Processes
using System.Threading.Tasks;

namespace BuildServerUploaderConsole.Processes
{
public class ProcessStep
{
Expand Down Expand Up @@ -32,6 +34,7 @@ public ProcessStep(string message, IResults results)
}

public virtual void ExecuteStep() { }
public virtual Task ExecuteStepAsync() { return Task.CompletedTask; }
#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public enum UploadType
{
Entire,
EngineAndTemplatesOnly,
FrbdkOnly
FrbdkOnly,
GumOnly,
}

#endregion
Expand Down Expand Up @@ -144,27 +145,45 @@ public override void ExecuteStep()

UploadFrbdkFiles();
}
else if(uploadType == UploadType.GumOnly)
{
UploadGumFiles();
}
}

private void UploadGumFiles()
{
string localFile = FileManager.GetDirectory(DirectoryHelper.GumBuildDirectory) + "Gum.zip";

if(!System.IO.File.Exists(localFile))
{
throw new Exception($"{localFile} file doesn't exist for upload");
}
string targetFile = gumFolder + FileManager.RemovePath(localFile);
Results.WriteMessage("Uploading " + localFile + " to " + targetFile);
SftpManager.UploadFile(
localFile, host, targetFile, Username, Password);
localFile, host, targetFile, Username, Password, PrintOutput);

Results.WriteMessage(localFile + " uploaded to " + targetFile);
}

DateTime lastWrite = DateTime.Now;
void PrintOutput(ulong amount)
{
if(DateTime.Now - lastWrite > TimeSpan.FromSeconds(1))
{
Results.WriteMessage("Uploaded " + (amount / 1024).ToString("N0") + " kbytes");
lastWrite = DateTime.Now;
}
}

private void UploadFrbdkFiles()
{
string localFile = ZipFrbdk.DestinationFile;

string targetFile = _ftpFolder + FileManager.RemovePath(localFile);

SftpManager.UploadFile(
localFile, host, targetFile, Username, Password);
localFile, host, targetFile, Username, Password, PrintOutput);

Results.WriteMessage(localFile + " uploaded to " + targetFile);

Expand Down Expand Up @@ -196,7 +215,7 @@ private void UploadEngineFiles()
string destination = _ftpFolder + "SingleDlls/" + fileName;

SftpManager.UploadFileWithOpenConnection(
localFile, destination, client);
localFile, destination, client, PrintOutput);


Results.WriteMessage(engineFiles[i].DestinationFile + " uploaded to " + destination);
Expand All @@ -205,7 +224,7 @@ private void UploadEngineFiles()
}
}

private static void UploadTemplateFiles(string _ftpFolder, IResults Results)
private void UploadTemplateFiles(string _ftpFolder, IResults Results)
{
string templateDirectory = DirectoryHelper.ReleaseDirectory + @"ZippedTemplates/";

Expand All @@ -226,7 +245,7 @@ private static void UploadTemplateFiles(string _ftpFolder, IResults Results)
string localFile = templateDirectory + fileName;
string destination = _ftpFolder + "ZippedTemplates/" + fileName;
SftpManager.UploadFileWithOpenConnection(
localFile, destination, client);
localFile, destination, client, PrintOutput);


Results.WriteMessage(file + " uploaded to " + destination);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static void CreateZip(IResults results, string destinationDirectory, stri
}

}
results.WriteMessage($" Finished adding {containedObjects} files to zip");
results.WriteMessage($" Finished adding {containedObjects.Count} files to zip");

zip.Save(fullZipFileName);

Expand Down
21 changes: 15 additions & 6 deletions FRBDK/BuildServerUploader/BuildServerUploaderConsole/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using BuildServerUploaderConsole.Processes;
using FlatRedBall.IO;

Expand All @@ -15,6 +16,7 @@ public static class CommandLineCommands
public const string ZipAndUploadFrbdk = "zipanduploadfrbdk";
public const string ChangeEngineVersion = "changeengineversion";
public const string ChangeFrbdkVersion = "changefrbdkversion";
public const string ZipAndUploadGum = "zipanduploadgum";
}


Expand All @@ -24,7 +26,7 @@ public class Program
private static readonly List<ProcessStep> ProcessSteps = new List<ProcessStep>();
private static readonly IResults Results = new TraceResults();

static void Main(string[] args)
static async Task Main(string[] args)
{
FileManager.PreserveCase = true;

Expand Down Expand Up @@ -61,6 +63,10 @@ static void Main(string[] args)
case CommandLineCommands.ChangeFrbdkVersion:
CreateChangeFrbdkVersion();
break;
case CommandLineCommands.ZipAndUploadGum:
ProcessSteps.Add(new ZipGum(Results));
ProcessSteps.Add(new UploadFilesToFrbServer(Results, UploadType.GumOnly, null, null));
break;
case "":
break;
default:
Expand All @@ -83,7 +89,7 @@ static void Main(string[] args)
//CreateCopyToInstallerSteps(true);
}

ExecuteSteps();
await ExecuteSteps();

}

Expand Down Expand Up @@ -121,10 +127,12 @@ private static void CreateZipAndUploadFrbdk(string[] args)

if (args.Length < 3)
{
throw new Exception("Expected 3 arguments: {operation} {username} {password}, but only got " + args.Length + "arguments");
ProcessSteps.Add(new UploadFilesToFrbServer(Results, UploadType.FrbdkOnly, null, null));
}
else
{
ProcessSteps.Add(new UploadFilesToFrbServer(Results, UploadType.FrbdkOnly, args[1], args[2]));
}

ProcessSteps.Add(new UploadFilesToFrbServer(Results, UploadType.FrbdkOnly, args[1], args[2]));
}

private static void CreateCopyToTemplatesSteps()
Expand Down Expand Up @@ -160,13 +168,14 @@ private static void CreateUploadProcessSteps()
ProcessSteps.Add(new UploadFilesToFrbServer(Results, UploadType.Entire, null, null));
}

private static void ExecuteSteps()
private static async Task ExecuteSteps()
{
for (int i = 0; i < ProcessSteps.Count; i++)
{
int step1Based = i + 1;
Results.WriteMessage($"Processing {step1Based}/{ProcessSteps.Count} : {ProcessSteps[i].Message}");
ProcessSteps[i].ExecuteStep();
await ProcessSteps[i].ExecuteStepAsync();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,27 +37,27 @@ public static SftpClient GetClient(string host, string userName, string password
return new SftpClient(host, userName, password);

}
public static void UploadFile(string localFileToUpload, string host, string targetFile, string userName, string password)
public static void UploadFile(string localFileToUpload, string host, string targetFile, string userName, string password, Action<ulong> uploadCallback)
{
using (var sftp = new SftpClient(host, userName, password))
{
sftp.OperationTimeout = new TimeSpan(0, 0, seconds: 40);
sftp.Connect();
UploadFileWithOpenConnection(localFileToUpload, targetFile, sftp);
UploadFileWithOpenConnection(localFileToUpload, targetFile, sftp, uploadCallback);

sftp.Disconnect();
}
}

public static void UploadFileWithOpenConnection(string localFileToUpload, string targetFile, SftpClient sftp)
public static void UploadFileWithOpenConnection(string localFileToUpload, string targetFile, SftpClient sftp, Action<ulong> uploadCallback)
{
var directory = FlatRedBall.IO.FileManager.GetDirectory(targetFile, FlatRedBall.IO.RelativeType.Relative);

CreateDirectoriesRecursively(directory, sftp);

using (var file = File.OpenRead(localFileToUpload))
{
sftp.UploadFile(file, targetFile, canOverride: true);
sftp.UploadFile(file, targetFile, canOverride: true, uploadCallback);
}
}

Expand Down
Loading

0 comments on commit 6c076e6

Please sign in to comment.