private async Task <ExpansionInfo> GetNewestExpansionFile(EditsResource edits, AppEdit appEdit) { try { ApksListResponse apksResponse = await edits.Apks.List(PackageName, appEdit.Id).ExecuteAsync(_cts.Token); int apkVersion = -1; int expansionVersion = -1; long fileSize = 0; foreach (Apk apk in apksResponse.Apks) { // ReSharper disable once UseNullPropagation if (apk.VersionCode != null) { if (apk.VersionCode.Value > apkVersion) { try { ExpansionFile expansionResponse = await edits.Expansionfiles.Get(PackageName, appEdit.Id, apk.VersionCode.Value, EditsResource.ExpansionfilesResource.GetRequest.ExpansionFileTypeEnum.Main).ExecuteAsync(_cts.Token); if (expansionResponse.ReferencesVersion != null) { expansionVersion = expansionResponse.ReferencesVersion.Value; ExpansionFile expansionRefResponse = await edits.Expansionfiles.Get(PackageName, appEdit.Id, expansionResponse.ReferencesVersion.Value, EditsResource.ExpansionfilesResource.GetRequest.ExpansionFileTypeEnum.Main).ExecuteAsync(_cts.Token); if (expansionRefResponse.FileSize != null && expansionRefResponse.FileSize.Value > 0) { apkVersion = apk.VersionCode.Value; expansionVersion = expansionResponse.ReferencesVersion.Value; fileSize = expansionRefResponse.FileSize.Value; } } else if (expansionResponse.FileSize != null && expansionResponse.FileSize.Value > 0) { apkVersion = apk.VersionCode.Value; expansionVersion = apkVersion; fileSize = expansionResponse.FileSize.Value; } } catch (Exception) { // ignored } } } } if (apkVersion < 0) { return(null); } return(new ExpansionInfo(apkVersion, expansionVersion, fileSize)); } catch (Exception) { // ignored } return(null); }
public int RetreiveLastBuildNumber() { InitEditService(); ApksListResponse apksListResponse = _edits.Apks.List(packageName, _editsId).Execute(); if (apksListResponse == null) { Logger.WrightLog("Retreive number failed"); return(-1); } else { return(apksListResponse.Apks[apksListResponse.Apks.Count - 1].VersionCode.Value); } }
// ReSharper disable once UnusedMethodReturnValue.Local private bool ListApks() { if (_serviceThread != null) { return(false); } UpdateStatus(string.Empty); _cts = new CancellationTokenSource(); _serviceThread = new Thread(async() => { UpdateStatus(string.Empty); StringBuilder sb = new StringBuilder(); try { UserCredential credential = await GetCredatials(); using (AndroidPublisherService service = new AndroidPublisherService(GetInitializer(credential))) { EditsResource edits = service.Edits; EditsResource.InsertRequest editRequest = edits.Insert(null, PackageName); AppEdit appEdit = await editRequest.ExecuteAsync(_cts.Token); ApksListResponse apksResponse = await edits.Apks.List(PackageName, appEdit.Id).ExecuteAsync(_cts.Token); sb.AppendLine("Apks:"); foreach (Apk apk in apksResponse.Apks) { if (apk.VersionCode != null) { sb.AppendLine($"Version: {apk.VersionCode.Value}, SHA1: {apk.Binary.Sha1}"); await PrintExpansion(sb, edits, appEdit, apk.VersionCode.Value); } } } } catch (Exception e) { sb.AppendLine($"Exception: {e.Message}"); } finally { _serviceThread = null; _cts.Dispose(); UpdateStatus(sb.ToString()); } }); _serviceThread.Start(); return(true); }