Example #1
0
        static IEnumerable <Uri> EnumerateAllFiles(Uri directoryUri, PackagingSetting setting)
        {
            switch (setting)
            {
            case PackagingSetting.AllFiles:
                foreach (string filePath in Directory.EnumerateFiles(directoryUri.LocalPath, "*", SearchOption.AllDirectories))
                {
                    yield return(new Uri(filePath));
                }
                break;

            case PackagingSetting.IgnoreHiddenAttribute:
                foreach (var uri in EnumerateFilesWithoutHiddenAttribute(directoryUri))
                {
                    yield return(uri);
                }
                break;

            default:
                throw new ArgumentException("setting が無効の値を指しています");
            }
        }
Example #2
0
        protected override void OnUpdated()
        {
            if (asd.Engine.Tool.BeginFullscreen("FilePackageGenerator", 0))
            {
                asd.Engine.Tool.Text("Source:");
                if (asd.Engine.Tool.Button("Open..."))
                {
                    Open();
                }

                asd.Engine.Tool.Text("Setting:");
                if (asd.Engine.Tool.Button(Setting == PackagingSetting.IgnoreHiddenAttribute ? "Ignore Hidden" : "All Files"))
                {
                    Setting = (Setting == PackagingSetting.AllFiles) ?
                              PackagingSetting.IgnoreHiddenAttribute :
                              PackagingSetting.AllFiles;
                    RefleshList();
                }
                asd.Engine.Tool.Text("Password:"******"Package:");
                if (asd.Engine.Tool.Button("Save as...") && SrcPath != string.Empty)
                {
                    Save();
                }

                asd.Engine.Tool.Text("");
                asd.Engine.Tool.Text("Selected Folder:");
                asd.Engine.Tool.Text(SrcPath);
                asd.Engine.Tool.Text("File List:");

                asd.Engine.Tool.ListBox(string.Empty, new[] { 0 }, FileList);
            }
            asd.Engine.Tool.End();
        }
Example #3
0
        public static void Run(string targetPath, string packName, PackagingSetting setting, IEnumerable <string> ignorePath, string key = "")
        {
            var version = PackageVersion;

            Uri directoryUri = new Uri(Path.GetFullPath(targetPath).RemoveLastDirectorySeparator());

            if (Path.GetExtension(packName) != PackFile.Extension)
            {
                packName += PackFile.Extension;
            }


            ErrorCheck(directoryUri);

            var internalFormat = new List <InternalHeader>();

            uint offset     = 0;
            uint headerSize = 0;

            foreach (Uri uri in EnumerateAllFiles(directoryUri, setting))
            {
                uint size = 0;
                using (var stream = File.Open(uri.LocalPath, FileMode.Open))
                {
                    size = (uint)stream.Length;
                }

                InternalHeader tmp = new InternalHeader(size,
                                                        offset,
                                                        // *.pack/hoge/fuga の *.pack/ を削除
                                                        new string(directoryUri.MakeRelativeUri(uri).ToString()
                                                                   .SkipWhile(ch => ch != Path.AltDirectorySeparatorChar && ch != Path.DirectorySeparatorChar)
                                                                   .Skip(1)
                                                                   .ToArray()));
                internalFormat.Add(tmp);
                headerSize += tmp.HeaderSize;
                offset     += size;
            }
            TopHeader format = new TopHeader((uint)internalFormat.Count, ignorePath
                                             .Where(path => !String.IsNullOrEmpty(path))
                                             .Select(path => directoryUri.MakeRelativeUri(new Uri(Path.GetFullPath(path))).ToString()), version);

            internalFormat.ForEach(inHeader => inHeader.Offset += headerSize + format.HeaderSize);

            PrintHeaderInfo(format, internalFormat, packName);

            string exportedPath = string.Empty;

            if (System.IO.Path.IsPathRooted(packName))
            {
                exportedPath = packName;
            }
            else
            {
                exportedPath = Path.GetDirectoryName(directoryUri.LocalPath)
                               // 実行ファイルと同じ階層に生成したい場合は GetFileName に変更
                               + Path.DirectorySeparatorChar
                               + packName;
            }

            using (var writer = new BinaryWriter(File.Create(exportedPath)))
            {
                writer.Write(format.ToByteArray());
                internalFormat.ForEach(inHeader => writer.Write(inHeader.ToByteArray()));

                foreach (string fullPath in EnumerateAllFiles(directoryUri, setting)
                         .Select(path => new Uri(directoryUri, path).LocalPath))
                {
                    writer.Write(File.ReadAllBytes(fullPath));
                }
            }

            if (!string.IsNullOrEmpty(key))
            {
                Encrypt(exportedPath, key, version);
            }
        }
