private static void WriteProductEntry(ProductEntry productEntry, FileStream stream) { PboUtilities.WriteString(stream, "sreV"); stream.Write(new byte[15], 0, 15); if (!string.IsNullOrEmpty(productEntry.Name)) { PboUtilities.WriteString(stream, productEntry.Name); } else { return; } if (!string.IsNullOrEmpty(productEntry.Prefix)) { PboUtilities.WriteString(stream, productEntry.Prefix); } else { return; } if (!string.IsNullOrEmpty(productEntry.ProductVersion)) { PboUtilities.WriteString(stream, productEntry.ProductVersion); } else { return; } foreach (var str in productEntry.Addtional) { PboUtilities.WriteString(stream, str); } }
public static void Clone(string path, ProductEntry productEntry, Dictionary <FileEntry, string> files, byte[] checksum = null) { try { if (!Directory.Exists(Path.GetDirectoryName(path)) && !string.IsNullOrEmpty(Path.GetDirectoryName(path))) { Directory.CreateDirectory(Path.GetDirectoryName(path)); } using (var stream = File.Create(path)) { stream.WriteByte(0x0); WriteProductEntry(productEntry, stream); stream.WriteByte(0x0); files.Add(new FileEntry(null, "", 0, 0, 0, 0, _file), ""); foreach (var entry in files.Keys) { WriteFileEntry(stream, entry); } files.Remove(files.Last().Key); foreach (var file in files.Values) { var buffer = new byte[2949120]; using (var open = File.OpenRead(file)) { int bytesRead; while ((bytesRead = open.Read(buffer, 0, 2949120)) > 0) { stream.Write(buffer, 0, bytesRead); } } } if (checksum != null && checksum.Any(b => b != 0)) { stream.WriteByte(0x0); stream.Write(checksum, 0, checksum.Length); } else if (checksum == null) { stream.Position = 0; byte[] hash; using (var sha1 = new SHA1Managed()) { hash = sha1.ComputeHash(stream); } stream.WriteByte(0x0); stream.Write(hash, 0, 20); } } } catch (Exception) { throw; } }
private bool ReadHeader(FileStream stream) { // TODO FIX SO BROKEN string str = PboUtilities.ReadString(stream); if (str != "sreV") { return(false); } int count = 0; while (count < 15) { stream.ReadByte(); count++; } List <string> list = new List <string>(); string pboname = ""; string version = ""; string prefix = PboUtilities.ReadString(stream); if (!string.IsNullOrEmpty(prefix)) { pboname = PboUtilities.ReadString(stream); if (!string.IsNullOrEmpty(pboname)) { version = PboUtilities.ReadString(stream); if (!string.IsNullOrEmpty(version)) { while (stream.ReadByte() != 0x0) { stream.Position--; string s = PboUtilities.ReadString(stream); list.Add(s); } } } } ProductEntry = new ProductEntry(prefix, pboname, version, list); return(true); }
public static bool Create(string directoryPath, string outpath) { DirectoryInfo dir = new DirectoryInfo(directoryPath); if (!dir.Exists) { throw new DirectoryNotFoundException(); } directoryPath = dir.FullName; ProductEntry entry = new ProductEntry("prefix", "", "", new List <string>()); string[] files = Directory.GetFiles(directoryPath, "$*$"); foreach (string file in files) { string varname = Path.GetFileNameWithoutExtension(file).Trim('$'); string data = File.ReadAllText(file).Split('\n')[0]; switch (varname.ToLowerInvariant()) { case "pboprefix": entry.Prefix = data; break; case "prefix": entry.Prefix = data; break; case "version": entry.ProductVersion = data; break; default: entry.Addtional.Add(data); break; } } return(Create(directoryPath, outpath, entry)); }
public static bool Create(string directoryPath, string outpath, ProductEntry productEntry) { var dir = new DirectoryInfo(directoryPath); if (!dir.Exists) { throw new DirectoryNotFoundException(); } directoryPath = dir.FullName; var files = Directory.GetFiles(directoryPath, "*", SearchOption.AllDirectories); var entries = new List <FileEntry>(); foreach (string file in files) { if (Path.GetFileName(file).StartsWith("$") && Path.GetFileName(file).EndsWith("$")) { continue; } FileInfo info = new FileInfo(file); string path = PboUtilities.GetRelativePath(info.FullName, directoryPath); entries.Add(new FileEntry(path, 0x0, (ulong)info.Length, (ulong)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds, (ulong)info.Length)); } try { using (var stream = File.Create(outpath)) { stream.WriteByte(0x0); WriteProductEntry(productEntry, stream); stream.WriteByte(0x0); entries.Add(new FileEntry(null, "", 0, 0, 0, 0, _file)); foreach (var entry in entries) { WriteFileEntry(stream, entry); } entries.Remove(entries.Last()); foreach (var entry in entries) { var buffer = new byte[2949120]; using (var open = File.OpenRead(Path.Combine(directoryPath, entry.FileName))) { var read = 4324324; while (read > 0) { read = open.Read(buffer, 0, buffer.Length); stream.Write(buffer, 0, read); } } } stream.Position = 0; byte[] hash; using (var sha1 = new SHA1Managed()) { hash = sha1.ComputeHash(stream); } stream.WriteByte(0x0); stream.Write(hash, 0, 20); } } catch (Exception e) { Console.WriteLine(e.Message); return(false); } return(true); }
public static void Clone(string path, ProductEntry productEntry, Dictionary<FileEntry, string> files, byte[] checksum = null) { try { if (!Directory.Exists(Path.GetDirectoryName(path)) && !String.IsNullOrEmpty(Path.GetDirectoryName(path))) Directory.CreateDirectory(Path.GetDirectoryName(path) ); using (var stream = File.Create(path)) { stream.WriteByte(0x0); WriteProductEntry(productEntry, stream); stream.WriteByte(0x0); files.Add(new FileEntry(null, "", 0, 0, 0, 0, _file), ""); foreach (var entry in files.Keys) { WriteFileEntry(stream, entry); } files.Remove(files.Last().Key); foreach (var file in files.Values) { var buffer = new byte[2949120]; using (var open = File.OpenRead(file)) { int bytesRead; while ((bytesRead = open.Read(buffer, 0, 2949120)) > 0) { stream.Write(buffer, 0, bytesRead); } } } if(checksum != null && checksum.Any(b => b!=0)) { stream.WriteByte(0x0); stream.Write(checksum, 0, checksum.Length); } else if (checksum == null) { stream.Position = 0; byte[] hash; using (var sha1 = new SHA1Managed()) { hash = sha1.ComputeHash(stream); } stream.WriteByte(0x0); stream.Write(hash, 0, 20); } } } catch (Exception) { throw; } }
private Boolean ReadHeader(FileStream stream) { // TODO FIX SO BROKEN var str = PboUtilities.ReadString(stream); if (str != "sreV") return false; int count = 0; while (count < 15) { stream.ReadByte(); count++; } var prefix = ""; var list = new List<string>(); var pboname = ""; var version = ""; prefix = PboUtilities.ReadString(stream); if (!String.IsNullOrEmpty(prefix)) { pboname = PboUtilities.ReadString(stream); if (!String.IsNullOrEmpty(pboname)) { version = PboUtilities.ReadString(stream); if (!String.IsNullOrEmpty(version)) { while (stream.ReadByte() != 0x0) { stream.Position--; var s = PboUtilities.ReadString(stream); list.Add(s); } } } } _productEntry = new ProductEntry(prefix, pboname, version, list); return true; }
private static void WriteProductEntry(ProductEntry productEntry, FileStream stream) { PboUtilities.WriteString(stream, "sreV"); stream.Write(new byte[15], 0, 15); if (!String.IsNullOrEmpty(productEntry.Name)) PboUtilities.WriteString(stream, productEntry.Name); else return; if (!String.IsNullOrEmpty(productEntry.Prefix)) PboUtilities.WriteString(stream, productEntry.Prefix); else return; if (!String.IsNullOrEmpty(productEntry.ProductVersion)) PboUtilities.WriteString(stream, productEntry.ProductVersion); else return; foreach (var str in productEntry.Addtional) { PboUtilities.WriteString(stream, str); } }
public static Boolean Create(string directoryPath, string outpath, ProductEntry productEntry) { var dir = new DirectoryInfo(directoryPath); if (!dir.Exists) throw new DirectoryNotFoundException(); directoryPath = dir.FullName; var files = Directory.GetFiles(directoryPath, "*", SearchOption.AllDirectories); var entries = new List<FileEntry>(); foreach (string file in files) { if(Path.GetFileName(file).StartsWith("$") && Path.GetFileName(file).EndsWith("$")) continue; FileInfo info = new FileInfo(file); string path = PboUtilities.GetRelativePath(info.FullName, directoryPath); entries.Add(new FileEntry(path, 0x0, (ulong) info.Length, (ulong) (DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds, (ulong) info.Length)); } try { using (var stream = File.Create(outpath)) { stream.WriteByte(0x0); WriteProductEntry(productEntry, stream); stream.WriteByte(0x0); entries.Add(new FileEntry(null, "", 0, 0, 0, 0, _file)); foreach (var entry in entries) { WriteFileEntry(stream, entry); } entries.Remove(entries.Last()); foreach (var entry in entries) { var buffer = new byte[2949120]; using (var open = File.OpenRead(Path.Combine(directoryPath, entry.FileName))) { var read = 4324324; while (read > 0) { read = open.Read(buffer, 0, buffer.Length); stream.Write(buffer, 0, read); } } } stream.Position = 0; byte[] hash; using (var sha1 = new SHA1Managed()) { hash = sha1.ComputeHash(stream); } stream.WriteByte(0x0); stream.Write(hash, 0, 20); } } catch (Exception e) { Console.WriteLine(e.Message); return false; } return true; }
public static Boolean Create(string directoryPath, string outpath) { var dir = new DirectoryInfo(directoryPath); if (!dir.Exists) throw new DirectoryNotFoundException(); directoryPath = dir.FullName; var entry = new ProductEntry("prefix","","",new List<string>()); var files = Directory.GetFiles(directoryPath, "$*$"); foreach (var file in files) { var varname = Path.GetFileNameWithoutExtension(file).Trim('$'); var data = File.ReadAllText(file).Split('\n')[0]; switch (varname.ToLowerInvariant()) { case "pboprefix": entry.Prefix = data; break; case "prefix": entry.Prefix = data; break; case "version": entry.ProductVersion = data; break; default: entry.Addtional.Add(data); break; } } return Create(directoryPath, outpath, entry); }
public static void Clone(string path, ProductEntry productEntry, Dictionary<FileEntry, string> files, Byte[] checksum) { try { using (var stream = File.Create(path)) { stream.WriteByte(0x0); WriteProductEntry(productEntry, stream); stream.WriteByte(0x0); files.Add(new FileEntry(null, "", 0, 0, 0, 0, 0), ""); foreach (var entry in files.Keys) { WriteFileEntry(stream, entry); } files.Remove(files.Last().Key); foreach (var file in files.Values) { var buffer = new byte[1024]; using (var open = File.OpenRead(file)) { int bytesRead; while ((bytesRead = open.Read(buffer, 0, 1024)) > 0) { stream.Write(buffer, 0, bytesRead); } } } stream.WriteByte(0x0); stream.Write(checksum, 0, checksum.Length); } } catch (Exception) { throw; } }
public static Boolean Create(string directoryPath, string outpath, ProductEntry productEntry) { var files = Directory.GetFiles(directoryPath, "*", SearchOption.AllDirectories); var entries = (from file in files select new FileInfo(file) into info let path = PboUtilities.GetRelativePath(info.FullName, directoryPath) select new FileEntry(path, 0x0, 0x0, (ulong) (DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds, (ulong) info.Length)).ToList(); try { using (var stream = File.Create(outpath)) { stream.WriteByte(0x0); WriteProductEntry(productEntry, stream); stream.WriteByte(0x0); entries.Add(new FileEntry(null, "", 0, 0, 0, 0)); foreach (var entry in entries) { WriteFileEntry(stream, entry); } entries.Remove(entries.Last()); foreach (var entry in entries) { var buffer = new byte[1024]; using (var open = File.OpenRead(Path.Combine(directoryPath, entry.FileName))) { var read = 4324324; while (read > 0) { read = open.Read(buffer, 0, buffer.Length); stream.Write(buffer, 0, read); } } } stream.Position = 0; byte[] hash; using (var sha1 = new SHA1Managed()) { hash = sha1.ComputeHash(stream); } stream.WriteByte(0x0); stream.Write(hash, 0, 20); } } catch (Exception e) { Console.WriteLine(e.Message); return false; } return true; }
private Boolean ReadHeader(FileStream stream) { var str = PboUtilities.ReadString(stream); if (str != "sreV") return false; var ch = 0x0; while (ch == 0x0) { ch = stream.ReadByte(); } var prefix = ((char)ch) + PboUtilities.ReadString(stream); var pboname = PboUtilities.ReadString(stream); var version = PboUtilities.ReadString(stream); var list = new List<string>(); while (stream.ReadByte() != 0x0) { stream.Position--; var s = PboUtilities.ReadString(stream); list.Add(s); } _productEntry = new ProductEntry(prefix,pboname,version,list); return true; }
private static void WriteProductEntry(ProductEntry productEntry, FileStream stream) { PboUtilities.WriteString(stream, "sreV"); stream.Write(new byte[15], 0, 15); PboUtilities.WriteString(stream, productEntry.Prefix); PboUtilities.WriteString(stream, productEntry.ProductName); PboUtilities.WriteString(stream, productEntry.ProductVersion); foreach (var str in productEntry.Addtional) { PboUtilities.WriteString(stream, str); } }