SteamVR_Input_PostProcessBuild.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using UnityEngine;
  2. using UnityEditor;
  3. using System.Collections;
  4. using UnityEditor.Callbacks;
  5. using System.IO;
  6. namespace Valve.VR
  7. {
  8. public class SteamVR_Input_PostProcessBuild
  9. {
  10. [PostProcessBuildAttribute(1)]
  11. public static void OnPostprocessBuild(BuildTarget target, string pathToBuiltProject)
  12. {
  13. SteamVR_Input.InitializeFile();
  14. FileInfo fileInfo = new FileInfo(pathToBuiltProject);
  15. string buildPath = fileInfo.Directory.FullName;
  16. bool overwrite = EditorPrefs.GetBool(SteamVR_Input_Generator.steamVRInputOverwriteBuildKey);
  17. SteamVR_Input.actionFile.CopyFilesToPath(buildPath, overwrite);
  18. }
  19. private static void UpdateAppKey(string newFilePath, string executableName)
  20. {
  21. if (File.Exists(newFilePath))
  22. {
  23. string jsonText = System.IO.File.ReadAllText(newFilePath);
  24. string findString = "\"app_key\" : \"";
  25. int stringStart = jsonText.IndexOf(findString);
  26. if (stringStart == -1)
  27. {
  28. findString = findString.Replace(" ", "");
  29. stringStart = jsonText.IndexOf(findString);
  30. if (stringStart == -1)
  31. return; //no app key
  32. }
  33. stringStart += findString.Length;
  34. int stringEnd = jsonText.IndexOf("\"", stringStart);
  35. int stringLength = stringEnd - stringStart;
  36. string currentAppKey = jsonText.Substring(stringStart, stringLength);
  37. if (string.Equals(currentAppKey, SteamVR_Settings.instance.editorAppKey, System.StringComparison.CurrentCultureIgnoreCase) == false)
  38. {
  39. jsonText = jsonText.Replace(currentAppKey, SteamVR_Settings.instance.editorAppKey);
  40. FileInfo file = new FileInfo(newFilePath);
  41. file.IsReadOnly = false;
  42. File.WriteAllText(newFilePath, jsonText);
  43. }
  44. }
  45. }
  46. }
  47. }