48 lines
1.5 KiB
C#
48 lines
1.5 KiB
C#
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";
|
|
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 new FileInfo(StringUtils.GetProcessPathFromCommand(path)).Directory.FullName;
|
|
default: return null;
|
|
}
|
|
}
|
|
}
|
|
}
|