Source: Engines/Wine/Plugins/regedit/script.js

  1. const { createTempFile, writeToFile } = include("utils.functions.filesystem.files");
  2. const FileClass = Java.type("java.io.File");
  3. const ArrayListClass = Java.type("java.util.ArrayList");
  4. /**
  5. * Plugin to provide Regedit support
  6. */
  7. module.default = class Regedit {
  8. constructor(wine) {
  9. this.wine = wine;
  10. }
  11. convertPatchContent(patchContent, contentType) {
  12. if (contentType && contentType === "binary") {
  13. return patchContent.map(byte => String.fromCharCode(byte)).join("");
  14. } else {
  15. return patchContent;
  16. }
  17. }
  18. fetchRegistryFile(root) {
  19. switch (root) {
  20. case "HKEY_CURRENT_USER":
  21. return "user.reg";
  22. case "HKEY_LOCAL_MACHINE":
  23. return "system.reg";
  24. default:
  25. throw new Error("Illegal registry root exception");
  26. }
  27. }
  28. open(args) {
  29. this.wine.run("regedit", [args], this.wine.prefixDirectory(), false, true);
  30. return this;
  31. }
  32. patch(patchContent, contentType) {
  33. const content = this.convertPatchContent(patchContent, contentType);
  34. const tmpFile = createTempFile("reg");
  35. writeToFile(tmpFile, content);
  36. this.wine.run("regedit", [tmpFile], this.wine.prefixDirectory(), false, true);
  37. return this;
  38. }
  39. deleteKey(keyPath) {
  40. this.wine.run("reg", ["delete", keyPath, "/f"], this.wine.prefixDirectory(), false, true);
  41. return this;
  42. }
  43. deleteValue(keyPath, value) {
  44. this.wine.run("reg", ["delete", keyPath, "/v", value, "/f"], this.wine.prefixDirectory(), false, true);
  45. return this;
  46. }
  47. fetchValue(keyPath) {
  48. const root = keyPath.shift();
  49. const registryFile = this.fetchRegistryFile(root);
  50. // ensure that correct type is passed to Java
  51. const keyPathList = new ArrayListClass();
  52. for (const level in keyPath) {
  53. keyPathList.add(keyPath[level]);
  54. }
  55. const registryValue = Bean("registryParser")
  56. .parseFile(new FileClass(this.wine.prefixDirectory() + "/" + registryFile), root)
  57. .getChild(keyPathList);
  58. if (registryValue == null) {
  59. return null;
  60. }
  61. if (registryValue.getText) {
  62. return registryValue.getText();
  63. } else {
  64. return registryValue;
  65. }
  66. }
  67. };