static void Androidpublisher(Perform perform, CommandLine commandLine, string[] args) { var authFile = commandLine.GetValue(ParameterAuth); var packageName = commandLine.GetValue(ParameterPackageName); var versionCode = int.Parse(commandLine.GetValue(ParameterVersion)); var apkFile = commandLine.GetValue(ParameterApk); var obbFile = commandLine.GetValue(ParameterObb); var name = commandLine.GetValue(ParameterName); var releaseNote = commandLine.GetValue(ParameterReleasenote); ExecuteAndroidpublisher(authFile, packageName, (service, editId) => { if (!string.IsNullOrWhiteSpace(apkFile)) { var apkSize = new FileInfo(apkFile).Length; var apkUpload = service.Edits.Apks.Upload(packageName, editId, File.OpenRead(apkFile), "application/vnd.android.package-archive"); apkUpload.ProgressChanged += (progress) => { Console.WriteLine($"上传{apkFile}进度:{progress.BytesSent.GetMemory()}/{apkSize.GetMemory()}"); }; Console.WriteLine($"开始上传apk文件:{apkFile}"); var apkResult = apkUpload.Upload(); if (apkResult.Exception != null) { throw apkResult.Exception; } } if (!string.IsNullOrWhiteSpace(obbFile)) { var obbSize = new FileInfo(obbFile).Length; var obbUpload = service.Edits.Expansionfiles.Upload(packageName, editId, versionCode, EditsResource.ExpansionfilesResource.UploadMediaUpload.ExpansionFileTypeEnum.Main, File.OpenRead(obbFile), "application/octet-stream"); obbUpload.ProgressChanged += (progress) => { Console.WriteLine($"上传{obbFile}进度:{progress.BytesSent.GetMemory()}/{obbSize.GetMemory()}"); }; Console.WriteLine($"开始上传obb文件:{apkFile}"); var obbResult = obbUpload.Upload(); if (obbResult.Exception != null) { throw obbResult.Exception; } } }, (release) => { if (!string.IsNullOrWhiteSpace(name)) { release.Name = name; } if (!string.IsNullOrWhiteSpace(releaseNote)) { release.ReleaseNotes = new List <LocalizedText>(); var model = Toml.ToModel(FileUtil.GetFileString(releaseNote)); foreach (var pair in model) { release.ReleaseNotes.Add(new LocalizedText() { Language = pair.Key, Text = (string)pair.Value }); } } release.VersionCodes = new List <long?>() { versionCode }; }); }
public static async Task <bool> PerformBootstrapAsync(CancellationToken ct = default) { var conf = Toml.ToModel(File.ReadAllText(BootstrapperConfFile, Encoding.UTF8)); var manifest_url = (string)conf["manifest_url"]; if (manifest_url == null) { StatusText("ERROR: manifest_url not configured"); return(false); } StatusText("Checking for updates..."); httpClient = new HttpClient(); httpClient.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", "ArknightsAutoHelperBootstrapper"); var manifest_str = await httpClient.GetStringAsync(manifest_url); var table = Toml.ToModel(manifest_str); if (new Version((string)table["version"]) > System.Reflection.Assembly.GetEntryAssembly().GetName().Version) { if (table.ContainsKey("download_url")) { // TODO: update bootstrapper await UpdateBootstrapper((string)table["download_url"], ct); // unreachable return(true); } else { StatusText("Bootstrapper need update, please visit " + (string)table["update_page"]); return(false); } } var manifest = Toml.ToModel <BootstrapperManifest>(manifest_str); var releases_bytes = await httpClient.GetByteArrayAsync(manifest.ReleaseManifestUrl); var releases = JsonNode.Parse(releases_bytes).AsArray(); var package2release = releases.Join( manifest.Packages, release => (string)release["tag_name"], package => package.Tag, (release, package) => (package, release) ).ToDictionary(x => x.package.Name, x => x.release.AsObject()); var success = true; foreach (var package in manifest.Packages) { StatusText(string.Format("Updating package {0}", package.Name)); try { var result = await UpdatePackage(package, package2release[package.Name], ct); StatusText(string.Format("{0}: {1}", package.Name, result)); } catch (Exception ex) { StatusText(string.Format("Failed to update package {0}: {1}", package.Name, ex.Message)); success = false; } } if (Directory.Exists(CacheDir)) { StatusText("Purging cache..."); foreach (var entry in new DirectoryInfo(CacheDir).EnumerateFileSystemInfos()) { if (entry.Attributes.HasFlag(FileAttributes.Directory)) { Directory.Delete(entry.FullName, true); } else { entry.Delete(); } } } if (File.Exists(TriggerUpdateTag)) { File.Delete(TriggerUpdateTag); } return(success); }