1
0

mptWine.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * mptWine.h
  3. * ---------
  4. * Purpose: Wine stuff.
  5. * Notes : (currently none)
  6. * Authors: OpenMPT Devs
  7. * The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
  8. */
  9. #pragma once
  10. #include "openmpt/all/BuildSettings.hpp"
  11. #include "mptOS.h"
  12. #include "mpt/library/library.hpp"
  13. #include "openmpt/base/FlagSet.hpp"
  14. #include <map>
  15. #include <optional>
  16. #include <string>
  17. #include <vector>
  18. OPENMPT_NAMESPACE_BEGIN
  19. #if MPT_OS_WINDOWS
  20. namespace mpt
  21. {
  22. namespace Wine
  23. {
  24. class Exception
  25. : public std::runtime_error
  26. {
  27. public:
  28. Exception(const std::string &text)
  29. : std::runtime_error(text)
  30. {
  31. return;
  32. }
  33. };
  34. typedef void (*ExecutePosixCommandProgress)(void *userdata);
  35. enum ExecuteProgressResult
  36. {
  37. ExecuteProgressContinueWaiting = 0,
  38. ExecuteProgressAsyncCancel = -1,
  39. };
  40. typedef ExecuteProgressResult (*ExecutePosixShellScriptProgress)(void *userdata);
  41. enum ExecFlags
  42. {
  43. ExecFlagNone = 0,
  44. ExecFlagSilent = 1<<0, // do not show a terminal window
  45. ExecFlagInteractive = 1<<1, // allow interaction (prevents stdout and stderr capturing and implies !silent)
  46. ExecFlagAsync = 1<<2, // do not wait for the script to finish
  47. ExecFlagProgressWindow = 1<<3, // not implemented by mptOS
  48. ExecFlagSplitOutput = 1<<4, // split stdout and stderr (implies silent)
  49. ExecFlagsDefault = ExecFlagNone
  50. };
  51. MPT_DECLARE_ENUM(ExecFlags)
  52. struct ExecResult
  53. {
  54. int exitcode;
  55. std::string output;
  56. std::string error;
  57. std::map<std::string, std::vector<char> > filetree;
  58. static ExecResult Error()
  59. {
  60. ExecResult result;
  61. result.exitcode = -1;
  62. return result;
  63. }
  64. };
  65. class Context
  66. {
  67. protected:
  68. mpt::OS::Wine::VersionContext m_VersionContext;
  69. std::shared_ptr<std::optional<mpt::library>> m_Kernel32;
  70. private:
  71. LPWSTR (*CDECL wine_get_dos_file_name)(LPCSTR str);
  72. LPSTR (*CDECL wine_get_unix_file_name)(LPCWSTR str);
  73. protected:
  74. std::string m_Uname_m;
  75. std::string m_HOME;
  76. std::string m_XDG_DATA_HOME;
  77. std::string m_XDG_CACHE_HOME;
  78. std::string m_XDG_CONFIG_HOME;
  79. public:
  80. Context(mpt::OS::Wine::VersionContext versionContext);
  81. public:
  82. std::string EscapePosixShell(std::string line);
  83. std::string PathToPosix(mpt::PathString windowsPath);
  84. mpt::PathString PathToWindows(std::string hostPath);
  85. ExecResult ExecutePosixShellScript(std::string script, FlagSet<ExecFlags> flags, std::map<std::string, std::vector<char> > filetree, std::string title, ExecutePosixCommandProgress progress, ExecutePosixShellScriptProgress progressCancel, void *userdata);
  86. int ExecutePosixShellCommand(std::string command, std::string & output, std::string & error);
  87. std::string PathToPosixCanonical(mpt::PathString windowsPath);
  88. std::string GetPosixEnvVar(std::string var, std::string def = std::string());
  89. public:
  90. mpt::OS::Wine::VersionContext VersionContext() const { return m_VersionContext; }
  91. std::shared_ptr<std::optional<mpt::library>> Kernel32() const { return m_Kernel32; }
  92. std::string Uname_m() const { return m_Uname_m; }
  93. std::string HOME() const { return m_HOME; }
  94. std::string XDG_DATA_HOME() const { return m_XDG_DATA_HOME; }
  95. std::string XDG_CACHE_HOME() const { return m_XDG_CACHE_HOME; }
  96. std::string XDG_CONFIG_HOME() const { return m_XDG_CONFIG_HOME; }
  97. };
  98. } // namespace Wine
  99. } // namespace mpt
  100. #endif // MPT_OS_WINDOWS
  101. OPENMPT_NAMESPACE_END