Skip to content

Commit

Permalink
Merge pull request #433 from ionite34/fix-invoke-update
Browse files Browse the repository at this point in the history
Fix invoke update & settings not saving when 0 bytes
  • Loading branch information
mohnjiles authored Dec 28, 2023
2 parents 56ca83d + 8f8f85c commit a054e81
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning 2.0](https://semver.org/spec/v2
### Fixed
- Fixed Python Packages dialog crash due to pip commands including warnings
- Fixed Base Model downloads from the Hugging Face tab downloading to the wrong folder
- Fixed InvokeAI `! [rejected] v3.4.0post2 -> v3.4.0post2 (would clobber existing tag)` error on updating to the latest version
- Fixed settings not saving in some scenarios, such as when the `settings.json` file existed but was empty

## v2.7.5
### Fixed
Expand Down
4 changes: 2 additions & 2 deletions StabilityMatrix.Core/Models/Packages/BaseGitPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ await PrerequisiteHelper
{
progress?.Report(new ProgressReport(-1f, "Fetching tags...", isIndeterminate: true));
await PrerequisiteHelper
.RunGit(new[] { "fetch", "--tags" }, onConsoleOutput, installedPackage.FullPath)
.RunGit(new[] { "fetch", "--tags", "--force" }, onConsoleOutput, installedPackage.FullPath)
.ConfigureAwait(false);

progress?.Report(
Expand Down Expand Up @@ -353,7 +353,7 @@ await InstallPackage(
// fetch
progress?.Report(new ProgressReport(-1f, "Fetching data...", isIndeterminate: true));
await PrerequisiteHelper
.RunGit("fetch", onConsoleOutput, installedPackage.FullPath)
.RunGit(new[] { "fetch", "--force" }, onConsoleOutput, installedPackage.FullPath)
.ConfigureAwait(false);

if (versionOptions.IsLatest)
Expand Down
31 changes: 24 additions & 7 deletions StabilityMatrix.Core/Services/SettingsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ public void Transaction<TValue>(Expression<Func<Settings, TValue>> expression, T
{
if (expression.Body is not MemberExpression memberExpression)
{
throw new ArgumentException($"Expression must be a member expression, not {expression.Body.NodeType}");
throw new ArgumentException(
$"Expression must be a member expression, not {expression.Body.NodeType}"
);
}

var propertyInfo = memberExpression.Member as PropertyInfo;
Expand Down Expand Up @@ -226,7 +228,10 @@ public void RelayPropertyFor<T, TValue>(
}

// Invoke property changed event, passing along sender
SettingsPropertyChanged?.Invoke(sender, new RelayPropertyChangedEventArgs(targetPropertyName, true));
SettingsPropertyChanged?.Invoke(
sender,
new RelayPropertyChangedEventArgs(targetPropertyName, true)
);
};

// Set initial value if requested
Expand Down Expand Up @@ -331,7 +336,10 @@ public void SetLibraryPath(string path)
var libraryJsonFile = Compat.AppDataHome.JoinFile("library.json");

var library = new LibrarySettings { LibraryPath = path };
var libraryJson = JsonSerializer.Serialize(library, new JsonSerializerOptions { WriteIndented = true });
var libraryJson = JsonSerializer.Serialize(
library,
new JsonSerializerOptions { WriteIndented = true }
);
libraryJsonFile.WriteAllText(libraryJson);

// actually create the LibraryPath directory
Expand Down Expand Up @@ -481,7 +489,9 @@ public void SaveLaunchArgs(Guid packageId, List<LaunchOption> launchArgs)

public string? GetActivePackageHost()
{
var package = Settings.InstalledPackages.FirstOrDefault(x => x.Id == Settings.ActiveInstalledPackageId);
var package = Settings.InstalledPackages.FirstOrDefault(
x => x.Id == Settings.ActiveInstalledPackageId
);
if (package == null)
return null;
var hostOption = package.LaunchArgs?.FirstOrDefault(x => x.Name.ToLowerInvariant() == "host");
Expand All @@ -494,7 +504,9 @@ public void SaveLaunchArgs(Guid packageId, List<LaunchOption> launchArgs)

public string? GetActivePackagePort()
{
var package = Settings.InstalledPackages.FirstOrDefault(x => x.Id == Settings.ActiveInstalledPackageId);
var package = Settings.InstalledPackages.FirstOrDefault(
x => x.Id == Settings.ActiveInstalledPackageId
);
if (package == null)
return null;
var portOption = package.LaunchArgs?.FirstOrDefault(x => x.Name.ToLowerInvariant() == "port");
Expand Down Expand Up @@ -615,11 +627,13 @@ protected virtual void LoadSettings()
if (fileStream.Length == 0)
{
Logger.Warn("Settings file is empty, using default settings");
isLoaded = true;
return;
}

if (
JsonSerializer.Deserialize(fileStream, SettingsSerializerContext.Default.Settings) is { } loadedSettings
JsonSerializer.Deserialize(fileStream, SettingsSerializerContext.Default.Settings) is
{ } loadedSettings
)
{
Settings = loadedSettings;
Expand Down Expand Up @@ -656,7 +670,10 @@ protected virtual void SaveSettings()
return;
}

var jsonBytes = JsonSerializer.SerializeToUtf8Bytes(Settings, SettingsSerializerContext.Default.Settings);
var jsonBytes = JsonSerializer.SerializeToUtf8Bytes(
Settings,
SettingsSerializerContext.Default.Settings
);

File.WriteAllBytes(SettingsPath, jsonBytes);
}
Expand Down

0 comments on commit a054e81

Please sign in to comment.