Example #4
0
        public static void Run(string targetPath, string packName, PackagingSetting setting, IEnumerable<string> ignorePath, string key = "")
        {
            var version = PackageVersion;

            Uri directoryUri = new Uri(Path.GetFullPath(targetPath).RemoveLastDirectorySeparator());

            if (Path.GetExtension(packName) != PackFile.Extension)
            {
                packName += PackFile.Extension;
            }

            ErrorCheck(directoryUri);

            var internalFormat = new List<InternalHeader>();

            uint offset = 0;
            uint headerSize = 0;

            foreach (Uri uri in EnumerateAllFiles(directoryUri, setting))
            {
                uint size = 0;
                using (var stream = File.Open(uri.LocalPath, FileMode.Open))
                {
                    size = (uint)stream.Length;
                }

                InternalHeader tmp = new InternalHeader(size,
                                                        offset,
                                                        // *.pack/hoge/fuga の *.pack/ を削除
                                                        new string(directoryUri.MakeRelativeUri(uri).ToString()
                                                                    .SkipWhile(ch => ch != Path.AltDirectorySeparatorChar && ch != Path.DirectorySeparatorChar)
                                                                    .Skip(1)
                                                                    .ToArray()));
                internalFormat.Add(tmp);
                headerSize += tmp.HeaderSize;
                offset += size;
            }
            TopHeader format = new TopHeader((uint)internalFormat.Count, ignorePath
                .Where(path => !String.IsNullOrEmpty(path))
                .Select(path => directoryUri.MakeRelativeUri(new Uri(Path.GetFullPath(path))).ToString()), version);

            internalFormat.ForEach(inHeader => inHeader.Offset += headerSize + format.HeaderSize);

            PrintHeaderInfo(format, internalFormat, packName);

            string exportedPath = string.Empty;
            if (System.IO.Path.IsPathRooted(packName))
            {
                exportedPath = packName;
            }
            else
            {
                exportedPath = Path.GetDirectoryName(directoryUri.LocalPath)
                    // 実行ファイルと同じ階層に生成したい場合は GetFileName に変更
                    + Path.DirectorySeparatorChar
                    + packName;
            }

            using (var writer = new BinaryWriter(File.Create(exportedPath)))
            {
                writer.Write(format.ToByteArray());
                internalFormat.ForEach(inHeader => writer.Write(inHeader.ToByteArray()));

                foreach (string fullPath in EnumerateAllFiles(directoryUri, setting)
                    .Select(path => new Uri(directoryUri, path).LocalPath))
                {
                    writer.Write(File.ReadAllBytes(fullPath));
                }
            }

            if (!string.IsNullOrEmpty(key))
            {
                Encrypt(exportedPath, key, version);
            }
        }
Example #5
0
 static IEnumerable<Uri> EnumerateAllFiles(Uri directoryUri, PackagingSetting setting)
 {
     switch (setting)
     {
         case PackagingSetting.AllFiles:
             foreach (string filePath in Directory.EnumerateFiles(directoryUri.LocalPath, "*", SearchOption.AllDirectories))
             {
                 yield return new Uri(filePath);
             }
             break;
         case PackagingSetting.IgnoreHiddenAttribute:
             foreach (var uri in EnumerateFilesWithoutHiddenAttribute(directoryUri))
             {
                 yield return uri;
             }
             break;
         default:
             throw new ArgumentException("setting が無効の値を指しています");
     }
 }