public static byte[] Asm(string asmSource) { var requestId = Guid.NewGuid(); var tempPath = Path.Combine(Path.GetTempPath(), requestId.ToString()); var currentDirectory = Directory.GetCurrentDirectory(); try { Directory.CreateDirectory(tempPath); var templates = IntegrationTemplatesLoader.AsmTemplates; var fs = new FSManager(tempPath); fs.SaveSnapshot(templates); File.WriteAllText(Path.Combine(tempPath, "test.S"), asmSource); Directory.SetCurrentDirectory(tempPath); var cmdInvocation = new BashInvocation("make bin"); FSCall(cmdInvocation); return(File.ReadAllBytes("firmware.bin")); } finally { Directory.SetCurrentDirectory(currentDirectory); if (Directory.Exists(tempPath)) { Directory.Delete(tempPath, true); } } }
public static async Task <byte[]> Make(Stream zipStream, string target) { var resultId = Guid.NewGuid(); var zipFolder = Path.Combine(Path.GetTempPath(), $"{resultId}"); var zipFile = Path.Combine(Path.GetTempPath(), $"{resultId}.zip"); var currentDirectory = Directory.GetCurrentDirectory(); try { await zipFile.CreateFromStreamAsync(zipStream); // extract to temp folder zipFile.ExtractZip(zipFolder); zipFile.DeleteFileIfExists(); Directory.SetCurrentDirectory(zipFolder); var bashInvoke = new BashInvocation($"make {target}"); FSCall(bashInvoke); // zip and return result zipFolder.CompressFolder(zipFile); return(File.ReadAllBytes(zipFile)); } finally { Directory.SetCurrentDirectory(currentDirectory); zipFolder.DeleteDirectoryIfExists(); zipFile.DeleteFileIfExists(); } }