Skip to content

Commit 86505f1

Browse files
authored
Add bindings for getKnownFolders(). Move stuff to mobase.utils. (#122)
1 parent a839d36 commit 86505f1

5 files changed

Lines changed: 298 additions & 0 deletions

File tree

src/mobase/mobase.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ PYBIND11_MODULE(mobase, m)
5656
py::module_ widgets = m.def_submodule("widgets");
5757
mo2::python::add_widget_bindings(widgets);
5858

59+
// utils
60+
//
61+
py::module_ utils = m.def_submodule("utils");
62+
mo2::python::add_utils_bindings(utils);
63+
5964
// functions
6065
//
6166
m.def("getFileVersion", wrap_for_filepath(&MOBase::getFileVersion),
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
#include <KnownFolders.h>
2+
3+
namespace mo2::python {
4+
5+
struct KnownFolder {
6+
const char* name;
7+
KNOWNFOLDERID guid;
8+
};
9+
10+
const std::array<KnownFolder, 142> KNOWN_FOLDERS{{
11+
{"AccountPictures", FOLDERID_AccountPictures},
12+
{"AddNewPrograms", FOLDERID_AddNewPrograms},
13+
{"AdminTools", FOLDERID_AdminTools},
14+
{"AllAppMods", FOLDERID_AllAppMods},
15+
{"AppCaptures", FOLDERID_AppCaptures},
16+
{"AppDataDesktop", FOLDERID_AppDataDesktop},
17+
{"AppDataDocuments", FOLDERID_AppDataDocuments},
18+
{"AppDataFavorites", FOLDERID_AppDataFavorites},
19+
{"AppDataProgramData", FOLDERID_AppDataProgramData},
20+
{"ApplicationShortcuts", FOLDERID_ApplicationShortcuts},
21+
{"AppsFolder", FOLDERID_AppsFolder},
22+
{"AppUpdates", FOLDERID_AppUpdates},
23+
{"CameraRoll", FOLDERID_CameraRoll},
24+
{"CameraRollLibrary", FOLDERID_CameraRollLibrary},
25+
{"CDBurning", FOLDERID_CDBurning},
26+
{"ChangeRemovePrograms", FOLDERID_ChangeRemovePrograms},
27+
{"CommonAdminTools", FOLDERID_CommonAdminTools},
28+
{"CommonOEMLinks", FOLDERID_CommonOEMLinks},
29+
{"CommonPrograms", FOLDERID_CommonPrograms},
30+
{"CommonStartMenu", FOLDERID_CommonStartMenu},
31+
{"CommonStartMenuPlaces", FOLDERID_CommonStartMenuPlaces},
32+
{"CommonStartup", FOLDERID_CommonStartup},
33+
{"CommonTemplates", FOLDERID_CommonTemplates},
34+
{"ComputerFolder", FOLDERID_ComputerFolder},
35+
{"ConflictFolder", FOLDERID_ConflictFolder},
36+
{"ConnectionsFolder", FOLDERID_ConnectionsFolder},
37+
{"Contacts", FOLDERID_Contacts},
38+
{"ControlPanelFolder", FOLDERID_ControlPanelFolder},
39+
{"Cookies", FOLDERID_Cookies},
40+
{"CurrentAppMods", FOLDERID_CurrentAppMods},
41+
{"Desktop", FOLDERID_Desktop},
42+
{"DevelopmentFiles", FOLDERID_DevelopmentFiles},
43+
{"Device", FOLDERID_Device},
44+
{"DeviceMetadataStore", FOLDERID_DeviceMetadataStore},
45+
{"Documents", FOLDERID_Documents},
46+
{"DocumentsLibrary", FOLDERID_DocumentsLibrary},
47+
{"Downloads", FOLDERID_Downloads},
48+
{"Favorites", FOLDERID_Favorites},
49+
{"Fonts", FOLDERID_Fonts},
50+
{"Games", FOLDERID_Games},
51+
{"GameTasks", FOLDERID_GameTasks},
52+
{"History", FOLDERID_History},
53+
{"HomeGroup", FOLDERID_HomeGroup},
54+
{"HomeGroupCurrentUser", FOLDERID_HomeGroupCurrentUser},
55+
{"ImplicitAppShortcuts", FOLDERID_ImplicitAppShortcuts},
56+
{"InternetCache", FOLDERID_InternetCache},
57+
{"InternetFolder", FOLDERID_InternetFolder},
58+
{"Libraries", FOLDERID_Libraries},
59+
{"Links", FOLDERID_Links},
60+
{"LocalAppData", FOLDERID_LocalAppData},
61+
{"LocalAppDataLow", FOLDERID_LocalAppDataLow},
62+
{"LocalDocuments", FOLDERID_LocalDocuments},
63+
{"LocalDownloads", FOLDERID_LocalDownloads},
64+
{"LocalizedResourcesDir", FOLDERID_LocalizedResourcesDir},
65+
{"LocalMusic", FOLDERID_LocalMusic},
66+
{"LocalPictures", FOLDERID_LocalPictures},
67+
{"LocalStorage", FOLDERID_LocalStorage},
68+
{"LocalVideos", FOLDERID_LocalVideos},
69+
{"Music", FOLDERID_Music},
70+
{"MusicLibrary", FOLDERID_MusicLibrary},
71+
{"NetHood", FOLDERID_NetHood},
72+
{"NetworkFolder", FOLDERID_NetworkFolder},
73+
{"Objects3D", FOLDERID_Objects3D},
74+
{"OneDrive", FOLDERID_OneDrive},
75+
{"OriginalImages", FOLDERID_OriginalImages},
76+
{"PhotoAlbums", FOLDERID_PhotoAlbums},
77+
{"Pictures", FOLDERID_Pictures},
78+
{"PicturesLibrary", FOLDERID_PicturesLibrary},
79+
{"Playlists", FOLDERID_Playlists},
80+
{"PrintersFolder", FOLDERID_PrintersFolder},
81+
{"PrintHood", FOLDERID_PrintHood},
82+
{"Profile", FOLDERID_Profile},
83+
{"ProgramData", FOLDERID_ProgramData},
84+
{"ProgramFiles", FOLDERID_ProgramFiles},
85+
{"ProgramFilesCommon", FOLDERID_ProgramFilesCommon},
86+
{"ProgramFilesCommonX64", FOLDERID_ProgramFilesCommonX64},
87+
{"ProgramFilesCommonX86", FOLDERID_ProgramFilesCommonX86},
88+
{"ProgramFilesX64", FOLDERID_ProgramFilesX64},
89+
{"ProgramFilesX86", FOLDERID_ProgramFilesX86},
90+
{"Programs", FOLDERID_Programs},
91+
{"Public", FOLDERID_Public},
92+
{"PublicDesktop", FOLDERID_PublicDesktop},
93+
{"PublicDocuments", FOLDERID_PublicDocuments},
94+
{"PublicDownloads", FOLDERID_PublicDownloads},
95+
{"PublicGameTasks", FOLDERID_PublicGameTasks},
96+
{"PublicLibraries", FOLDERID_PublicLibraries},
97+
{"PublicMusic", FOLDERID_PublicMusic},
98+
{"PublicPictures", FOLDERID_PublicPictures},
99+
{"PublicRingtones", FOLDERID_PublicRingtones},
100+
{"PublicUserTiles", FOLDERID_PublicUserTiles},
101+
{"PublicVideos", FOLDERID_PublicVideos},
102+
{"QuickLaunch", FOLDERID_QuickLaunch},
103+
{"Recent", FOLDERID_Recent},
104+
{"RecordedCalls", FOLDERID_RecordedCalls},
105+
{"RecordedTVLibrary", FOLDERID_RecordedTVLibrary},
106+
{"RecycleBinFolder", FOLDERID_RecycleBinFolder},
107+
{"ResourceDir", FOLDERID_ResourceDir},
108+
{"RetailDemo", FOLDERID_RetailDemo},
109+
{"Ringtones", FOLDERID_Ringtones},
110+
{"RoamedTileImages", FOLDERID_RoamedTileImages},
111+
{"RoamingAppData", FOLDERID_RoamingAppData},
112+
{"RoamingTiles", FOLDERID_RoamingTiles},
113+
{"SampleMusic", FOLDERID_SampleMusic},
114+
{"SamplePictures", FOLDERID_SamplePictures},
115+
{"SamplePlaylists", FOLDERID_SamplePlaylists},
116+
{"SampleVideos", FOLDERID_SampleVideos},
117+
{"SavedGames", FOLDERID_SavedGames},
118+
{"SavedPictures", FOLDERID_SavedPictures},
119+
{"SavedPicturesLibrary", FOLDERID_SavedPicturesLibrary},
120+
{"SavedSearches", FOLDERID_SavedSearches},
121+
{"Screenshots", FOLDERID_Screenshots},
122+
{"SEARCH_CSC", FOLDERID_SEARCH_CSC},
123+
{"SEARCH_MAPI", FOLDERID_SEARCH_MAPI},
124+
{"SearchHistory", FOLDERID_SearchHistory},
125+
{"SearchHome", FOLDERID_SearchHome},
126+
{"SearchTemplates", FOLDERID_SearchTemplates},
127+
{"SendTo", FOLDERID_SendTo},
128+
{"SidebarDefaultParts", FOLDERID_SidebarDefaultParts},
129+
{"SidebarParts", FOLDERID_SidebarParts},
130+
{"SkyDrive", FOLDERID_SkyDrive},
131+
{"SkyDriveCameraRoll", FOLDERID_SkyDriveCameraRoll},
132+
{"SkyDriveDocuments", FOLDERID_SkyDriveDocuments},
133+
{"SkyDriveMusic", FOLDERID_SkyDriveMusic},
134+
{"SkyDrivePictures", FOLDERID_SkyDrivePictures},
135+
{"StartMenu", FOLDERID_StartMenu},
136+
{"StartMenuAllPrograms", FOLDERID_StartMenuAllPrograms},
137+
{"Startup", FOLDERID_Startup},
138+
{"SyncManagerFolder", FOLDERID_SyncManagerFolder},
139+
{"SyncResultsFolder", FOLDERID_SyncResultsFolder},
140+
{"SyncSetupFolder", FOLDERID_SyncSetupFolder},
141+
{"System", FOLDERID_System},
142+
{"SystemX86", FOLDERID_SystemX86},
143+
{"Templates", FOLDERID_Templates},
144+
{"UserPinned", FOLDERID_UserPinned},
145+
{"UserProfiles", FOLDERID_UserProfiles},
146+
{"UserProgramFiles", FOLDERID_UserProgramFiles},
147+
{"UserProgramFilesCommon", FOLDERID_UserProgramFilesCommon},
148+
{"UsersFiles", FOLDERID_UsersFiles},
149+
{"UsersLibraries", FOLDERID_UsersLibraries},
150+
{"Videos", FOLDERID_Videos},
151+
{"VideosLibrary", FOLDERID_VideosLibrary},
152+
{"Windows", FOLDERID_Windows},
153+
}};
154+
155+
} // namespace mo2::python

src/mobase/wrappers/utils.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#include "wrappers.h"
2+
3+
#include "../pybind11_all.h"
4+
5+
#include <report.h>
6+
#include <utility.h>
7+
8+
#include "known_folders.h"
9+
10+
namespace py = pybind11;
11+
using namespace MOBase;
12+
13+
namespace mo2::python {
14+
15+
void add_utils_bindings(pybind11::module_ m)
16+
{
17+
py::class_<KnownFolder> pyKnownFolder(m, "KnownFolder");
18+
for (std::size_t i = 0; i < KNOWN_FOLDERS.size(); ++i) {
19+
pyKnownFolder.attr(KNOWN_FOLDERS[i].name) = py::int_(i);
20+
}
21+
22+
m.def(
23+
"getKnownFolder",
24+
[](std::size_t knownFolderId, QString what) {
25+
return getKnownFolder(KNOWN_FOLDERS.at(knownFolderId).guid, what);
26+
},
27+
py::arg("known_folder"), py::arg("what") = "");
28+
29+
m.def(
30+
"getOptionalKnownFolder",
31+
[](std::size_t knownFolderId) {
32+
const auto r =
33+
getOptionalKnownFolder(KNOWN_FOLDERS.at(knownFolderId).guid);
34+
return r.isEmpty() ? py::none{} : py::cast(r);
35+
},
36+
py::arg("known_folder"));
37+
38+
m.def("getFileVersion", wrap_for_filepath(&MOBase::getFileVersion),
39+
py::arg("filepath"));
40+
m.def("getProductVersion", wrap_for_filepath(&MOBase::getProductVersion),
41+
py::arg("executable"));
42+
m.def("getIconForExecutable", wrap_for_filepath(&MOBase::iconForExecutable),
43+
py::arg("executable"));
44+
}
45+
46+
} // namespace mo2::python

src/mobase/wrappers/wrappers.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ namespace mo2::python {
3030
*/
3131
void add_widget_bindings(pybind11::module_ m);
3232

33+
/**
34+
* @brief Add bindings for the various utilities classes and functions in uibase
35+
* that cannot be extended from Python.
36+
*
37+
* @param m Python module to add bindings to.
38+
*/
39+
void add_utils_bindings(pybind11::module_ m);
40+
3341
/**
3442
* @brief Add bindings for the uibase wrappers to the given module. uibase
3543
* wrappers include classes from uibase that can be extended from Python but

src/plugin_python_en.ts

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!DOCTYPE TS>
3+
<TS version="2.1" language="en_US">
4+
<context>
5+
<name>ProxyPython</name>
6+
<message>
7+
<location filename="proxy/proxypython.cpp" line="88"/>
8+
<source>Python Initialization failed</source>
9+
<translation type="unfinished"></translation>
10+
</message>
11+
<message>
12+
<location filename="proxy/proxypython.cpp" line="89"/>
13+
<source>On a previous start the Python Plugin failed to initialize.
14+
Do you want to try initializing python again (at the risk of another crash)?
15+
Suggestion: Select &quot;no&quot;, and click the warning sign for further help.Afterwards you have to re-enable the python plugin.</source>
16+
<translation type="unfinished"></translation>
17+
</message>
18+
<message>
19+
<location filename="proxy/proxypython.cpp" line="162"/>
20+
<source>Python Proxy</source>
21+
<translation type="unfinished"></translation>
22+
</message>
23+
<message>
24+
<location filename="proxy/proxypython.cpp" line="172"/>
25+
<source>Proxy Plugin to allow plugins written in python to be loaded</source>
26+
<translation type="unfinished"></translation>
27+
</message>
28+
<message>
29+
<location filename="proxy/proxypython.cpp" line="244"/>
30+
<source>ModOrganizer path contains a semicolon</source>
31+
<translation type="unfinished"></translation>
32+
</message>
33+
<message>
34+
<location filename="proxy/proxypython.cpp" line="246"/>
35+
<source>Python DLL not found</source>
36+
<translation type="unfinished"></translation>
37+
</message>
38+
<message>
39+
<location filename="proxy/proxypython.cpp" line="248"/>
40+
<source>Invalid Python DLL</source>
41+
<translation type="unfinished"></translation>
42+
</message>
43+
<message>
44+
<location filename="proxy/proxypython.cpp" line="250"/>
45+
<source>Initializing Python failed</source>
46+
<translation type="unfinished"></translation>
47+
</message>
48+
<message>
49+
<location filename="proxy/proxypython.cpp" line="252"/>
50+
<location filename="proxy/proxypython.cpp" line="281"/>
51+
<source>invalid problem key %1</source>
52+
<translation type="unfinished"></translation>
53+
</message>
54+
<message>
55+
<location filename="proxy/proxypython.cpp" line="260"/>
56+
<source>The path to Mod Organizer (%1) contains a semicolon.&lt;br&gt;While this is legal on NTFS drives, many applications do not handle it correctly.&lt;br&gt;Unfortunately MO depends on libraries that seem to fall into that group.&lt;br&gt;As a result the python plugin cannot be loaded, and the only solution we can offer is to remove the semicolon or move MO to a path without a semicolon.</source>
57+
<oldsource>The path to Mod Organizer (%1) contains a semicolon. &lt;br&gt;While this is legal on NTFS drives, many softwares do not handle it correctly.&lt;br&gt;Unfortunately MO depends on libraries that seem to fall into that group.&lt;br&gt;As a result the python plugin cannot be loaded, and the only solution we canoffer is to remove the semicolon or move MO to a path without a semicolon.</oldsource>
58+
<translation type="unfinished"></translation>
59+
</message>
60+
<message>
61+
<location filename="proxy/proxypython.cpp" line="270"/>
62+
<source>The Python plugin DLL was not found, maybe your antivirus deleted it. Re-installing MO2 might fix the problem.</source>
63+
<translation type="unfinished"></translation>
64+
</message>
65+
<message>
66+
<location filename="proxy/proxypython.cpp" line="273"/>
67+
<source>The Python plugin DLL is invalid, maybe your antivirus is blocking it. Re-installing MO2 and adding exclusions for it to your AV might fix the problem.</source>
68+
<translation type="unfinished"></translation>
69+
</message>
70+
<message>
71+
<location filename="proxy/proxypython.cpp" line="278"/>
72+
<source>The initialization of the Python plugin DLL failed, unfortunately without any details.</source>
73+
<translation type="unfinished"></translation>
74+
</message>
75+
</context>
76+
<context>
77+
<name>QObject</name>
78+
<message>
79+
<location filename="runner/error.h" line="76"/>
80+
<source>An unknown exception was thrown in python code.</source>
81+
<translation type="unfinished"></translation>
82+
</message>
83+
</context>
84+
</TS>

0 commit comments

Comments
 (0)