示例#1
0
        internal void PatchIroAdvanced()
        {
            string        pathToSource  = PathToSourceFolder;
            string        iropFile      = PathToIropFile;
            List <string> filesToDelete = FilesToDelete;

            _7thWrapperLib.CompressType compressType = (_7thWrapperLib.CompressType)CompressionSelectedIndex;

            IsPatching = true;

            Task patchTask = Task.Factory.StartNew(() =>
            {
                var files = Directory.GetFiles(pathToSource, "*", SearchOption.AllDirectories)
                            .Select(s => s.Substring(pathToSource.Length).Trim('\\', '/'))
                            .Select(s => _7thWrapperLib.IrosArc.ArchiveCreateEntry.FromDisk(pathToSource, s))
                            .ToList();

                if (filesToDelete.Any())
                {
                    byte[] deldata = Encoding.Unicode.GetBytes(String.Join("\n", filesToDelete));
                    files.Add(new _7thWrapperLib.IrosArc.ArchiveCreateEntry()
                    {
                        Filename = "%IrosPatch:Deleted",
                        GetData  = () => deldata
                    });
                }

                using (var fs = new FileStream(iropFile, FileMode.Create))
                    _7thWrapperLib.IrosArc.Create(fs, files, _7thWrapperLib.ArchiveFlags.Patch, compressType, IroProgress);
            });

            patchTask.ContinueWith((result) =>
            {
                IsPatching    = false;
                ProgressValue = 0;

                if (result.IsFaulted)
                {
                    Logger.Warn(result.Exception.GetBaseException());
                    StatusText = $"{ResourceHelper.Get(StringKey.AnErrorOccuredWhilePatching)}: {result.Exception.GetBaseException().Message}";
                    return;
                }

                StatusText = ResourceHelper.Get(StringKey.PatchingComplete);
            });
        }
示例#2
0
        internal void PatchIro()
        {
            string pathToOriginalIro = PathToOriginalIroFile;
            string pathToNewIro      = PathToNewIroFile;
            string iropFile          = PathToIropFile;

            _7thWrapperLib.CompressType compressType = (_7thWrapperLib.CompressType)CompressionSelectedIndex;

            IsPatching = true;

            Task patchTask = Task.Factory.StartNew(() =>
            {
                using (_7thWrapperLib.IrosArc orig = new _7thWrapperLib.IrosArc(pathToOriginalIro, true))
                {
                    using (_7thWrapperLib.IrosArc newiro = new _7thWrapperLib.IrosArc(pathToNewIro))
                    {
                        using (var fs = new FileStream(iropFile, FileMode.Create))
                            _7thWrapperLib.IrosPatcher.Create(orig, newiro, fs, compressType, IroProgress);
                    }
                }
            });

            patchTask.ContinueWith((result) =>
            {
                IsPatching    = false;
                ProgressValue = 0;

                if (result.IsFaulted)
                {
                    Logger.Warn(result.Exception.GetBaseException());
                    StatusText = $"{ResourceHelper.Get(StringKey.AnErrorOccuredWhilePatching)}: {result.Exception.GetBaseException().Message}";
                    return;
                }

                StatusText = ResourceHelper.Get(StringKey.PatchingComplete);
            });
        }
示例#3
0
        internal Task PackIro()
        {
            string pathToSource = PathToSourceFolder;
            string outputFile   = PathToOutputFile;

            _7thWrapperLib.CompressType compressType = (_7thWrapperLib.CompressType)CompressionSelectedIndex;

            IsPacking = true;

            Task packTask = Task.Factory.StartNew(() =>
            {
                var files = Directory.GetFiles(pathToSource, "*", SearchOption.AllDirectories)
                            .Select(s => s.Substring(pathToSource.Length).Trim('\\', '/'))
                            .ToList();

                using (var fs = new FileStream(outputFile, FileMode.Create))
                    _7thWrapperLib.IrosArc.Create(fs, files.Select(s => _7thWrapperLib.IrosArc.ArchiveCreateEntry.FromDisk(pathToSource, s)), _7thWrapperLib.ArchiveFlags.None, compressType, IroProgress);
            });

            packTask.ContinueWith((result) =>
            {
                IsPacking     = false;
                ProgressValue = 0;

                if (result.IsFaulted)
                {
                    Logger.Warn(result.Exception.GetBaseException());
                    StatusText = $"An error occured while packing: {result.Exception.GetBaseException().Message}";
                    return;
                }

                StatusText = "Packing complete!";
            });

            return(packTask);
        }
