public void PlayWav(WorkspacePath workspacePath) { if (workspace.Exists(workspacePath) && workspacePath.GetExtension() == ".wav") { if (currentSound != null) { StopWav(); } using (var stream = workspace.OpenFile(workspacePath, FileAccess.Read)) { currentSound = SoundEffect.FromStream(stream).CreateInstance(); } currentSound.Play(); } }
public Dictionary <string, object> CreateExe(string name, WorkspacePath[] files, WorkspacePath template, WorkspacePath exportPath, string[] libFileNames = null) { var response = new Dictionary <string, object> { { "success", false }, { "message", "" } }; // var buildFilePath = template.ParentPath.AppendFile("build.json"); // // if (workspace.Exists(buildFilePath)) // { // var buildText = ""; // // using (var file = workspace.OpenFile(buildFilePath, FileAccess.Read)) // { // buildText = file.ReadAllText(); // file.Close(); // file.Dispose(); // } var platform = template.EntityName.Split(' ')[1].Split('.')[0]; var contentPath = platform == "Mac" ? name + ".app/Contents/Resources/Content/DefaultGame/" : "Content/DefaultGame/"; // Make sure the source is a pv8 file if (workspace.Exists(template) && template.GetExtension() == ".pvr") { workspace.CreateDirectoryRecursive(exportPath); exportPath = exportPath.AppendFile(name + ".zip"); // Remove platform from name name = name.Split(' ')[0]; using (Stream fsIn = workspace.OpenFile(template, FileAccess.Read)) using (var zfIn = new ZipFile(fsIn)) { using (Stream fsOut = workspace.CreateFile(exportPath)) { using (var zfOut = new ZipOutputStream(fsOut)) { // Copy over all of the contents of the template to a new Zip file foreach (ZipEntry zipEntry in zfIn) { if (!zipEntry.IsFile) { // Ignore directories continue; } var entryFileName = zipEntry.Name; if (!entryFileName.Contains(contentPath)) { Stream fsInput = null; long size = 0; // Check to see if there is a bios file if (entryFileName.EndsWith("bios.json")) { // Create a reader from a new copy of the zipEntry StreamReader reader = new StreamReader(zfIn.GetInputStream(zipEntry)); // Read out all of the text var text = reader.ReadToEnd(); // // Replace the base directory with the game name and no spaces text = text.Replace(@"GameRunner", name.Replace(" " + platform, " ").Replace(" ", "")); text = text.Replace(@"PV8 Game Runner", name.Replace(" " + platform, "")); // Create a new memory stream in place of the zip file entry fsInput = new MemoryStream(); // Wrap the stream in a writer var writer = new StreamWriter(fsInput); // Write the text to the stream writer.Write(text); // Flush the stream and set it back to the begining writer.Flush(); fsInput.Seek(0, SeekOrigin.Begin); // Get the size so we know how big it is later on size = fsInput.Length; } // Clean up path for mac builds if (platform == "Mac") { if (entryFileName.StartsWith("Runner.app")) { // We rename the default Runner.app path to the game name to rename everything in the exe entryFileName = entryFileName.Replace("Runner.app", name + ".app"); } } else { // fsInput = new MemoryStream(); // We need to look for the launch script if (entryFileName == "Pixel Vision 8 Runner") { // Create a reader from a new copy of the zipEntry StreamReader reader = new StreamReader(zfIn.GetInputStream(zipEntry)); // Read out all of the text string text = reader.ReadToEnd(); // // Replace the default name with the game name text = text.Replace(@"Pixel\ Vision\ 8\ Runner", name.Replace(" ", @"\ ")); // Create a new memory stream in place of the zip file entry fsInput = new MemoryStream(); // Wrap the stream in a writer var writer = new StreamWriter(fsInput); // Write the text to the stream writer.Write(text); // Flush the stream and set it back to the begining writer.Flush(); fsInput.Seek(0, SeekOrigin.Begin); // Get the size so we know how big it is later on size = fsInput.Length; } // Rename all the executibale files in the linux build entryFileName = entryFileName.Replace("Pixel Vision 8 Runner", name); } // Check to see if we have a stream if (fsInput == null) { // Get a stream from the current zip entry fsInput = zfIn.GetInputStream(zipEntry); size = zipEntry.Size; } using (fsInput) { ZipEntry newEntry = new ZipEntry(entryFileName) { DateTime = DateTime.Now, Size = size }; zfOut.PutNextEntry(newEntry); var buffer = new byte[4096]; StreamUtils.Copy(fsInput, zfOut, buffer); fsInput.Close(); zfOut.CloseEntry(); } } } // Copy over all of the game files var list = from p in files where workspace.fileExtensions.Any(val => p.EntityName.EndsWith(val)) select p; // Readjust the content path contentPath = platform == "Mac" ? name + ".app/Contents/Resources/Content/DefaultGame/" : "Content/DefaultGame/"; foreach (var file in list) { var entryFileName = contentPath + file.EntityName; using (var fileStream = workspace.OpenFile(file, FileAccess.Read)) { var newEntry = new ZipEntry(entryFileName) { DateTime = DateTime.Now, Size = fileStream.Length }; zfOut.PutNextEntry(newEntry); var buffer = new byte[4096]; StreamUtils.Copy(fileStream, zfOut, buffer); zfOut.CloseEntry(); fileStream.Close(); } } // Copy over all of the library files if (libFileNames != null) { var libFileData = new Dictionary <string, byte[]>(); workspace.IncludeLibDirectoryFiles(libFileData); var total = libFileNames.Length; for (int i = 0; i < total; i++) { var fileName = libFileNames[i] + ".lua"; if (libFileData.ContainsKey(fileName)) { var entryFileName = contentPath + fileName; using (var fileStream = new MemoryStream(libFileData[fileName])) { var newEntry = new ZipEntry(entryFileName) { DateTime = DateTime.Now, Size = fileStream.Length }; zfOut.PutNextEntry(newEntry); var buffer = new byte[4096]; StreamUtils.Copy(fileStream, zfOut, buffer); zfOut.CloseEntry(); fileStream.Close(); } } } } } } } // } } return(response); }