BeatSaber-version-changer/ui/VersionChanger.cs

182 lines
5.9 KiB
C#
Raw Normal View History

2022-05-12 00:35:22 +02:00
using BeatSaber_Versions.controller;
2022-05-14 19:00:01 +02:00
using BeatSaber_Versions.controller.helper;
2022-05-12 00:35:22 +02:00
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";
2022-05-15 03:02:51 +02:00
private VersionConfigDict Versionen = Storage.Config;
2022-05-12 00:35:22 +02:00
private String beatsaberfolder = @"A:\BS";
public VersionChanger()
{
InitializeComponent();
2022-05-15 03:02:51 +02:00
VersionConfigDict Versionen = Storage.Config;
beatsaberfolder = Versionen.beatsaberfolder;
foreach (var key in (Versionen.versions).Keys)
2022-05-12 00:35:22 +02:00
{
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;
2022-05-15 03:02:51 +02:00
if (Directory.Exists(Storage.Config.beatsaberfolder))
2022-05-12 00:35:22 +02:00
{
2022-05-14 19:00:01 +02:00
2022-05-15 03:02:51 +02:00
if (staticHelpers.IsSymbolic(Storage.Config.beatsaberfolder))
2022-05-12 00:35:22 +02:00
{
2022-05-15 03:02:51 +02:00
Directory.Delete(Storage.Config.beatsaberfolder);
2022-05-12 00:35:22 +02:00
if (Directory.Exists(Target))
{
2022-05-15 03:02:51 +02:00
CreateSymbolicLink(Storage.Config.beatsaberfolder, Target, 0x1);
2022-05-12 00:35:22 +02:00
setSongFolder();
}
}
}
else
{
if (Directory.Exists(Target))
{
2022-05-15 03:02:51 +02:00
CreateSymbolicLink(Storage.Config.beatsaberfolder, Target, 0x1);
2022-05-12 00:35:22 +02:00
setSongFolder();
}
}
}
private void setSongFolder()
{
2022-05-15 03:02:51 +02:00
String songFolderConf = Storage.Config.beatsabersongs;
if (songFolderConf != "") {
String songFolder = Storage.Config.beatsaberfolder + "\\Beat Saber_Data\\CustomLevels";
if (Directory.Exists(songFolder))
2022-05-12 00:35:22 +02:00
{
2022-05-15 03:02:51 +02:00
if (staticHelpers.IsSymbolic(songFolder))
{
MessageBox.Show("Is a symbolic link <3");
}
else
{
MessageBox.Show("Is a normal folder.");
}
2022-05-12 00:35:22 +02:00
}
else
{
2022-05-15 03:02:51 +02:00
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
}
2022-05-12 00:35:22 +02:00
}
}
}
private void saveSetting_Click(object sender, EventArgs e)
{
2022-05-15 03:02:51 +02:00
Versionen = Storage.Config;
2022-05-12 00:35:22 +02:00
VersionConfig tmp = new VersionConfig();
tmp.path = folderPath.Text;
tmp.name = versionName.Text;
tmp.version = versionVersion.Text;
if (Versionen.versions.ContainsKey((String)tmp.version))
{
2022-05-14 19:00:01 +02:00
Versionen.versions[tmp.version] = tmp;
2022-05-12 00:35:22 +02:00
}
else
{
2022-05-14 19:00:01 +02:00
Versionen.versions.Add(tmp.version,tmp);
}
2022-05-12 00:35:22 +02:00
2022-05-14 19:00:01 +02:00
versionListBox.Items.Clear();
foreach (var key in (Versionen.versions).Keys)
{
versionListBox.Items.Add(key);
2022-05-12 00:35:22 +02:00
}
2022-05-15 03:02:51 +02:00
Storage.Config = Versionen;
Storage.CC.writeConfig();
2022-05-12 00:35:22 +02:00
}
2022-05-14 19:00:01 +02:00
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;
2022-05-15 03:02:51 +02:00
Versionen = Storage.Config;
2022-05-14 19:00:01 +02:00
if(Item != null)
{
Versionen.versions.Remove((String)Item);
}
versionListBox.Items.Clear();
foreach (var key in (Versionen.versions).Keys)
{
versionListBox.Items.Add(key);
}
2022-05-12 00:35:22 +02:00
2022-05-15 03:02:51 +02:00
Storage.Config = Versionen;
Storage.CC.writeConfig();
2022-05-12 00:35:22 +02:00
}
2022-05-14 19:00:01 +02:00
private void settingBSFolder_Click(object sender, EventArgs e)
{
BeatSaberFolders_Modal mod = new BeatSaberFolders_Modal();
mod.Show();
}
2022-05-12 00:35:22 +02:00
}
}