private static void Main(string[] args) { var docopt = new DocoptWrapper(Usage, args); var service = new Service(FilePath.SecretJsonFile, FilePath.CredentialsJsonFile); DriveUtils.SetService(service); var updater = new Updater.Updater(); if (docopt.Get("install").IsTrue) { updater.Install(docopt.GetInt("--code"), docopt.GetString("--name")); } else if (docopt.Get("checkupdate").IsTrue) { updater.Checkupdate(); } else if (docopt.Get("showversions").IsTrue) { //show all versions in the project updater.ShowVersions(); } #if DEBUG Console.WriteLine("Press Enter to exit..."); Console.ReadLine(); #endif }
private async Task HandleUpdater() { try { string updateSiteString = "https://onedrive.live.com/download?resid=D332F531B200D073%218103"; Uri updateSite = new Uri(updateSiteString); Uri remotePackageStorageDirectory = new Uri(updateSite, "Packages/"); if (Directory.Exists(baseDirectory) == false) { Directory.CreateDirectory(baseDirectory); } IStorageProvider storageProvider = new StorageProvider(baseDirectory); using (ICacheStorageProvider cacheStorageProvider = new CacheStorageProvider(System.IO.Path.Combine(baseDirectory, "Cache"))) { IPackageAcquisitionFactory packageAcquisitionFactory = new PackageAcquisitionFactory(); IUpdaterCache updaterCache = UpdaterCache.InitializeCache(cacheStorageProvider); IPackageMetadataCollection packageMetadataCollection = null; IUpdater updater = new Updater.Updater(); using (XmlReader xmlReader = XmlReader.Create(updateSite.AbsoluteUri)) { packageMetadataCollection = updater.ParseMetadataCollectionXml(xmlReader); } IUpdateState updateState = updater.DetermineUpdateState(updaterCache.InstalledPackages, packageMetadataCollection); IPackageInstaller packageInstaller = updater.CreateInstaller(); foreach (IPackageMetadata packageMetadata in updateState.Packages) { IPackageAcquisition packageAcquisition = packageAcquisitionFactory.BuildPackageAcquisition(remotePackageStorageDirectory, cacheStorageProvider); using (ZipArchive packageArchive = await packageAcquisition.AcquirePackageArchive(packageMetadata)) { using (IPackage package = Package.OpenPackage(packageMetadata, packageArchive)) { packageInstaller.Install(storageProvider, package); updaterCache.MarkPackageAsInstalled(package.Metadata); } } } } } catch (Exception ex) { string baseDirectory = System.IO.Path.Combine(Android.OS.Environment.ExternalStorageDirectory.AbsolutePath, "Updater"); File.WriteAllText(System.IO.Path.Combine(baseDirectory, "error.txt"), ex.ToString()); } }
private async void PerformUpdateCommandCallback() { Status = "Downloading update..."; Uri updateSite = new Uri(@"https://onedrive.live.com/download?resid=D332F531B200D073%218103"); Uri remotePackageStorageDirectory = new Uri(updateSite, "Packages/"); string baseDirectory = Path.GetFullPath("Data"); IStorageProvider storageProvider = new StorageProvider(baseDirectory); using (ICacheStorageProvider cacheStorageProvider = new CacheStorageProvider(Path.Combine(baseDirectory, "Cache"))) { IPackageAcquisitionFactory packageAcquisitionFactory = new PackageAcquisitionFactory(); IUpdaterCache updaterCache = UpdaterCache.InitializeCache(cacheStorageProvider); IPackageMetadataCollection packageMetadataCollection = null; IUpdater updater = new Updater.Updater(); using (XmlReader xmlReader = XmlReader.Create(updateSite.AbsoluteUri)) { packageMetadataCollection = updater.ParseMetadataCollectionXml(xmlReader); } IUpdateState updateState = updater.DetermineUpdateState(updaterCache.InstalledPackages, packageMetadataCollection); IPackageInstaller packageInstaller = updater.CreateInstaller(); foreach (IPackageMetadata packageMetadata in updateState.Packages) { IPackageAcquisition packageAcquisition = packageAcquisitionFactory.BuildPackageAcquisition(remotePackageStorageDirectory, cacheStorageProvider); using (ZipArchive packageArchive = await packageAcquisition.AcquirePackageArchive(packageMetadata)) { using (IPackage package = Package.OpenPackage(packageMetadata, packageArchive)) { packageInstaller.Install(storageProvider, package); updaterCache.MarkPackageAsInstalled(package.Metadata); } } } } RefreshImage(); Status = "Image updated!"; }