Detects user chart path for Malody chart finder.
This commit is contained in:
@@ -1,24 +1,45 @@
|
||||
using Cryville.Common;
|
||||
using Cryville.Crtr.Browsing;
|
||||
using Microsoft.Win32;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace Cryville.Crtr.Extensions.Malody {
|
||||
public class MalodyChartFinder : LocalResourceFinder {
|
||||
public override string Name { get { return "Malody beatmaps"; } }
|
||||
|
||||
public override string GetRootPath() {
|
||||
var malodyDataPath = GetMalodyDataPath();
|
||||
var malodyConfigPath = Path.Combine(malodyDataPath, "config.json");
|
||||
if (File.Exists(malodyConfigPath)) {
|
||||
using (var reader = new StreamReader(malodyConfigPath, Encoding.UTF8)) {
|
||||
var config = JsonConvert.DeserializeObject<Dictionary<string, object>>(reader.ReadToEnd());
|
||||
object userPath;
|
||||
if (config.TryGetValue("user_chart_path", out userPath)) {
|
||||
var strUserPath = userPath as string;
|
||||
if (!string.IsNullOrEmpty(strUserPath)) {
|
||||
return strUserPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return Path.Combine(malodyDataPath, "beatmap");
|
||||
}
|
||||
|
||||
string GetMalodyDataPath() {
|
||||
switch (Environment.OSVersion.Platform) {
|
||||
case PlatformID.Unix:
|
||||
return "/storage/emulated/0/data/malody/beatmap";
|
||||
return "/storage/emulated/0/data/malody";
|
||||
case PlatformID.Win32NT:
|
||||
var reg = Registry.ClassesRoot.OpenSubKey(@"malody\Shell\Open\Command");
|
||||
if (reg == null) return null;
|
||||
var pathObj = reg.GetValue(null);
|
||||
if (pathObj == null) return null;
|
||||
var path = (string)pathObj;
|
||||
return Path.Combine(new FileInfo(StringUtils.GetProcessPathFromCommand(path)).Directory.FullName, "beatmap");
|
||||
return new FileInfo(StringUtils.GetProcessPathFromCommand(path)).Directory.FullName;
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user