Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for custom profiles and update dependencies #81

Merged
merged 1 commit into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 50 additions & 24 deletions vrcosc-magicchatbox/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,34 +35,57 @@ protected override async void OnStartup(StartupEventArgs e)
// Process command-line arguments
if (e.Args != null && e.Args.Length > 0)
{
switch (e.Args[0])
foreach (string arg in e.Args)
{
case "-update":
loadingWindow.UpdateProgress("Go, go, go! Update, update, update!", 75);
await Task.Run(() => updater.UpdateApplication());
Shutdown();
return;
case "-updateadmin":
loadingWindow.UpdateProgress("Admin style update, now that's fancy!", 85);
await Task.Run(() => updater.UpdateApplication(true));
Shutdown();
return;
case "-rollback":
loadingWindow.UpdateProgress("Oops! Let's roll back.", 50);
await Task.Run(() => updater.RollbackApplication(loadingWindow));
Shutdown();
return;
case "-clearbackup":
loadingWindow.UpdateProgress("Rolling back and clearing the slate. Fresh start!", 50);
await Task.Run(() => updater.ClearBackUp());
break;
default:
loadingWindow.Hide();
Logging.WriteException(new Exception($"Invalid command line argument '{e.Args[0]}'"), MSGBox: true, exitapp: true);
return;
if (arg.StartsWith("-profile="))
{
string profileNumberString = arg.Substring(9);
if (int.TryParse(profileNumberString, out int profileNumber))
{
ViewModel.Instance.ProfileNumber = profileNumber;
ViewModel.Instance.UseCustomProfile = true;
ViewModel.Instance.SetDataPath();
}
else
{
loadingWindow.Hide();
Logging.WriteException(new Exception($"Invalid profile number '{profileNumberString}'"), MSGBox: true, exitapp: true);
return;
}
}
else
{
switch (arg)
{
case "-update":
loadingWindow.UpdateProgress("Go, go, go! Update, update, update!", 75);
await Task.Run(() => updater.UpdateApplication());
Shutdown();
return;
case "-updateadmin":
loadingWindow.UpdateProgress("Admin style update, now that's fancy!", 85);
await Task.Run(() => updater.UpdateApplication(true));
Shutdown();
return;
case "-rollback":
loadingWindow.UpdateProgress("Oops! Let's roll back.", 50);
await Task.Run(() => updater.RollbackApplication(loadingWindow));
Shutdown();
return;
case "-clearbackup":
loadingWindow.UpdateProgress("Rolling back and clearing the slate. Fresh start!", 50);
await Task.Run(() => updater.ClearBackUp());
break;
default:
loadingWindow.Hide();
Logging.WriteException(new Exception($"Invalid command line argument '{arg}'"), MSGBox: true, exitapp: true);
return;
}
}
}
}


// Initialize various components with progress updates
await InitializeComponentsWithProgress(loadingWindow);

Expand Down Expand Up @@ -153,6 +176,9 @@ private async Task InitializeComponentsWithProgress(StartUp loadingWindow)
loadingWindow.UpdateProgress("Turbocharging MediaLink engines... Fast & Furious: Data Drift!", 95);
ApplicationMediaController = new MediaLinkModule(ViewModel.Instance.IntgrScanMediaLink);

loadingWindow.UpdateProgress("Starting the modules... Ready, set, go!", 96);
await Task.Run(() => ViewModel.Instance.StartModules());

loadingWindow.UpdateProgress("Loading MediaLink styles... Fashion show, here we come!", 98);
await Task.Run(() => DataController.LoadAndSaveMediaLinkStyles());
}
Expand Down
44 changes: 31 additions & 13 deletions vrcosc-magicchatbox/Classes/DataAndSecurity/UpdateApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,46 +26,64 @@ public class UpdateApp
private string magicChatboxExePath;
private string backupPath;

public UpdateApp()
public UpdateApp(bool createNewAppLocation = false)
{
dataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Vrcosc-MagicChatbox");
InitializePaths();
InitializePaths(createNewAppLocation);
}

