StorePackage.h 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #pragma once
  2. // Round 165n (store165): LYNX packaged as MSIX for the Microsoft Store. The pure rules behind src/platform/Package.cpp
  3. // (no JUCE, no Windows headers, so tests can check them on every OS).
  4. //
  5. // Inside an MSIX package Windows redirects *new* files under %APPDATA% / %LOCALAPPDATA% to a private per-user,
  6. // per-package folder (%LOCALAPPDATA%\Packages\<family name>\LocalCache\Roaming|Local) and merges it back only for the
  7. // package's own processes. Explorer, curl and other programs see the real disk, so a crash report LYNX "wrote to
  8. // %APPDATA%\LYNX\crash-reports" would not be there when the user opens that folder. A packaged LYNX therefore uses the
  9. // redirected folder's real path as its settings folder: the same place Windows would have put the files anyway (so
  10. // stray writes to %APPDATA%\LYNX still land next to them), but a path every program can open.
  11. #include <string>
  12. #include <string_view>
  13. namespace lynx::store
  14. {
  15. // The application id in AppxManifest.xml (<Application Id="LYNX">): "shell:AppsFolder\<family>!LYNX" starts it.
  16. inline constexpr const char* applicationId = "LYNX";
  17. // The settings folder of a packaged LYNX: <LocalAppData>\Packages\<family>\LocalCache\Roaming\LYNX — where Windows
  18. // redirects %APPDATA%\LYNX for this package. Empty when either part is missing.
  19. inline std::string packagedSettingsFolder (std::string_view localAppData, std::string_view familyName)
  20. {
  21. if (localAppData.empty() || familyName.empty())
  22. return {};
  23. std::string path (localAppData);
  24. if (path.back() != '\\' && path.back() != '/')
  25. path += '\\';
  26. path += "Packages\\";
  27. path += familyName;
  28. path += "\\LocalCache\\Roaming\\LYNX";
  29. return path;
  30. }
  31. // The shell target that starts the packaged app (a relaunch after a language change, for instance): a packaged exe
  32. // started by its file path would run without the package's identity.
  33. inline std::string appsFolderTarget (std::string_view familyName)
  34. {
  35. return "shell:AppsFolder\\" + std::string (familyName) + "!" + applicationId;
  36. }
  37. // First start of the Store build on a PC that already ran the installer / zip build: which top-level entries of the
  38. // old %APPDATA%\LYNX are copied into the packaged settings folder. Preferences, the plugin list, favourites, presets,
  39. // themes, layouts and the user's own plugin folder come along; caches (rebuilt on demand), autosaves, crash reports,
  40. // session markers, logs and --packageinfo's probe file of the other build stay where they are (a copied "session running" marker would even
  41. // report a crash that never happened).
  42. inline bool migratesFromUnpackaged (std::string_view name, bool isDirectory)
  43. {
  44. if (name.empty() || name == "." || name == "..")
  45. return false;
  46. if (isDirectory)
  47. return name != "wavecache" && name != "autosave" && name != "flp-embedded" && name != "crash-reports" && name != "sessions";
  48. const auto endsWith = [name] (std::string_view suffix) {
  49. return name.size() >= suffix.size() && name.substr (name.size() - suffix.size()) == suffix;
  50. };
  51. if (endsWith (".log") || endsWith (".tmp"))
  52. return false;
  53. return name != "session-running.txt" && name != "migrated-from-appdata.txt" && name != "package-probe.txt";
  54. }
  55. // The marker written once the copy is done (it is never copied itself, see above).
  56. inline constexpr const char* migrationMarker = "migrated-from-appdata.txt";
  57. } // namespace lynx::store