mirror of
https://github.com/whoswhip/RhythiaReplayExporter.git
synced 2026-12-04 07:08:42 +00:00
77 lines
2.5 KiB
C#
77 lines
2.5 KiB
C#
using System.Globalization;
|
|
using System.Runtime.InteropServices;
|
|
using Microsoft.Data.Sqlite;
|
|
|
|
namespace RhythiaReplayExporter;
|
|
|
|
class Program
|
|
{
|
|
static void Main(string[] args)
|
|
{
|
|
string appData;
|
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
|
appData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
|
|
else
|
|
appData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
|
|
if (string.IsNullOrWhiteSpace(appData))
|
|
{
|
|
Console.WriteLine("Failed to find app data folder.");
|
|
Environment.Exit(1);
|
|
return;
|
|
}
|
|
|
|
string rhythia = Path.Combine(appData, "CapoRhythia");
|
|
if (!Directory.Exists(rhythia))
|
|
{
|
|
rhythia = Path.Combine(appData, "Rhythia");
|
|
if (!Directory.Exists(rhythia))
|
|
{
|
|
Console.WriteLine("Neither CapoRhythia or Rhythia exists in app data.");
|
|
Environment.Exit(1);
|
|
return;
|
|
}
|
|
}
|
|
|
|
string database = Path.Combine(rhythia, "rhythia.db");
|
|
if (!File.Exists(database))
|
|
{
|
|
Console.WriteLine("Rhythia user database doesn't exist.");
|
|
Environment.Exit(1);
|
|
return;
|
|
}
|
|
|
|
string workingDir = Environment.CurrentDirectory;
|
|
string replaysDir = Path.Combine(workingDir, "replays");
|
|
if (args.Length > 0)
|
|
replaysDir = args[0];
|
|
|
|
Directory.CreateDirectory(replaysDir);
|
|
|
|
using SqliteConnection con = new($"Data Source={database}");
|
|
con.Open();
|
|
|
|
using SqliteCommand comm = con.CreateCommand();
|
|
comm.CommandText = "SELECT CreatedAt, LegacyMapId, Replay FROM Scores;";
|
|
using var reader = comm.ExecuteReader();
|
|
|
|
int count = 0;
|
|
while (reader.Read())
|
|
{
|
|
DateTime createdAt = DateTime.ParseExact(
|
|
reader.GetString(0),
|
|
"yyyy-MM-dd HH:mm:ss.FFFFFFF",
|
|
CultureInfo.InvariantCulture
|
|
);
|
|
string legacyMapId = reader.GetString(1);
|
|
byte[] replay = reader.GetFieldValue<byte[]>(2);
|
|
|
|
string filename = $"{createdAt:yyyy-MM-dd-HHmmss}-{legacyMapId.Replace(" ", "_")}.rhr";
|
|
string path = Path.Combine(replaysDir, filename);
|
|
File.WriteAllBytes(path, replay);
|
|
Console.WriteLine($"Wrote {filename} to {path}");
|
|
count++;
|
|
}
|
|
Console.WriteLine($"Exported {count} replays to {replaysDir}");
|
|
}
|
|
}
|