This commit is contained in:
Theenoro 2022-05-12 00:35:22 +02:00
parent 371b625fed
commit b5b8b4f117
9 changed files with 572 additions and 0 deletions

16
BeatSaber-Versions.csproj Normal file
View File

@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<RootNamespace>BeatSaber_Versions</RootNamespace>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="YamlDotNet" Version="11.2.1" />
</ItemGroup>
</Project>

30
BeatSaber-Versions.sln Normal file
View File

@ -0,0 +1,30 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.32112.339
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BeatSaber-Versions", "BeatSaber-Versions.csproj", "{92403BEE-848E-4C1D-9629-AE45CFE516C6}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{D699286A-E227-419D-B679-C06476A92A01}"
ProjectSection(SolutionItems) = preProject
config.yaml = config.yaml
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{92403BEE-848E-4C1D-9629-AE45CFE516C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{92403BEE-848E-4C1D-9629-AE45CFE516C6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{92403BEE-848E-4C1D-9629-AE45CFE516C6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{92403BEE-848E-4C1D-9629-AE45CFE516C6}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {FB96C177-79F2-4B97-8A56-26C1763D0B30}
EndGlobalSection
EndGlobal

17
Program.cs Normal file
View File

@ -0,0 +1,17 @@
namespace BeatSaber_Versions
{
internal static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.Run(new VersionChanger());
}
}
}

237
VersionChanger.Designer.cs generated Normal file
View File

@ -0,0 +1,237 @@
namespace BeatSaber_Versions
{
partial class VersionChanger
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.menuStrip1 = new System.Windows.Forms.MenuStrip();
this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
this.panel1 = new System.Windows.Forms.Panel();
this.playSelected = new System.Windows.Forms.Button();
this.versionListBox = new System.Windows.Forms.ListBox();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.folderPath = new System.Windows.Forms.TextBox();
this.versionVersion = new System.Windows.Forms.TextBox();
this.setFolder = new System.Windows.Forms.Button();
this.label2 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.selectFolderForVersion = new System.Windows.Forms.FolderBrowserDialog();
this.button2 = new System.Windows.Forms.Button();
this.versionName = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.saveSetting = new System.Windows.Forms.Button();
this.menuStrip1.SuspendLayout();
this.panel1.SuspendLayout();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// menuStrip1
//
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.toolStripMenuItem1});
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
this.menuStrip1.Name = "menuStrip1";
this.menuStrip1.Size = new System.Drawing.Size(1008, 24);
this.menuStrip1.TabIndex = 0;
this.menuStrip1.Text = "menuStrip1";
//
// toolStripMenuItem1
//
this.toolStripMenuItem1.Name = "toolStripMenuItem1";
this.toolStripMenuItem1.Size = new System.Drawing.Size(125, 20);
this.toolStripMenuItem1.Text = "toolStripMenuItem1";
//
// panel1
//
this.panel1.Controls.Add(this.button2);
this.panel1.Controls.Add(this.playSelected);
this.panel1.Location = new System.Drawing.Point(0, 27);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(1008, 36);
this.panel1.TabIndex = 1;
//
// playSelected
//
this.playSelected.Location = new System.Drawing.Point(908, 10);
this.playSelected.Name = "playSelected";
this.playSelected.Size = new System.Drawing.Size(96, 23);
this.playSelected.TabIndex = 3;
this.playSelected.Text = "Play Selected";
this.playSelected.UseVisualStyleBackColor = true;
this.playSelected.Click += new System.EventHandler(this.playSelected_Click);
//
// versionListBox
//
this.versionListBox.FormattingEnabled = true;
this.versionListBox.ItemHeight = 15;
this.versionListBox.Location = new System.Drawing.Point(2, 66);
this.versionListBox.Name = "versionListBox";
this.versionListBox.Size = new System.Drawing.Size(164, 454);
this.versionListBox.TabIndex = 2;
this.versionListBox.SelectedIndexChanged += new System.EventHandler(this.versionListBox_SelectedIndexChanged);
//
// groupBox1
//
this.groupBox1.Controls.Add(this.saveSetting);
this.groupBox1.Controls.Add(this.label3);
this.groupBox1.Controls.Add(this.versionName);
this.groupBox1.Controls.Add(this.folderPath);
this.groupBox1.Controls.Add(this.versionVersion);
this.groupBox1.Controls.Add(this.setFolder);
this.groupBox1.Controls.Add(this.label2);
this.groupBox1.Controls.Add(this.label1);
this.groupBox1.Location = new System.Drawing.Point(167, 66);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(838, 454);
this.groupBox1.TabIndex = 3;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "groupBox1";
//
// folderPath
//
this.folderPath.Location = new System.Drawing.Point(132, 79);
this.folderPath.Name = "folderPath";
this.folderPath.Size = new System.Drawing.Size(603, 23);
this.folderPath.TabIndex = 4;
//
// versionVersion
//
this.versionVersion.Location = new System.Drawing.Point(132, 51);
this.versionVersion.Name = "versionVersion";
this.versionVersion.Size = new System.Drawing.Size(603, 23);
this.versionVersion.TabIndex = 3;
//
// setFolder
//
this.setFolder.Location = new System.Drawing.Point(741, 79);
this.setFolder.Name = "setFolder";
this.setFolder.Size = new System.Drawing.Size(75, 23);
this.setFolder.TabIndex = 2;
this.setFolder.Text = "Set Folder";
this.setFolder.UseVisualStyleBackColor = true;
this.setFolder.Click += new System.EventHandler(this.setFolder_Click);
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(18, 82);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(40, 15);
this.label2.TabIndex = 1;
this.label2.Text = "Folder";
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(18, 54);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(45, 15);
this.label1.TabIndex = 0;
this.label1.Text = "Version";
//
// selectFolderForVersion
//
this.selectFolderForVersion.HelpRequest += new System.EventHandler(this.folderBrowserDialog1_HelpRequest);
//
// button2
//
this.button2.Location = new System.Drawing.Point(3, 10);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(87, 23);
this.button2.TabIndex = 4;
this.button2.Text = "Add Version";
this.button2.UseVisualStyleBackColor = true;
//
// versionName
//
this.versionName.Location = new System.Drawing.Point(132, 22);
this.versionName.Name = "versionName";
this.versionName.Size = new System.Drawing.Size(603, 23);
this.versionName.TabIndex = 5;
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(18, 25);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(39, 15);
this.label3.TabIndex = 6;
this.label3.Text = "Name";
//
// saveSetting
//
this.saveSetting.Location = new System.Drawing.Point(741, 108);
this.saveSetting.Name = "saveSetting";
this.saveSetting.Size = new System.Drawing.Size(75, 23);
this.saveSetting.TabIndex = 7;
this.saveSetting.Text = "Save";
this.saveSetting.UseVisualStyleBackColor = true;
this.saveSetting.Click += new System.EventHandler(this.saveSetting_Click);
//
// VersionChanger
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1008, 525);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.versionListBox);
this.Controls.Add(this.panel1);
this.Controls.Add(this.menuStrip1);
this.MainMenuStrip = this.menuStrip1;
this.Name = "VersionChanger";
this.Text = "Form1";
this.menuStrip1.ResumeLayout(false);
this.menuStrip1.PerformLayout();
this.panel1.ResumeLayout(false);
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private MenuStrip menuStrip1;
private ToolStripMenuItem toolStripMenuItem1;
private Panel panel1;
private Button playSelected;
private ListBox gameVersions;
private ListBox versionListBox;
private GroupBox groupBox1;
private TextBox folderPath;
private TextBox versionVersion;
private Button setFolder;
private Label label2;
private Label label1;
private FolderBrowserDialog selectFolderForVersion;
private Button button2;
private Label label3;
private TextBox versionName;
private Button saveSetting;
}
}

