AcManager.Tools.Miscellaneous.LocaleUpdater.InstallCustom C# (CSharp) Méthode

InstallCustom() public méthode

public InstallCustom ( string id, IProgress progress = null, CancellationToken cancellation = default(CancellationToken) ) : Task
id string
progress IProgress
cancellation System.Threading.CancellationToken
Résultat Task
        public async Task<string> InstallCustom(string id, IProgress<double?> progress = null, CancellationToken cancellation = default(CancellationToken)) {
            var destination = FilesStorage.Instance.GetDirectory("Locales", id);

            var data = await CmApiProvider.GetDataAsync(@"locales/get/base", progress, cancellation);
            if (cancellation.IsCancellationRequested || data == null) return null;

            progress?.Report(null);
            using (var memory = new MemoryStream(data))
            using (var updateZip = new ZipArchive(memory)) {
                foreach (var entry in updateZip.Entries) {
                    using (var stream = entry.Open()) {
                        var filename = Path.Combine(destination, entry.Name);
                        if (File.Exists(filename)) continue;

                        await FileUtils.WriteAllBytesAsync(filename, stream, cancellation);
                        if (cancellation.IsCancellationRequested) return null;
                    }
                }
            }

            return destination;
        }
    }