182 lines
5.9 KiB
C#
182 lines
5.9 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 = Storage.Config;
|
|
private String beatsaberfolder = @"A:\BS";
|
|
|
|
public VersionChanger()
|
|
{
|
|
|
|
InitializeComponent();
|
|
|
|
VersionConfigDict Versionen = Storage.Config;
|
|
beatsaberfolder = Versionen.beatsaberfolder;
|
|
foreach (var key in (Versionen.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(Storage.Config.beatsaberfolder))
|
|
{
|
|
|
|
if (staticHelpers.IsSymbolic(Storage.Config.beatsaberfolder))
|
|
{
|
|
Directory.Delete(Storage.Config.beatsaberfolder);
|
|
if (Directory.Exists(Target))
|
|
{
|
|
CreateSymbolicLink(Storage.Config.beatsaberfolder, Target, 0x1);
|
|
setSongFolder();
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (Directory.Exists(Target))
|
|
{
|
|
CreateSymbolicLink(Storage.Config.beatsaberfolder, Target, 0x1);
|
|
setSongFolder();
|
|
}
|
|
}
|
|
}
|
|
private void setSongFolder()
|
|
{
|
|
String songFolderConf = Storage.Config.beatsabersongs;
|
|
if (songFolderConf != "") {
|
|
String songFolder = Storage.Config.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)
|
|
{
|
|
|
|
Versionen = Storage.Config;
|
|
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);
|
|
}
|
|
Storage.Config = Versionen;
|
|
Storage.CC.writeConfig();
|
|
}
|
|
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;
|
|
Versionen = Storage.Config;
|
|
if(Item != null)
|
|
{
|
|
Versionen.versions.Remove((String)Item);
|
|
}
|
|
versionListBox.Items.Clear();
|
|
foreach (var key in (Versionen.versions).Keys)
|
|
{
|
|
versionListBox.Items.Add(key);
|
|
}
|
|
|
|
Storage.Config = Versionen;
|
|
Storage.CC.writeConfig();
|
|
|
|
}
|
|
|
|
private void settingBSFolder_Click(object sender, EventArgs e)
|
|
{
|
|
BeatSaberFolders_Modal mod = new BeatSaberFolders_Modal();
|
|
mod.Show();
|
|
}
|
|
}
|
|
} |