Exemple #1
0
        public static void Main(string[] args)
        {
            bool showHelp = false;
            bool verbose = false;

            OptionSet options = new OptionSet()
            {
                {
                    "v|verbose",
                    "be verbose (list files)",
                    v => verbose = v != null
                },
                {
                    "h|help",
                    "show this message and exit", 
                    v => showHelp = v != null
                },
            };

            List<string> extras;

            try
            {
                extras = options.Parse(args);
            }
            catch (OptionException e)
            {
                Console.Write("{0}: ", GetExecutableName());
                Console.WriteLine(e.Message);
                Console.WriteLine("Try `{0} --help' for more information.", GetExecutableName());
                return;
            }

            if (extras.Count < 1 || showHelp == true)
            {
                Console.WriteLine("Usage: {0} [OPTIONS]+ output_big input_directory+", GetExecutableName());
                Console.WriteLine("Pack files from input directories into a Big File.");
                Console.WriteLine();
                Console.WriteLine("Options:");
                options.WriteOptionDescriptions(Console.Out);
                return;
            }

            var inputPaths = new List<string>();
            string outputPath;

            if (extras.Count == 1)
            {
                inputPaths.Add(extras[0]);
                outputPath = Path.ChangeExtension(extras[0], ".viv");
            }
            else
            {
                outputPath = extras[0];
                inputPaths.AddRange(extras.Skip(1));
            }

            var paths = new SortedDictionary<uint, string>();

            if (verbose == true)
            {
                Console.WriteLine("Finding files...");
            }

            foreach (var relPath in inputPaths)
            {
                string inputPath = Path.GetFullPath(relPath);

                if (inputPath.EndsWith(Path.DirectorySeparatorChar.ToString()) == true)
                {
                    inputPath = inputPath.Substring(0, inputPath.Length - 1);
                }

                foreach (string path in Directory.GetFiles(inputPath, "*", SearchOption.AllDirectories))
                {
                    string fullPath = Path.GetFullPath(path);
                    string partPath = fullPath.Substring(inputPath.Length + 1).ToLowerInvariant();

                    uint hash = 0xFFFFFFFF;
                    if (partPath.ToUpper().StartsWith("__UNKNOWN") == true)
                    {
                        string partName;
                        
                        partName = Path.GetFileNameWithoutExtension(partPath);
                        if (partName.Length > 8)
                        {
                            partName = partName.Substring(0, 8);
                        }

                        hash = uint.Parse(
                            partName,
                            System.Globalization.NumberStyles.AllowHexSpecifier);
                    }
                    else
                    {
                        hash = partPath.ToLowerInvariant().HashFileName();
                    }

                    if (paths.ContainsKey(hash) == true)
                    {
                        Console.WriteLine("Ignoring {0} duplicate.", partPath);
                        continue;
                    }

                    paths[hash] = fullPath;
                }
            }

            using (var output = File.Open(outputPath, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite))
            {
                var big = new BigFile();

                if (verbose == true)
                {
                    Console.WriteLine("Adding files...");
                }

                // write a dummy header
                output.Seek(0, SeekOrigin.Begin);
                big.Entries.Clear();
                foreach (var kvp in paths)
                {
                    big.Entries.Add(new BigFile.Entry()
                        {
                            Name = 0,
                            Offset = 0,
                            Size = 0,
                        });
                }
                big.Serialize(output);

                output.Seek(output.Position.Align(2048), SeekOrigin.Begin);
                long baseOffset = output.Position;

                // write file data
                big.Entries.Clear();

                if (verbose == true)
                {
                    Console.WriteLine("Writing to disk...");
                }

                foreach (var kvp in paths)
                {
                    if (verbose == true)
                    {
                        Console.WriteLine(kvp.Value);
                    }

                    using (var input = File.Open(kvp.Value, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                    {
                        output.Seek(baseOffset, SeekOrigin.Begin);

                        uint size = (uint)input.Length.Align(2048);

                        big.Entries.Add(new BigFile.Entry()
                            {
                                Name = kvp.Key,
                                Offset = (uint)output.Position,
                                Size = size,
                            });

                        output.WriteFromStream(input, input.Length);
                        baseOffset += size;
                    }
                }

                // write filled header
                output.Seek(0, SeekOrigin.Begin);
                big.TotalFileSize = (uint)output.Length;
                big.Serialize(output);
            }
        }
Exemple #2
0
        private void OnOpen(object sender, EventArgs e)
        {
            if (this.openDialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            if (this.openDialog.InitialDirectory != null)
            {
                this.openDialog.InitialDirectory = null;
            }

            BigFile archive;
            using (var input = this.openDialog.OpenFile())
            {
                archive = new BigFile();
                archive.Deserialize(input);
            }
            this.Archive = archive;

            /*
            TextWriter writer = new StreamWriter("all_file_hashes.txt");
            foreach (var hash in table.Keys.OrderBy(k => k))
            {
                writer.WriteLine(hash.ToString("X8"));
            }
            writer.Close();
            */

            this.BuildFileTree();
        }
		public void ShowSaveProgress(
            IWin32Window owner,
            Stream stream,
            BigFile archive,
            IEnumerable<BigFile.Entry> saving,
            Dictionary<uint, string> fileNames,
            string basePath,
            SaveAllSettings settings)
		{
			SaveAllInformation info;
			info.BasePath = basePath;
			info.Stream = stream;
			info.Archive = archive;
            info.Saving = saving;
			info.FileNames = fileNames;
            info.Settings = settings;

			this.progressBar.Value = 0;
			this.progressBar.Maximum = 100;

			this.SaveThread = new Thread(new ParameterizedThreadStart(SaveAll));
			this.SaveThread.Start(info);
			this.ShowDialog(owner);
		}