SteamVR_Input_PostProcessBuild.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. }
  14. private static void UpdateAppKey(string newFilePath, string executableName)
  15. {
  16. if (File.Exists(newFilePath))
  17. {
  18. string jsonText = System.IO.File.ReadAllText(newFilePath);
  19. string findString = "\"app_key\" : \"";
  20. int stringStart = jsonText.IndexOf(findString);
  21. if (stringStart == -1)
  22. {
  23. findString = findString.Replace(" ", "");
  24. stringStart = jsonText.IndexOf(findString);
  25. if (stringStart == -1)
  26. return; //no app key
  27. }
  28. stringStart += findString.Length;
  29. int stringEnd = jsonText.IndexOf("\"", stringStart);
  30. int stringLength = stringEnd - stringStart;
  31. string currentAppKey = jsonText.Substring(stringStart, stringLength);
  32. if (string.Equals(currentAppKey, SteamVR_Settings.instance.editorAppKey, System.StringComparison.CurrentCultureIgnoreCase) == false)
  33. {
  34. jsonText = jsonText.Replace(currentAppKey, SteamVR_Settings.instance.editorAppKey);
  35. FileInfo file = new FileInfo(newFilePath);
  36. file.IsReadOnly = false;
  37. File.WriteAllText(newFilePath, jsonText);
  38. }
  39. }
  40. }
  41. }
  42. }