示例#4
0
文件: Program.cs 项目: rodriada000/7h
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                System.Console.WriteLine(HELP);
                return;
            }
            _7thWrapperLib.RuntimeLog.Enabled = args.Any(s => s.Equals("/LOG", StringComparison.InvariantCultureIgnoreCase));

            Action <double, string> onProgress = (d, s) => {
                Console.WriteLine(String.Format("{0}%: {1}", (int)(d * 100), s));
            };

            if (args[0].Equals("LIST", StringComparison.InvariantCultureIgnoreCase))
            {
                _7thWrapperLib.IrosArc iro = new _7thWrapperLib.IrosArc(args[1]);
                foreach (string s in iro.GetInformation())
                {
                    Console.WriteLine(s);
                }
            }
            else if (args[0].Equals("CREATE", StringComparison.InvariantCultureIgnoreCase))
            {
                List <_7thWrapperLib.IrosArc.ArchiveCreateEntry> entries = new List <_7thWrapperLib.IrosArc.ArchiveCreateEntry>();
                string dir = args[2];
                foreach (string file in System.IO.Directory.GetFiles(dir, "*", System.IO.SearchOption.AllDirectories))
                {
                    entries.Add(_7thWrapperLib.IrosArc.ArchiveCreateEntry.FromDisk(dir, file.Substring(dir.Length).Trim('/', '\\')));
                }
                _7thWrapperLib.CompressType compress = (_7thWrapperLib.CompressType)Enum.Parse(typeof(_7thWrapperLib.CompressType), args[3]);

                using (var fs = new System.IO.FileStream(args[1], System.IO.FileMode.Create))
                    _7thWrapperLib.IrosArc.Create(fs,
                                                  entries,
                                                  _7thWrapperLib.ArchiveFlags.None,
                                                  compress,
                                                  onProgress
                                                  );
            }
            else if (args[0].Equals("EXTRACT", StringComparison.InvariantCultureIgnoreCase))
            {
                _7thWrapperLib.IrosArc iro = new _7thWrapperLib.IrosArc(args[1]);
                var sw = new System.Diagnostics.Stopwatch();
                sw.Start();
                string filter = args.Length > 3 ? args[3] : String.Empty;
                foreach (string file in iro.AllFileNames())
                {
                    if (!String.IsNullOrEmpty(filter) && (file.IndexOf(filter) < 0))
                    {
                        continue;
                    }
                    Console.WriteLine("Writing " + file);
                    byte[] data = iro.GetBytes(file);
                    string fn   = System.IO.Path.Combine(args[2], file);
                    fn = fn.Replace("%", "___").Replace(":", "---");
                    System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(fn));
                    System.IO.File.WriteAllBytes(fn, data);
                }
                sw.Stop();
                Console.WriteLine("Done in " + (sw.ElapsedMilliseconds / 1000f) + " seconds");
            }
            else if (args[0].Equals("MAKEPATCH", StringComparison.InvariantCultureIgnoreCase))
            {
                _7thWrapperLib.IrosArc      orig     = new _7thWrapperLib.IrosArc(args[1]);
                _7thWrapperLib.IrosArc      newarc   = new _7thWrapperLib.IrosArc(args[2]);
                _7thWrapperLib.CompressType compress = (_7thWrapperLib.CompressType)Enum.Parse(typeof(_7thWrapperLib.CompressType), args[4]);
                using (var fs = new System.IO.FileStream(args[3], System.IO.FileMode.Create)) {
                    _7thWrapperLib.IrosPatcher.Create(orig, newarc, fs, compress, onProgress);
                }
            }
            else if (args[0].Equals("APPLYPATCH", StringComparison.InvariantCultureIgnoreCase))
            {
                _7thWrapperLib.IrosArc orig  = new _7thWrapperLib.IrosArc(args[1], true);
                _7thWrapperLib.IrosArc patch = new _7thWrapperLib.IrosArc(args[2]);
                orig.ApplyPatch(patch, onProgress);
            }
        }