190 lines
6.1 KiB
C#
190 lines
6.1 KiB
C#
using BeatSaber_Versions.controller;
|
|
using BeatSaber_Versions.controller.helper;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Runtime.InteropServices;
|
|
using YamlDotNet.Serialization;
|
|
using YamlDotNet.Serialization.NamingConventions;
|
|
|
|
namespace BeatSaber_Versions
|
|
{
|
|
public partial class VersionChanger : Form
|
|
{
|
|
[DllImport("kernel32.dll")]
|
|
static extern bool CreateSymbolicLink(string lpSymlinkFileName,
|
|
string lpTargetFileName, int dwFlags);
|
|
|
|
private string Path = $@"{AppDomain.CurrentDomain.BaseDirectory}config.yaml";
|
|
private VersionConfigDict Versionen = null;
|
|
private String beatsaberfolder = @"A:\BS";
|
|
|
|
public VersionChanger()
|
|
{
|
|
|
|
InitializeComponent();
|
|
|
|
var deserializer = new DeserializerBuilder()
|
|
.WithNamingConvention(UnderscoredNamingConvention.Instance) // see height_in_inches in sample yml
|
|
.Build();
|
|
|
|
string yml = File.ReadAllText(Path);
|
|
var p = deserializer.Deserialize<VersionConfigDict>(yml);
|
|
|
|
Versionen = p;
|
|
beatsaberfolder = p.beatsaberfolder;
|
|
foreach (var key in (p.versions).Keys)
|
|
{
|
|
versionListBox.Items.Add(key);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
private void folderBrowserDialog1_HelpRequest(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void setFolder_Click(object sender, EventArgs e)
|
|
{
|
|
DialogResult folder = selectFolderForVersion.ShowDialog();
|
|
if(folder == DialogResult.OK)
|
|
{
|
|
MessageBox.Show("" + selectFolderForVersion.SelectedPath);
|
|
folderPath.Text = selectFolderForVersion.SelectedPath;
|
|
|
|
|
|
}
|
|
else
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
private void versionListBox_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
var Item = ((sender as ListBox).SelectedItem);
|
|
if(Item != null)
|
|
{
|
|
folderPath.Text = Versionen.versions[(String)Item].path;
|
|
versionName.Text = Versionen.versions[(String)Item].name;
|
|
versionVersion.Text = Versionen.versions[(String)Item].version;
|
|
}
|
|
}
|
|
|
|
private void playSelected_Click(object sender, EventArgs e)
|
|
{
|
|
String Target = folderPath.Text;
|
|
if (Directory.Exists(beatsaberfolder))
|
|
{
|
|
|
|
if (staticHelpers.IsSymbolic(beatsaberfolder))
|
|
{
|
|
Directory.Delete(beatsaberfolder);
|
|
if (Directory.Exists(Target))
|
|
{
|
|
CreateSymbolicLink(beatsaberfolder, Target, 0x1);
|
|
setSongFolder();
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (Directory.Exists(Target))
|
|
{
|
|
CreateSymbolicLink(beatsaberfolder, Target, 0x1);
|
|
setSongFolder();
|
|
}
|
|
}
|
|
}
|
|
private void setSongFolder()
|
|
{
|
|
String songFolderConf = Versionen.beatsabersongs;
|
|
String songFolder = beatsaberfolder+ "\\Beat Saber_Data\\CustomLevels";
|
|
if (Directory.Exists(songFolder))
|
|
{
|
|
if (staticHelpers.IsSymbolic(songFolder))
|
|
{
|
|
MessageBox.Show("Is a symbolic link <3");
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show("Is a normal folder.");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
DialogResult dialogResult = MessageBox.Show("Create symbolic link, may deduplicate your song library", "Settings", MessageBoxButtons.YesNo);
|
|
if (dialogResult == DialogResult.Yes)
|
|
{
|
|
CreateSymbolicLink(songFolder, songFolderConf, 0x1);
|
|
MessageBox.Show("Created symbolic link to song folder.");
|
|
}
|
|
else if (dialogResult == DialogResult.No)
|
|
{
|
|
//do something else
|
|
}
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
private void saveSetting_Click(object sender, EventArgs e)
|
|
{
|
|
VersionConfig tmp = new VersionConfig();
|
|
tmp.path = folderPath.Text;
|
|
tmp.name = versionName.Text;
|
|
tmp.version = versionVersion.Text;
|
|
if (Versionen.versions.ContainsKey((String)tmp.version))
|
|
{
|
|
Versionen.versions[tmp.version] = tmp;
|
|
}
|
|
else
|
|
{
|
|
Versionen.versions.Add(tmp.version,tmp);
|
|
}
|
|
|
|
versionListBox.Items.Clear();
|
|
foreach (var key in (Versionen.versions).Keys)
|
|
{
|
|
versionListBox.Items.Add(key);
|
|
}
|
|
|
|
var serializer = new SerializerBuilder()
|
|
.WithNamingConvention(CamelCaseNamingConvention.Instance)
|
|
.Build();
|
|
var yaml = serializer.Serialize(Versionen);
|
|
File.WriteAllTextAsync(Path,yaml);
|
|
System.Console.WriteLine(yaml);
|
|
}
|
|
private void addVersion(object sender,EventArgs e){
|
|
folderPath.Text = "";
|
|
versionName.Text = "";
|
|
versionVersion.Text = "";
|
|
versionListBox.ClearSelected();
|
|
}
|
|
private void deleteVersion(object sender, EventArgs e){
|
|
var Item = versionVersion.Text;
|
|
if(Item != null)
|
|
{
|
|
Versionen.versions.Remove((String)Item);
|
|
}
|
|
versionListBox.Items.Clear();
|
|
foreach (var key in (Versionen.versions).Keys)
|
|
{
|
|
versionListBox.Items.Add(key);
|
|
}
|
|
|
|
var serializer = new SerializerBuilder()
|
|
.WithNamingConvention(CamelCaseNamingConvention.Instance)
|
|
.Build();
|
|
var yaml = serializer.Serialize(Versionen);
|
|
File.WriteAllTextAsync(Path,yaml);
|
|
System.Console.WriteLine(yaml);
|
|
|
|
}
|
|
|
|
}
|
|
} |