Пример #1
0
        /// <inheritdoc cref="Task.Execute"/>
        public override bool Execute()
        {
            try
            {
                Log.LogMessageFromResources("MessageSettingFlag", FilePath);

                LargeAddressAware.SetLargeAddressAware(FilePath);
            }
            catch (Exception e)
            {
                Log.LogErrorFromException(e, showStackTrace: true);
            }

            return(!Log.HasLoggedErrors);
        }
Пример #2
0
        public async Task <PatchInfo[]> RunAsync(DownloadConfiguration downloadConfiguration, PatchCache patchCache, CancellationToken ct = default)
        {
            Progress.Progress        = 0;
            Progress.IsIndeterminate = true;

            App.Logger.Info(nameof(ComparePhase), "Fetching patches");
            var patches = await PatchInfo.FetchPatchInfosAsync(_InstallConfiguration, downloadConfiguration, ct);

            App.Logger.Info(nameof(ComparePhase), "Fetching cache data");
            var cacheData = await patchCache.SelectAllAsync();

            App.Logger.Info(nameof(ComparePhase), "Pre-fetching file times");
            var preFetchedFileTimes = await Task.Run(() => _PreFetchFileTimes());

            var workingPatches = patches
                                 .Select(p => new UpdateInfo
            {
                PatchInfo         = p,
                ShouldUpdate      = true,
                LastWriteFileTime = preFetchedFileTimes.ContainsKey(p.Name) ? preFetchedFileTimes[p.Name] : 0
            })
                                 .ToArray();

            var nextIndexAtomic     = 0;
            var progressValueAtomic = 0;

            var errorTokenSource    = new CancellationTokenSource();
            var combinedTokenSource = CancellationTokenSource.CreateLinkedTokenSource(ct, errorTokenSource.Token);

            App.Logger.Info(nameof(ComparePhase), "Comparing files");
            Progress.IsIndeterminate = false;

            void ProcessLoop()
            {
                try
                {
                    var pso2ExecutableFileName = Path.GetFileName(_InstallConfiguration.PSO2Executable);

                    while (true)
                    {
                        var index = Interlocked.Increment(ref nextIndexAtomic) - 1;
                        if (index >= workingPatches.Length)
                        {
                            return;
                        }

                        combinedTokenSource.Token.ThrowIfCancellationRequested();

                        try
                        {
                            ref var patch = ref workingPatches[index];

                            var relativeFilePath = patch.PatchInfo.Name
                                                   .Substring(0, patch.PatchInfo.Name.Length - 4)
                                                   .Replace('/', Path.DirectorySeparatorChar)
                                                   .ToLower();
                            var filePath = Path.Combine(_InstallConfiguration.PSO2BinDirectory, relativeFilePath);
                            var fileName = Path.GetFileName(relativeFilePath);

                            // skip this if mod files are not enabled so they are marked as invalid
                            if (Properties.Settings.Default.ModFilesEnabled)
                            {
                                // skip file if a file with the same name exists in the mods folder
                                if (Path.GetDirectoryName(filePath).ToLower() == _InstallConfiguration.DataWin32Directory.ToLower())
                                {
                                    var modFilePath = Path.Combine(_InstallConfiguration.ModsDirectory, fileName);
                                    if (File.Exists(modFilePath))
                                    {
                                        patch.ShouldUpdate = false;
                                        continue;
                                    }
                                }
                            }

                            if (!cacheData.ContainsKey(patch.PatchInfo.Name))
                            {
                                continue;
                            }

                            var cacheEntry = cacheData[patch.PatchInfo.Name];

                            if (patch.PatchInfo.Hash != cacheEntry.Hash)
                            {
                                continue;
                            }

                            // skip pso2.exe if the file is large address aware patched
                            if (fileName == pso2ExecutableFileName &&
                                File.Exists(filePath) &&
                                Properties.Settings.Default.LargeAddressAwareEnabled &&
                                LargeAddressAware.IsLargeAddressAwarePactchApplied(_InstallConfiguration, patch.PatchInfo.Hash))
                            {
                                patch.ShouldUpdate = false;
                                continue;
                            }

                            if (patch.LastWriteFileTime == 0)
                            {
                                patch.LastWriteFileTime = new FileInfo(filePath).LastWriteTimeUtc.ToFileTimeUtc();
                            }

                            patch.ShouldUpdate = patch.LastWriteFileTime != cacheEntry.LastWriteTime;
                        }
                        finally
                        {
                            Interlocked.Increment(ref progressValueAtomic);
                        }
                    }
                }
Пример #3
0
 public async Task RunAsync(CancellationToken ct = default)
 {
     await Task.Run(() => LargeAddressAware.ApplyLargeAddressAwarePatch(_InstallConfiguration));
 }