Exemplo n.º 1
0
        public static void Build(InstallStatus status, string path, string fomod)
        {
            var compressor = new SevenZipCompressor
            {
                ArchiveFormat     = OutArchiveFormat.SevenZip,
                CompressionLevel  = CompressionLevel.Fast,
                CompressionMethod = CompressionMethod.Lzma2,
                CompressionMode   = CompressionMode.Create,
            };

            compressor.CustomParameters.Add("mt", "on"); //enable multithreading

            compressor.FilesFound              += (sender, e) => status.ItemsTotal = e.Value;
            compressor.Compressing             += (sender, e) => e.Cancel = status.Token.IsCancellationRequested;
            compressor.CompressionFinished     += (sender, e) => status.Finish();
            compressor.FileCompressionStarted  += (sender, e) => status.CurrentOperation = "Compressing " + e.FileName;
            compressor.FileCompressionFinished += (sender, e) => status.Step();

            compressor.CompressDirectory(path, fomod, true);
        }
Exemplo n.º 2
0
        public void Install(CancellationToken inToken)
        {
            var LinkedSource = CancellationTokenSource.CreateLinkedTokenSource(inToken);

            Token = LinkedSource.Token;

            Prompts.PromptPaths();

            _bsaDiff = DependencyRegistry.Container
                       //.With("progress").EqualTo(ProgressMinorOperation)
                       //.With("token").EqualTo(Token)
                       .GetInstance <BsaDiff>();
            _nvse = DependencyRegistry.Container
                    .With("FNVPath").EqualTo(Prompts.FalloutNVPath)
                    .GetInstance <NVSE>();

            var opProg = new InstallStatus(ProgressMajorOperation, Token)
            {
                ItemsTotal = 7 + Game.BuildableBSAs.Count + Game.CheckedESMs.Length
            };

            try
            {
                HandleStep <CheckingRequiredFilesStep>(opProg);

                if (!_nvse.Check())
                {
                    string err = null;
                    //true : should download, continue install
                    //false: should not download, continue install
                    //null : should not download, abort install
                    switch (_nvse.Prompt())
                    {
                    case true:
                        if (_nvse.Install(out err))
                        {
                            break;
                        }
                        goto default;

                    case false:
                        break;

                    default:
                        Fail(err);
                        return;
                    }
                }

                try
                {
                    const string curOp = "Creating FOMOD foundation";
                    opProg.CurrentOperation = curOp;

                    Log.File(curOp);

                    string
                        srcFolder = Path.Combine(Paths.AssetsDir, "TTW Data", "TTW Files"),
                        tarFolder = Prompts.TTWSavePath;

                    Util.CopyFolder(srcFolder, tarFolder);
                }
                finally
                {
                    //+1
                    opProg.Step();
                }

                //count BuildableBSAs
                HandleStep <BuildBsasStep>(opProg);

                try
                {
                    opProg.CurrentOperation = "Building SFX";

                    BuildSFX();
                }
                finally
                {
                    //+1
                    opProg.Step();
                }

                try
                {
                    opProg.CurrentOperation = "Building Voices";

                    BuildVoice();
                }
                finally
                {
                    //+1
                    opProg.Step();
                }

                try
                {
                    const string ttwArchive = "TaleOfTwoWastelands.bsa";
                    opProg.CurrentOperation = "Copying " + ttwArchive;

                    if (!File.Exists(Path.Combine(DirTTWMain, ttwArchive)))
                    {
                        File.Copy(Path.Combine(Paths.AssetsDir, "TTW Data", ttwArchive), Path.Combine(DirTTWMain, ttwArchive));
                    }
                }
                finally
                {
                    //+1
                    opProg.Step();
                }

                //count CheckedESMs
                if (!PatchMasters(opProg))
                {
                    return;
                }

                //+2
                {
                    const string prefix = "Copying ";
                    const string opA    = "Fallout3 music files";
                    const string opB    = "Fallout3 video files";

                    opProg.CurrentOperation = prefix + opA;
                    FalloutLineCopy(opA, Path.Combine(Paths.AssetsDir, "TTW Data", "FO3_MusicCopy.txt"));
                    opProg.Step();

                    opProg.CurrentOperation = prefix + opB;
                    FalloutLineCopy(opB, Path.Combine(Paths.AssetsDir, "TTW Data", "FO3_VideoCopy.txt"));
                    opProg.Step();
                }

                HandleStep <BuildFOMODsStep>(opProg);

                opProg.Finish();

                Log.Display("Install completed successfully.");
                MessageBox.Show(string.Format(Localization.InstalledSuccessfully, Localization.TTW));
            }
            catch (OperationCanceledException)
            {
                //intentionally cancelled - swallow exception
                Log.Dual("Install was cancelled.");
            }
            catch (Exception ex)
            {
                Log.File(ex.ToString());
                Fail("An error interrupted the install!");
                MessageBox.Show(string.Format(Localization.ErrorWhileInstalling, ex.Message), Localization.Error);
            }
        }
