158 lines
4.7 KiB
C#
158 lines
4.7 KiB
C#
using BeatSaber_Versions.controller;
|
|
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 (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 (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))
|
|
{
|
|
|
|
}
|
|
else
|
|
{
|
|
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* Helper
|
|
*/
|
|
private bool IsSymbolic(string path)
|
|
{
|
|
FileInfo pathInfo = new FileInfo(path);
|
|
return pathInfo.Attributes.HasFlag(FileAttributes.ReparsePoint);
|
|
}
|
|
}
|
|
} |