Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions OpenUtau.Core/PackageManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,13 @@ public class OudepMetadata {
public string version = string.Empty;
public string description = string.Empty;
public string @class = string.Empty;

// If none of these are set, the oudep installs to DependencyPath
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public bool? isPlugin = false;
public bool? isTheme = false;
}



public class PackageManager : SingletonBase<PackageManager> {
Expand Down Expand Up @@ -180,8 +185,13 @@ public async Task InstallAsync(RegistrySoftware software, IProgress<int>? progre

public async Task UninstallAsync(string id) {
if (string.IsNullOrEmpty(id)) throw new ArgumentNullException(nameof(id));
var basePath = Path.Combine(PathManager.Inst.DependencyPath, id);
if (!Directory.Exists(basePath)) return;
var candidates = new[] {
Path.Combine(PathManager.Inst.DependencyPath, id),
Path.Combine(PathManager.Inst.PluginsPath, id),
Path.Combine(PathManager.Inst.ThemesPath, id),
};
var basePath = candidates.FirstOrDefault(Directory.Exists);
if (basePath == null) return;
try {
await Task.Run(() => Directory.Delete(basePath, true));
} catch (Exception e) {
Expand Down Expand Up @@ -215,8 +225,15 @@ public async Task InstallFromStreamAsync(Stream stream, string expectedId, strin
if (string.IsNullOrEmpty(id) && !string.IsNullOrEmpty(metadata.name)) {
id = metadata.name;
}

string ResolveBasePath() {
if (metadata.isPlugin == true) return Path.Combine(PathManager.Inst.PluginsPath, id);
if (metadata.isTheme == true) return Path.Combine(PathManager.Inst.ThemesPath, id);
return Path.Combine(PathManager.Inst.DependencyPath, id);
}
var basePath = ResolveBasePath();

await Task.Run(() => {
var basePath = Path.Combine(PathManager.Inst.DependencyPath, id);
try {
if (Directory.Exists(basePath)) {
Directory.Delete(basePath, true);
Expand All @@ -226,7 +243,6 @@ await Task.Run(() => {
}
foreach (var entry in archive.Entries) {
if (string.IsNullOrEmpty(entry.Key) || entry.Key.Contains("..")) {
// Prevent zipSlip attack
continue;
}
var filePath = Path.Combine(basePath, entry.Key);
Expand Down
Loading