public Updater() { _project = Project.ByInstallConfig( InstallConfigJson.Load(FilePath.InstallConfigFile) ); }
/// <summary> /// Upload updater to drive and return its link. /// </summary> public void GetUpdater(string os) { Console.WriteLine("Creating Updater..."); string fileId; if (DriveUtils.GetUpdaterLink(_project, os, out fileId)) { Console.WriteLine(DriveUtils.IdToDirectDownloadLink(fileId)); return; } //copy updater into temp var sourcePath = ""; switch (os) { case "win": sourcePath = FilePath.WinUpdaterDir; break; case "linux": sourcePath = FilePath.LinuxUpdaterDir; break; default: return; } var destinationPath = FilePath.TempDir; Directory.CreateDirectory(destinationPath); Utils.Empty(new DirectoryInfo(destinationPath)); //Now Create all of the directories foreach (var dirPath in Directory.GetDirectories(sourcePath, "*", SearchOption.AllDirectories)) { Directory.CreateDirectory(dirPath.Replace(sourcePath, destinationPath)); } //Copy all the files & Replaces any files with the same name foreach (var newPath in Directory.GetFiles(sourcePath, "*.*", SearchOption.AllDirectories)) { File.Copy(newPath, newPath.Replace(sourcePath, destinationPath), true); } //create json for updater var installConfigJson = new InstallConfigJson( FilePath.InstallConfigJsonInTemp, DriveUtils.GetRootFoderIdFromMyDrive(), _project.SoftwareName ); installConfigJson.SaveJson(); //zip and upload File.Delete(FilePath.TempZipFile); ZipFile.CreateFromDirectory(FilePath.TempDir, FilePath.TempZipFile); Console.WriteLine("Uploading to Drive..."); var updaterFileId = DriveUtils.UploadFileToCloud($"{_project.SoftwareName}--{os}.zip", _project.FolderId, FilePath.TempZipFile); Console.WriteLine("Link for the updater:"); Console.WriteLine(DriveUtils.IdToDirectDownloadLink(updaterFileId)); }