Skip to content

Commit

Permalink
Copy default bindings too
Browse files Browse the repository at this point in the history
  • Loading branch information
KimihikoAkayasaki committed Nov 10, 2024
1 parent 21aecad commit c71c0bf
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 11 deletions.
41 changes: 31 additions & 10 deletions plugin_OpenVR/EvrInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Newtonsoft.Json;
using plugin_OpenVR.Utils;
using Valve.VR;
using Windows.Storage;

namespace plugin_OpenVR;

Expand Down Expand Up @@ -263,22 +264,42 @@ private static (uint Left, uint Right) VrControllerIndexes => (

public void SaveSettings()
{
var manifestPath = Path.Join(PackageUtils.GetAmethystAppDataPath(), "Amethyst", "actions.json");
File.WriteAllText(manifestPath, JsonConvert.SerializeObject(RegisteredActions, Formatting.Indented));
try
{
var manifestPath = Path.Join(PackageUtils.GetAmethystAppDataPath(), "Amethyst", "action_manifest.json");
File.WriteAllText(manifestPath, JsonConvert.SerializeObject(RegisteredActions, Formatting.Indented));

Directory.CreateDirectory(Path.Join(PackageUtils.GetAmethystAppDataPath(), "Amethyst", "input_profiles"));
new DirectoryInfo(Path.Join(Directory.GetParent(Assembly.GetExecutingAssembly().Location)!.FullName, "input_profiles"))
.CopyToFolder(Path.Join(PackageUtils.GetAmethystAppDataPath(), "Amethyst", "input_profiles"));
}
catch (Exception e)
{
Host?.Log(e);
}
}

public string ReadSettings()
{
var manifestPath = Path.Join(PackageUtils.GetAmethystAppDataPath(), "Amethyst", "actions.json");
RegisteredActions = File.Exists(manifestPath)
? JsonConvert.DeserializeObject<ActionsManifest>(
File.ReadAllText(manifestPath)) ?? new ActionsManifest(true)
: new ActionsManifest(true);
try
{
var manifestPath = Path.Join(PackageUtils.GetAmethystAppDataPath(), "Amethyst", "action_manifest.json");
RegisteredActions = File.Exists(manifestPath)
? JsonConvert.DeserializeObject<ActionsManifest>(
File.ReadAllText(manifestPath)) ?? new ActionsManifest(true)
: new ActionsManifest(true);

if (RegisteredActions.WasNull || !RegisteredActions.IsValid) // Re-generate the action manifest if it's not found
File.WriteAllText(manifestPath, JsonConvert.SerializeObject(RegisteredActions, Formatting.Indented));
if (RegisteredActions.WasNull || !RegisteredActions.IsValid)
SaveSettings(); // Re-generate the action manifest if it's not found

return manifestPath;
}
catch (Exception e)
{
Host?.Log(e);
}

return manifestPath;
return Path.Join(PackageUtils.GetAmethystAppDataPath(), "Amethyst", "action_manifest.json");
}

// Note: SteamVR must be initialized beforehand.
Expand Down
2 changes: 1 addition & 1 deletion plugin_OpenVR/Utils/PackageUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static class StorageExtensions
{
public static void CopyToFolder(this DirectoryInfo source, string destination, bool log = false)
{
// Now Create all of the directories
// Now Create all directories
foreach (var dirPath in source.GetDirectories("*", SearchOption.AllDirectories))
Directory.CreateDirectory(dirPath.FullName.Replace(source.FullName, destination));

Expand Down

0 comments on commit c71c0bf

Please sign in to comment.