private void InitializePaths()
private void InitializePaths(bool createNewAppLocation)
{
string jsonFilePath = Path.Combine(dataPath, "app_location.json");
if (File.Exists(jsonFilePath))
string actualCurrentAppPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

if (!File.Exists(jsonFilePath))
{
SetDefaultPaths();
SaveUpdateLocation();
}
else
{
var settingsJson = File.ReadAllText(jsonFilePath);

if (string.IsNullOrWhiteSpace(settingsJson) || settingsJson.All(c => c == '\0'))
{
Logging.WriteInfo("The app_location.json file is empty or corrupted.");
SetDefaultPaths();
SaveUpdateLocation();
}
else
{
try
{
JObject appLocation = JObject.Parse(settingsJson);
currentAppPath = appLocation["currentAppPath"].ToString();
tempPath = appLocation["tempPath"].ToString();
unzipPath = appLocation["unzipPath"].ToString();
magicChatboxExePath = appLocation["magicChatboxExePath"].ToString();
backupPath = Path.Combine(dataPath, "backup");

// Check if the current app path matches the actual current app path
if (createNewAppLocation || !string.Equals(currentAppPath, actualCurrentAppPath, StringComparison.OrdinalIgnoreCase))
{
// The app has been moved to a new location
Logging.WriteInfo("The application has been moved. Updating app_location.json.");
SetDefaultPaths();
SaveUpdateLocation();
}
else
{
// Existing code to set paths from app_location.json
tempPath = appLocation["tempPath"].ToString();
unzipPath = appLocation["unzipPath"].ToString();
magicChatboxExePath = appLocation["magicChatboxExePath"].ToString();
backupPath = Path.Combine(dataPath, "backup");
}
}
catch (Newtonsoft.Json.JsonReaderException ex)
{
Logging.WriteInfo($"Error parsing app_location.json: {ex.Message}");
SetDefaultPaths();
SaveUpdateLocation();
}
}
}
else
{
SetDefaultPaths();
}

if (!Directory.Exists(tempPath))
{
Expand Down Expand Up @@ -417,7 +435,7 @@ public void ClearBackUp()
private void SaveUpdateLocation(string backupPath = null)
{
JObject appLocation = new JObject(
new JProperty("currentAppPath", Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)),
new JProperty("currentAppPath", currentAppPath),
new JProperty("tempPath", tempPath),
new JProperty("unzipPath", unzipPath),
new JProperty("magicChatboxExePath", magicChatboxExePath)
Expand Down
2 changes: 1 addition & 1 deletion vrcosc-magicchatbox/Classes/Modules/AfkModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ partial void OnAfkTimeoutChanged(int value)
}

private const string SettingsFileName = "AfkModuleSettings.json";
private static readonly string SettingsPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Vrcosc-MagicChatbox", SettingsFileName);
private static readonly string SettingsPath = Path.Combine(ViewModel.Instance.DataPath, SettingsFileName);

[ObservableProperty]
private int afkTimeout = 120;
Expand Down
2 changes: 1 addition & 1 deletion vrcosc-magicchatbox/Classes/Modules/PulsoidModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public void SaveSettings()

public static string GetFullSettingsPath()
{
return Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Vrcosc-MagicChatbox"), SettingsFileName);
return Path.Combine(ViewModel.Instance.DataPath, SettingsFileName);
}

public static PulsoidModuleSettings LoadSettings()
Expand Down
4 changes: 2 additions & 2 deletions vrcosc-magicchatbox/MagicChatbox.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>WinExe</OutputType>
<Version>0.9.040</Version>
<Version>0.9.039</Version>
<TargetFramework>net8.0-windows10.0.22000.0</TargetFramework>
<RootNamespace>vrcosc_magicchatbox</RootNamespace>
<Nullable>enable</Nullable>
Expand Down Expand Up @@ -192,7 +192,7 @@
<ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
<PackageReference Include="Dubya.WindowsMediaController" Version="2.5.5" />
<PackageReference Include="LibreHardwareMonitorLib" Version="0.9.4-pre351" />
<PackageReference Include="LibreHardwareMonitorLib" Version="0.9.4-pre353" />
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.135" />
<PackageReference Include="NAudio" Version="2.2.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
Expand Down
25 changes: 22 additions & 3 deletions vrcosc-magicchatbox/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -681,11 +681,18 @@ private void NewFavText_TextChanged(object sender, TextChangedEventArgs e)

private void NewVersion_MouseUp(object sender, MouseButtonEventArgs e)
{
if(ViewModel.Instance.UseCustomProfile)
{
Logging.WriteException(new Exception("Cannot update while using a custom profile."), MSGBox: true);
return;
}


if (ViewModel.Instance.CanUpdate)
{
ViewModel.Instance.CanUpdate = false;
ViewModel.Instance.CanUpdateLabel = false;
UpdateApp updateApp = new UpdateApp();
UpdateApp updateApp = new UpdateApp(true);
Task.Run(() => updateApp.PrepareUpdate());
}
else
Expand Down Expand Up @@ -1559,7 +1566,13 @@ private bool IsRunAsAdmin()

private void UpdateByZipFile_Click(object sender, RoutedEventArgs e)
{
UpdateApp updateApp = new UpdateApp();
if (ViewModel.Instance.UseCustomProfile)
{
Logging.WriteException(new Exception("Cannot update by zip while using a custom profile."), MSGBox: true);
return;
}

UpdateApp updateApp = new UpdateApp(true);
updateApp.SelectCustomZip();
}

Expand Down Expand Up @@ -1633,7 +1646,13 @@ private void StopRecord_Click(object sender, RoutedEventArgs e)

private void Rollback_Click(object sender, RoutedEventArgs e)
{
UpdateApp updateApp = new UpdateApp();
if (ViewModel.Instance.UseCustomProfile)
{
Logging.WriteException(new Exception("Cannot rollback while using a custom profile."), MSGBox: true);
return;
}

UpdateApp updateApp = new UpdateApp(true);
updateApp.StartRollback();
}

Expand Down
4 changes: 4 additions & 0 deletions vrcosc-magicchatbox/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
},
"Normal": {
"commandName": "Project"
},
"Profile 1": {
"commandName": "Project",
"commandLineArgs": "-profile=1"
}
}
}
6 changes: 3 additions & 3 deletions vrcosc-magicchatbox/UI/Dialogs/ApplicationError.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private void OpenLogFolder_Click(object sender, RoutedEventArgs e)

