private static ISaveUpgradeStep?FindPathToVersion(SaveInformation saveInfo, string fromVersion, string toVersion) { var step = SaveUpgradeSteps.GetUpgradeStepForVersion(fromVersion); if (step == null) { return(null); } saveInfo.ThriveVersion = fromVersion; var nextVersion = step.VersionAfterUpgrade(saveInfo); // Stop if found target version if (VersionUtils.Compare(nextVersion, toVersion) >= 0) { return(step); } // Otherwise verify that there exists steps until the toVersion if (FindPathToVersion(saveInfo, nextVersion, toVersion) == null) { // No further path found return(null); } return(step); }
/// <summary> /// Loads the save file with the latest write time. /// Does not load if there is a version difference. /// </summary> /// <returns>False if the versions do not match</returns> public static bool QuickLoad() { // TODO: is there a way to to find the latest modified file without checking them all? var save = CreateListOfSaves(SaveOrder.LastModifiedFirst).FirstOrDefault(); if (save == null) { GD.Print("No saves exist, can't quick load"); return(true); } SaveInformation info; try { info = global::Save.LoadJustInfoFromSave(save); } catch (Exception e) { GD.PrintErr($"Cannot load save information for save {save}: {e}"); return(true); } var versionDiff = VersionUtils.Compare(info.ThriveVersion, Constants.Version); if (versionDiff != 0) { return(false); } LoadSave(save); return(true); }
public string PerformUpgrade(SaveInformation saveInfo, string inputSave, string outputSave) { var versionDifference = VersionUtils.Compare(VersionAfter, saveInfo.ThriveVersion); if (versionDifference == int.MaxValue) { throw new Exception("Could not compare version in save to version it would be upgraded to"); } if (versionDifference <= 0) { throw new ArgumentException("This converter can't upgrade the provided save"); } // SaveInformation is not used here as saveInfo is assumed to be up to date var(freshInfo, saveStructure, screenshot) = Save.LoadJSONStructureFromFile(inputSave); if (freshInfo.ThriveVersion != saveInfo.ThriveVersion) { GD.PrintErr("Unexpected save version in freshly loaded save information"); } PerformUpgradeOnJSON(saveStructure); PerformUpgradeOnInfo(saveInfo); CopySaveInfoToStructure(saveStructure, saveInfo); // TODO: should the "Name" in saveStructure be updated? (there's a bigger need to update it when making the // backup file rather than here...) Save.WriteSaveJSONToFile(saveInfo, saveStructure, screenshot, outputSave); return(VersionAfter); }
private static void UpdatePackageReferences(NewProjectSettings settings) { try { string productVersion = Assembly.GetEntryAssembly().GetProductVersion(); string flutterVersion = settings.FlutterVersion; if (string.IsNullOrEmpty(flutterVersion)) { flutterVersion = FlutterTools.GetVersion().Version; } SdkVersion sdk = AppSettings.Default.SdkTable.Versions.First(v => v.Version == productVersion); SdkFlutterVersion fv = sdk.Compatibility.FirstOrDefault(f => VersionUtils.Compare(f.Version, flutterVersion) == 0); if (fv == null) { // We're using a version of Flutter that is not officially supported by Flutnet (no binding libraries exist). // Let's try and see if we can find a prior version that's fully compatible. // If we can't find anything, simply return and keep the template configuration as is. sdk.Compatibility.Sort(new SdkFlutterVersionComparer()); fv = sdk.Compatibility.LastOrDefault(f => VersionUtils.Compare(f.Version, flutterVersion) < 0); if (fv == null) { return; } } if (settings.TargetAndroid) { string interopVersion = !string.IsNullOrEmpty(fv.AndroidInteropVersion) ? fv.AndroidInteropVersion : fv.Version; string csprojPath = Path.Combine(settings.SolutionPath, $"{settings.ProjectName}.Android", $"{settings.ProjectName}.Android.csproj"); UpdatePackageReferences_AndroidProject(csprojPath, interopVersion); csprojPath = Path.Combine(settings.SolutionPath, $"{settings.ProjectName}.ModuleInterop.Android", $"{settings.ProjectName}.ModuleInterop.Android.csproj"); UpdatePackageReferences_AndroidProject(csprojPath, interopVersion); } if (settings.TargetIos && OperatingSystem.IsMacOS()) { string interopVersion = !string.IsNullOrEmpty(fv.IosInteropVersion) ? fv.IosInteropVersion : fv.Version; string csprojPath = Path.Combine(settings.SolutionPath, $"{settings.ProjectName}.iOS", $"{settings.ProjectName}.iOS.csproj"); UpdatePackageReferences_iOSProject(csprojPath, interopVersion); csprojPath = Path.Combine(settings.SolutionPath, $"{settings.ProjectName}.PluginInterop.iOS", $"{settings.ProjectName}.PluginInterop.iOS.csproj"); UpdatePackageReferences_iOSProject(csprojPath, interopVersion); } } catch (Exception e) { throw new CommandLineException(CommandLineErrorCode.NewProject_SetNativeReferencesFailed, e); } }
public static CheckForUpdatesResponse CheckForUpdates(bool verbose = false) { try { CheckForUpdatesResponse response; AppUsageData data = AppSettings.Default.UsageData; data.Reload(); if (data.LastCheckedForUpdates.GetValueOrDefault() < DateTime.Now.AddHours(-1)) { response = WebApiClient.CheckForUpdates(AppSettings.Default.SdkTable.Revision); if (!string.IsNullOrEmpty(response.NewSdkTable) && SerDes.TryXmlStringToObject(response.NewSdkTable, out SdkTable table)) { SerDes.ObjectToXmlFile(table, AppSettings.Default.SdkTableCurrentPath); AppSettings.Default.SdkTable = table; } data.LastCheckedForUpdates = DateTime.Now; data.UpToDate = response.UpToDate; data.NewVersion = response.NewVersion; data.DownloadUrl = response.DownloadUrl; data.Save(); } else { // prevent new Flutnet installations to report // old server responses if (!data.UpToDate && !string.IsNullOrEmpty(data.NewVersion)) { string productVersion = Assembly.GetEntryAssembly().GetProductVersion(); int compare = VersionUtils.Compare(productVersion, data.NewVersion); if (compare >= 0) { data.UpToDate = true; data.Save(); } } response = new CheckForUpdatesResponse { UpToDate = data.UpToDate, NewVersion = data.NewVersion, DownloadUrl = data.DownloadUrl }; } return(response); } catch (Exception ex) { Log.Ex(ex); Console.WriteLine(ex); throw; } }
public override int Compare(SdkFlutterVersion x, SdkFlutterVersion y) { if (x == null && y == null) { return(0); } if (x == null) { return(-1); } if (y == null) { return(1); } return(VersionUtils.Compare(x.Version, y.Version)); }
/// <summary> /// Returns true if the specified version is known to be incompatible /// from list in KnownSaveIncompatibilityPoints /// </summary> /// <param name="saveVersion">The save's version to check</param> /// <returns>True if certainly incompatible</returns> public static bool IsKnownIncompatible(string saveVersion) { int currentVersionPlaceInList = -1; int savePlaceInList = -1; var current = Constants.Version; for (int i = 0; i < KnownSaveIncompatibilityPoints.Count; ++i) { var version = KnownSaveIncompatibilityPoints[i]; bool anyMatched = false; var currentDifference = VersionUtils.Compare(current, version); var saveDifference = VersionUtils.Compare(saveVersion, version); if (currentDifference >= 0) { anyMatched = true; currentVersionPlaceInList = i; } if (saveDifference >= 0) { anyMatched = true; savePlaceInList = i; } if (!anyMatched) { break; } } // If the current version and the save version don't fit in the same place in the save breakage points list // the save is either older or newer than the closes save breakage point to the current version. // Basically if numbers don't match, we know that the save is incompatible. return(currentVersionPlaceInList != savePlaceInList); }
public static CompatibilityResult CheckCompatibility(bool verbose = false) { try { string productVersion = Assembly.GetEntryAssembly().GetProductVersion(); FlutterVersion flutterVersion = FlutterTools.GetVersion(verbose); SdkVersion sdk = AppSettings.Default.SdkTable.Versions.First(v => v.Version == productVersion); sdk.Compatibility.Sort(new SdkFlutterVersionComparer()); bool supported = false; // Indicates whether this SDK explicitly supports the installed Flutter version SdkFlutterVersion prev = null; // The last supported Flutter version that precedes the installed one (can be NULL) SdkFlutterVersion next = null; // The first supported Flutter version that follows the installed one (can be NULL) SdkFlutterVersion latest = null; // The latest supported Flutter version for (int i = 0; i < sdk.Compatibility.Count; i++) { SdkFlutterVersion fv = sdk.Compatibility[i]; int compare = VersionUtils.Compare(fv.Version, flutterVersion.Version); if (compare == 0) { supported = true; break; } if (compare < 0) { prev = fv; } else if (next == null) { next = fv; } if (i == sdk.Compatibility.Count - 1) { latest = fv; } } FlutterCompatibility compatibility; if (supported) { compatibility = FlutterCompatibility.Supported; } else if (prev != null) { compatibility = FlutterCompatibility.SupportNotGuaranteed; } else { compatibility = FlutterCompatibility.NotSupported; } CompatibilityResult result = new CompatibilityResult { Compatibility = compatibility, InstalledVersion = flutterVersion, NextSupportedVersion = next?.Version, LatestSupportedVersion = latest?.Version }; return(result); } catch (Exception ex) { Log.Ex(ex); Console.WriteLine(ex); throw; } }