/// <summary> /// Queries or loads the latest version of DarkRift /// </summary> /// <returns>The latest version of DarkRift</returns> public string GetLatestDarkRiftVersion() { Console.WriteLine("Querying server for the latest DarkRift version..."); string uri = $"/DarkRift2/Releases/"; string latestJson; try { latestJson = webClientUtility.DownloadString(uri); } catch (WebException e) { Console.WriteLine(Output.Yellow($"Could not query latest DarkRift version from the server. Will use the last known latest instead.\n\t{e.Message}")); return(null); } // Parse out 'latest' field VersionMetadata versionMetadata = VersionMetadata.Parse(latestJson); Console.WriteLine($"Latest version of DarkRift is {versionMetadata.Latest}."); context.Profile.LatestKnownDarkRiftVersion = versionMetadata.Latest; context.Save(); return(versionMetadata.Latest); }
/// <summary> /// Queries or loads the latest version of DarkRift /// </summary> /// <returns>The latest version of DarkRift</returns> public static string GetLatestDarkRiftVersion() { if (latestDarkRiftVersion != null) { return(latestDarkRiftVersion); } Console.WriteLine("Querying server for the latest DarkRift version..."); string uri = $"https://www.darkriftnetworking.com/DarkRift2/Releases/"; try { using (WebClient myWebClient = new WebClient()) { string latestJson = myWebClient.DownloadString(uri); // Parse out 'latest' field VersionMetadata versionMetadata = VersionMetadata.Parse(latestJson); Console.WriteLine($"Server says the latest version is {versionMetadata.Latest}."); Profile profile = Profile.Load(); profile.LatestKnownDarkRiftVersion = versionMetadata.Latest; profile.Save(); latestDarkRiftVersion = versionMetadata.Latest; return(versionMetadata.Latest); } } catch (WebException e) { Console.WriteLine(Output.Yellow($"Could not query latest DarkRift version from the server. Will use the last known latest instead.\n\t{e.Message}")); latestDarkRiftVersion = Profile.Load().LatestKnownDarkRiftVersion; if (latestDarkRiftVersion == null) { Console.WriteLine(Output.Red($"No latest DarkRift version stored locally!")); return(null); } Console.WriteLine($"Last known latest version is {latestDarkRiftVersion}."); return(latestDarkRiftVersion); } }
/// <summary> /// Queries or loads the latest version of DarkRift /// </summary> /// <returns>The latest version of DarkRift</returns> public static string GetLatestDarkRiftVersion() { if (latestDarkRiftVersion != null) { return(latestDarkRiftVersion); } Console.WriteLine("Querying server for the latest DarkRift version..."); try { using (WebClient myWebClient = new WebClient()) { string latestJson = myWebClient.DownloadString(Config.DR_DR2_RELEASE_URI); // Parse out 'latest' field VersionMetadata versionMetadata = VersionMetadata.Parse(latestJson); Console.WriteLine($"Server says the latest version is {versionMetadata.Latest}."); Profile.LatestKnownDarkRiftVersion = versionMetadata.Latest; Profile.Save(); latestDarkRiftVersion = versionMetadata.Latest; return(versionMetadata.Latest); } } catch (WebException e) { Console.WriteLine(Output.Yellow($"Could not query latest DarkRift version from the server. Will use the last known latest instead.\n\t{e.Message}")); latestDarkRiftVersion = Profile.LatestKnownDarkRiftVersion; if (latestDarkRiftVersion == null) { Console.Error.WriteLine(Output.Red($"No latest DarkRift version stored locally!")); return(null); } Console.WriteLine($"Last known latest version is {latestDarkRiftVersion}."); return(latestDarkRiftVersion); } }
/// <summary> /// Updates all the package or the CLI given provided options in cmd - check Options.cs /// </summary> /// <param name="opts">PackageOptions from cmd</param> /// <returns>Exit code</returns> public static int UpdatePackagesOrCli(PackageOptions opts) { // If --cli is defined we upgrade our runtime if (opts.UpgradeCli) { string myPath = Directory.GetDirectoryRoot(Assembly.GetEntryAssembly().Location); using (WebClient myWebClient = new WebClient()) { string latestJson = null; try { latestJson = myWebClient.DownloadString(Config.DR_CLI_RELEASE_URI); } catch (WebException) { Console.WriteLine(Output.Red("Couldn't check for the latest version of the CLI")); return(1); } // Parse out 'latest' field VersionMetadata versionMetadata = VersionMetadata.Parse(latestJson); var version = Assembly.GetEntryAssembly().GetName().Version; var serverVersion = new Version(versionMetadata.Latest); if (serverVersion == version) { Console.WriteLine("DarkRift CLI is up to date"); return(0); } else if (serverVersion > version) { Console.WriteLine($"Most recent CLI version is {versionMetadata.Latest}."); Console.WriteLine($"Current version installed is {version}"); Console.WriteLine("Updating..."); string stagingPath = Path.Combine(Config.USER_DR_DIR, "DownloadCLI.zip"); string uriDownload = $"{Config.DR_CLI_RELEASE_URI}/{serverVersion}"; try { myWebClient.DownloadFile(uriDownload, stagingPath); } catch (WebException) { Console.WriteLine(Output.Red($"Couldn't download DarkRift CLI {serverVersion}")); return(1); } Console.WriteLine($"Extracting package..."); ZipFile.ExtractToDirectory(stagingPath, myPath, true); Console.WriteLine(Output.Green($"Successfully downloaded and installed DarkRift CLI version {serverVersion}")); return(0); } // This shouldn't happen else { Console.WriteLine("How can you possibly have a greater version than it is on the server???"); return(1); } } } // If it is not defined it just updates all packages to the latest version of the sdk else { foreach (Package package in PackageManager.PackageList) { PackageState state = PackageManager.UpdateBySdkVersion(package.ID, out Package p); // check if success if (state != PackageState.Installed) { Console.WriteLine(Output.Red($"Something went wrong updating {package.ID}")); } } } return(0); }