private void Update_Click(object sender, RoutedEventArgs e)
{
UpdateApp updater = new UpdateApp();
UpdateApp updater = new UpdateApp(true);
updater.SelectCustomZip();
}

Expand All @@ -70,7 +70,7 @@ private void NewVersion_MouseUp(object sender, System.Windows.Input.MouseButtonE
{
ViewModel.Instance.CanUpdate = false;
ViewModel.Instance.CanUpdateLabel = false;
UpdateApp updateApp = new UpdateApp();
UpdateApp updateApp = new UpdateApp(true);
Task.Run(() => updateApp.PrepareUpdate());
}
else
Expand All @@ -91,7 +91,7 @@ private async Task ManualUpdateCheckAsync()

private void rollback_Click(object sender, RoutedEventArgs e)
{
UpdateApp updater = new UpdateApp();
UpdateApp updater = new UpdateApp(true);
updater.StartRollback();
}
}
Expand Down
49 changes: 42 additions & 7 deletions vrcosc-magicchatbox/ViewModels/ViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -325,13 +325,6 @@ public ViewModel()
{ nameof(Settings_Status), value => Settings_Status = value }
};

HeartRateConnector = new PulsoidModule();
SoundpadModule = new(1000);


PropertyChanged += HeartRateConnector.PropertyChangedHandler;
PropertyChanged += SoundpadModule.PropertyChangedHandler;

ShuffleEmojis();
CurrentEmoji = GetNextEmoji();
}
Expand All @@ -341,6 +334,16 @@ private void ProcessInfo_PropertyChanged(object sender, PropertyChangedEventArgs
Resort();
}

public void StartModules()
{
HeartRateConnector = new PulsoidModule();
SoundpadModule = new(1000);


PropertyChanged += HeartRateConnector.PropertyChangedHandler;
PropertyChanged += SoundpadModule.PropertyChangedHandler;
}



private void Resort()
Expand Down Expand Up @@ -2186,6 +2189,16 @@ public int OSCPOrtIN
}
}

public void SetDataPath()
{
if(UseCustomProfile)
{
DataPath = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
$"Vrcosc-MagicChatbox-profile-{ProfileNumber}");
}
}

private string _DataPath = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
"Vrcosc-MagicChatbox");
Expand Down Expand Up @@ -4167,6 +4180,28 @@ public string GetNextEmoji()
return CurrentEmoji = _shuffledEmojis.Dequeue();
}

private int _profileNumber;
public int ProfileNumber
{
get => _profileNumber;
set
{
_profileNumber = value;
NotifyPropertyChanged(nameof(ProfileNumber));
}
}

private bool _useCustomProfile;
public bool UseCustomProfile
{
get => _useCustomProfile;
set
{
_useCustomProfile = value;
NotifyPropertyChanged(nameof(UseCustomProfile));
}
}

#endregion

#region PropChangedEvent
Expand Down
Loading