private static void Main(string[] args) { if (args.Contains("--root")) { int i = args.ToList().IndexOf("--root"); AppRootHelper.SetCustomBase(Path.GetFullPath(args[i + 1])); List <string> a = new List <string>(args); a.RemoveRange(i, 2); args = a.ToArray(); } else { AppRootHelper. SetAppDomainBase(); // Hack to be able to use the .netstandard libs in unity AND as console app. } VisConsole.RunConsole(args); }
public override void Pack(string input) { if (Directory.Exists(input)) { string cacheDir = Path.Combine(VisConsole.GetCacheDirectory(SubSystem), "zip-temp"); Directory.CreateDirectory(cacheDir); string newFile = Path.Combine(cacheDir, Path.GetRandomFileName() + ".zip"); ZipFile.CreateFromDirectory(input, newFile); input = newFile; } else { Log("Invalid Format: {0}", Path.GetExtension(input)); return; } ZipArchive archive = ZipFile.OpenRead(input); string fullPath = Path.GetFullPath(input); string output = Path.Combine( Path.GetDirectoryName(fullPath), Path.GetFileNameWithoutExtension(fullPath) + ".bin" ); FileStream fs = File.Create(output); if (m_Settings.DiskSize != 0) { fs.SetLength(m_Settings.DiskSize); } foreach (ZipArchiveEntry file in archive.Entries) { string fsPath = m_Settings.FileSystemPrefix + file.FullName; Log("File: '{0}' => '{1}'", file.FullName, fsPath); uint fileSize = m_Settings.UnpackData ? ( uint )file.Length : ( uint )file.Length / sizeof(uint); fs.Write(BitConverter.GetBytes(( uint )fsPath.Length), 0, sizeof(uint)); fs.Write(BitConverter.GetBytes(fileSize), 0, sizeof(uint)); fs.Write(BitConverter.GetBytes(0U), 0, sizeof(uint)); byte[] name = fsPath.Select(x => ( uint )x).SelectMany(BitConverter.GetBytes).ToArray(); fs.Write(name, 0, name.Length); Stream s = file.Open(); byte[] buffer = new byte[1024 * 1024]; int read = buffer.Length; do { read = s.Read(buffer, 0, buffer.Length); if (m_Settings.UnpackData && !m_Settings.UnpackIgnoreExtensions.Contains(Path.GetExtension(file.FullName))) { byte[] tempBuffer = buffer.Take(read). Select(x => ( uint )x). SelectMany(BitConverter.GetBytes). ToArray(); fs.Write(tempBuffer, 0, tempBuffer.Length); } else { fs.Write(buffer, 0, read); } }while (read == buffer.Length); s.Close(); } fs.Close(); archive.Dispose(); }