158
VersionChanger.cs Normal file
View File

@ -0,0 +1,158 @@
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);
}
}
}

69
VersionChanger.resx Normal file
View File

@ -0,0 +1,69 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="selectFolderForVersion.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>132, 17</value>
</metadata>
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>119</value>
</metadata>
</root>

14
config.yaml Normal file
View File

@ -0,0 +1,14 @@
beatsaberfolder: C:\\Program Files (x86)\\Steam\\steamapps\\common\\BeatSaber
versions:
1.18.3:
version: 1.18.3
path: D:\\Games\\BeatSaber Online
name: Multiplayer
1.21.0:
version: 1.21.0
path: C:\\Program Files (x86)\\Steam\\steamapps\\common\\Beat Saber-Stream
name: Stream
1.22.0:
version: 1.22.0
path: C:\\Program Files (x86)\\Steam\\steamapps\\common\\Beat Saber-new
name: Stream

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BeatSaber_Versions.controller
{
internal class VersionConfig
{
public string version { get; set; }
public string name { get; set; }
public string path { get; set; }
}
}

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BeatSaber_Versions.controller
{
internal class VersionConfigDict
{
public String? beatsabersongs { get; set; }
public String? beatsaberfolder { get; set; }
public Dictionary<string,VersionConfig> versions { get; set; }
}
}