Пример #1
0
 private static string _GetPSO2Hash(InstallConfiguration installConfiguration)
 {
     using (var stream = File.OpenRead(installConfiguration.PSO2Executable))
         using (var md5 = MD5.Create())
         {
             var hashBytes = md5.ComputeHash(stream);
             return(string.Concat(hashBytes.Select(b => b.ToString("X2"))));
         }
 }
Пример #2
0
 private static Config _TryReadConfig(InstallConfiguration installConfiguration)
 {
     try
     {
         var file = File.ReadAllText(installConfiguration.LargeAddressAwareConfig);
         return(JsonConvert.DeserializeObject <Config>(file));
     }
     catch
     {
         return(null);
     }
 }
Пример #3
0
 private static Config _TryReadConfig(InstallConfiguration installConfiguration)
 {
     try
     {
         var file = File.ReadAllText(installConfiguration.LargeAddressAwareConfig);
         return(JsonConvert.DeserializeObject <Config>(file));
     }
     catch (Exception ex)
     {
         App.Logger.Warning(nameof(LargeAddressAware), "Failed to read config", ex);
         return(null);
     }
 }
Пример #4
0
        public static async Task <PatchCache> CreateAsync(InstallConfiguration configuration)
        {
            var connection = new SQLiteConnection($"Data Source={configuration.PatchCacheDatabase};Version=3");
            await connection.OpenAsync();

            const string tableString = @"create table if not exists PatchInfo (
                Id integer not null primary key,
                Name text not null unique on conflict replace,
                Hash text not null,
                LastWriteTime integer not null
            );";

            using (var command = connection.CreateCommand())
            {
                command.CommandText = tableString;
                await command.ExecuteNonQueryAsync();
            }

            return(new PatchCache(connection));
        }
Пример #5
0
        public static void ApplyLargeAddressAwarePatch(InstallConfiguration installConfiguration)
        {
            if (IsLargeAddressAwarePactchApplied(installConfiguration, null))
            {
                return;
            }

            var originalHash = _GetPSO2Hash(installConfiguration);

            _ApplyLargeAddressAwarePatch(installConfiguration.PSO2Executable);

            var patchedHash = _GetPSO2Hash(installConfiguration);

            var config = new Config
            {
                OriginalHash = originalHash,
                PatchedHash  = patchedHash
            };
            var json = JsonConvert.SerializeObject(config);

            File.WriteAllText(installConfiguration.LargeAddressAwareConfig, json);
        }
Пример #6
0
        public static bool IsLargeAddressAwarePactchApplied(InstallConfiguration installConfiguration, string serverHash)
        {
            var config = _TryReadConfig(installConfiguration);

            if (config == null)
            {
                return(false);
            }

            if (serverHash != null && config.OriginalHash != serverHash)
            {
                return(false);
            }

            try
            {
                return(_GetPSO2Hash(installConfiguration) == config.PatchedHash);
            }
            catch
            {
                return(false);
            }
        }
Пример #7
0
        public static async Task <List <PatchInfo> > FetchPatchInfosAsync(InstallConfiguration installConfiguration, DownloadConfiguration downloadConfiguration, CancellationToken ct = default)
        {
            ct.ThrowIfCancellationRequested();

            var infos = new List <PatchInfo>();

            // patchlist
            App.Logger.Info(nameof(PatchInfo), "Downloading patch list");
            using (var client = new AquaHttpClient())
                using (var response = await client.GetAsync(downloadConfiguration.PatchesPatchList, ct))
                    using (var reader = new StringReader(await response.Content.ReadAsStringAsync()))
                    {
                        App.Logger.Info(nameof(PatchInfo), "Parsing patch list");

                        while (true)
                        {
                            ct.ThrowIfCancellationRequested();

                            var line = await reader.ReadLineAsync();

                            if (line == null)
                            {
                                break;
                            }

                            var parts = line.Split();
                            if (parts.Length < 4)
                            {
                                throw new Exception($"Patch list line contained less than four parts: \"{line}\"");
                            }

                            var name = parts[0];
                            var hash = parts[1];
                            var type = parts[3];

                            if (Path.GetFileNameWithoutExtension(name) == Path.GetFileName(installConfiguration.CensorFile))
                            {
                                continue;
                            }

                            Uri root;
                            switch (type)
                            {
                            case "p":
                                root = downloadConfiguration.RootPatches;
                                break;

                            case "m":
                                root = downloadConfiguration.RootMaster;
                                break;

                            default:
                                throw new Exception($"Patch list line contained unknown root type \"{type}\"");
                            }

                            infos.Add(new PatchInfo
                            {
                                Name         = name,
                                Hash         = hash,
                                DownloadPath = new Uri(root, name)
                            });
                        }
                    }

            // launcherlist
            App.Logger.Info(nameof(PatchInfo), "Downloading launcher list");
            using (var client = new AquaHttpClient())
                using (var response = await client.GetAsync(downloadConfiguration.PatchesLauncherList, ct))
                    using (var reader = new StringReader(await response.Content.ReadAsStringAsync()))
                    {
                        App.Logger.Info(nameof(PatchInfo), "Parsing launcher list");

                        while (true)
                        {
                            ct.ThrowIfCancellationRequested();

                            var line = await reader.ReadLineAsync();

                            if (line == null)
                            {
                                break;
                            }

                            var parts = line.Split();
                            if (parts.Length < 3)
                            {
                                throw new Exception($"Launcher list line contained less than three parts: \"{line}\"");
                            }

                            var name = parts[0];
                            // parts[1] is file size
                            var hash = parts[2];

                            infos.Add(new PatchInfo
                            {
                                Name         = name,
                                Hash         = hash,
                                DownloadPath = new Uri(downloadConfiguration.RootPatches, name)
                            });
                        }
                    }

            return(infos);
        }