Exemplo n.º 3
0
        public bool PatchBsa(CompressionOptions bsaOptions, string oldBSA, string newBSA, bool simulate = false)
        {
            var Op = new InstallStatus(Progress, Token) { ItemsTotal = 7 };

            var outBsaFilename = Path.GetFileNameWithoutExtension(newBSA);

            BSA bsa;
            try
            {
                Op.CurrentOperation = "Opening " + Path.GetFileName(oldBSA);

                bsa = new BSA(oldBSA, bsaOptions);
            }
            finally
            {
                Op.Step();
            }

            IDictionary<string, string> renameDict;
            try
            {
                Op.CurrentOperation = "Opening rename database";

#if LEGACY
                var renamePath = Path.Combine(Installer.PatchDir, outBsaFilename, "RenameFiles.dict");
#else
                var renamePath = Path.Combine(Installer.PatchDir, Path.ChangeExtension(outBsaFilename, ".ren"));
#endif
                if (File.Exists(renamePath))
                {
#if LEGACY
                    renameDict = new Dictionary<string, string>(Util.ReadOldDatabase(renamePath));
#else
                    using (var fileStream = File.OpenRead(renamePath))
                    using (var lzmaStream = new LzmaDecodeStream(fileStream))
                    using (var reader = new BinaryReader(lzmaStream))
                    {
                        var numPairs = reader.ReadInt32();
                        renameDict = new Dictionary<string, string>(numPairs);

                        while (numPairs-- > 0)
                            renameDict.Add(reader.ReadString(), reader.ReadString());
                    }
#endif
                }
                else
                    renameDict = new Dictionary<string, string>();
            }
            finally
            {
                Op.Step();
            }

            PatchDict patchDict;
            try
            {
                Op.CurrentOperation = "Opening patch database";

#if LEGACY
                var chkPrefix = Path.Combine(Installer.PatchDir, outBsaFilename);
                var chkPath = Path.Combine(chkPrefix, "CheckSums.dict");
                patchDict = PatchDict.FromOldDatabase(Util.ReadOldDatabase(chkPath), chkPrefix, b => b);
#else
                var patchPath = Path.Combine(Installer.PatchDir, Path.ChangeExtension(outBsaFilename, ".pat"));
                if (File.Exists(patchPath))
                {
                    patchDict = new PatchDict(patchPath);
                }
                else
                {
                    Log.Dual("\tNo patch database is available for: " + oldBSA);
                    return false;
                }
#endif
            }
            finally
            {
                Op.Step();
            }

            using (bsa)
            {
                try
                {
                    RenameFiles(bsa, renameDict);

                    if (renameDict.Count > 0)
                    {
                        foreach (var kvp in renameDict)
                        {
                            Log.Dual("File not found: " + kvp.Value);
                            Log.Dual("\tCannot create: " + kvp.Key);
                        }
                    }
                }
                finally
                {
                    Op.Step();
                }

                var allFiles = bsa.SelectMany(folder => folder).ToList();
                try
                {
                    var opChk = new InstallStatus(Progress, Token) { ItemsTotal = patchDict.Count };

                    var joinedPatches = from patKvp in patchDict
                                        //if the join is not grouped, this will exclude missing files, and we can't find and fail on them
                                        join oldFile in allFiles on patKvp.Key equals oldFile.Filename into foundOld
                                        join bsaFile in allFiles on patKvp.Key equals bsaFile.Filename
                                        select new PatchJoin(bsaFile, foundOld.SingleOrDefault(), patKvp.Value);

#if DEBUG
                    var watch = new Stopwatch();
                    try
                    {
                        watch.Start();
#endif
#if PARALLEL
                        Parallel.ForEach(joinedPatches, join =>
#else
                        foreach (var join in joinedPatches)
#endif
 HandleFile(opChk, join)
#if PARALLEL
)
#endif
;
#if DEBUG
                    }
                    finally
                    {
                        watch.Stop();
                        Debug.WriteLine(outBsaFilename + " HandleFile loop finished in " + watch.Elapsed);
                    }
#endif
                }
                finally
                {
                    Op.Step();
                }

                try
                {
                    Op.CurrentOperation = "Removing unnecessary files";

                    var notIncluded = allFiles.Where(file => !patchDict.ContainsKey(file.Filename));
                    var filesToRemove = new HashSet<BSAFile>(notIncluded);

                    foreach (BSAFolder folder in bsa)
                        folder.RemoveWhere(filesToRemove.Contains);

                    var emptyFolders = bsa.Where(folder => folder.Count == 0).ToList();
                    emptyFolders.ForEach(folder => bsa.Remove(folder));
                }
                finally
                {
                    Op.Step();
                }

                try
                {
                    Op.CurrentOperation = "Saving " + Path.GetFileName(newBSA);

                    if (!simulate)
                        bsa.Save(newBSA.ToLowerInvariant());
                }
                finally
                {
                    Op.Step();
                }
            }

            Op.Finish();

            return true;
        }