コード例 #1
0
 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);
     }
 }
コード例 #2
0
 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;
     }
 }
コード例 #3
0
ファイル: PboArchive.cs プロジェクト: jokoho48/SwiftPbo
        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);
        }
コード例 #4
0
ファイル: PboArchive.cs プロジェクト: jokoho48/SwiftPbo
        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));
        }
コード例 #5
0
        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);
        }
コード例 #6
0
ファイル: PboArchive.cs プロジェクト: headswe/SwiftPbo
 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;
     }
 }
コード例 #7
0
ファイル: PboArchive.cs プロジェクト: headswe/SwiftPbo
        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;
        }
コード例 #8
0
ファイル: PboArchive.cs プロジェクト: headswe/SwiftPbo
 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);
     }
 }
コード例 #9
0
ファイル: PboArchive.cs プロジェクト: headswe/SwiftPbo
 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;
 }
コード例 #10
0
ファイル: PboArchive.cs プロジェクト: headswe/SwiftPbo
 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);
 }
コード例 #11
0
 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;
     }
 }
コード例 #12
0
 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;
 }
コード例 #13
0
ファイル: PboArchive.cs プロジェクト: nikolauska/SwiftPbo
 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;
 }
コード例 #14
0
ファイル: PboArchive.cs プロジェクト: nikolauska/SwiftPbo
 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);
     }
 }