18
18
#include " ext.h"
19
19
#include " ext_obex.h"
20
20
21
+ #ifdef CMX_CPP_HEADER
22
+ #include < string>
23
+ #include < filesystem>
24
+ namespace fs = std::filesystem;
25
+ #endif
21
26
22
27
// ---------------------------------------------------------------------------
23
28
// constants
28
33
// ---------------------------------------------------------------------------
29
34
// forward declarations
30
35
31
- // t_symbol* locate_path_to_external(t_class* c);
36
+ #ifdef CMX_CPP_HEADER
37
+ std::string get_path_to_external (t_class* c, char * subpath);
38
+ std::string get_path_to_package (t_class* c, char * subpath);
39
+ #else
32
40
t_string* get_path_to_external (t_class* c, char * subpath);
33
41
t_string* get_path_to_package (t_class* c, char * subpath);
42
+ #endif
34
43
t_object* create_object (t_object* x, const char * text);
35
44
void path_basename (const char * path, char * filename);
36
45
void path_dirname (const char * path, char * parent_directory);
@@ -45,6 +54,63 @@ void path_join(char* destination, const char* path1, const char* path2);
45
54
#ifdef CMX_IMPLEMENTATION
46
55
47
56
57
+ #ifdef CMX_CPP_HEADER
58
+ /* *
59
+ * @brief Return path to external with optional subpath
60
+ *
61
+ * @param c t_class instance
62
+ * @param subpath The subpath or NULL (if not)
63
+ *
64
+ * @return path to external + (optional subpath)
65
+ */
66
+ std::string get_path_to_external (t_class* c, char * subpath)
67
+ {
68
+ char external_path[MAX_PATH_CHARS];
69
+ char external_name[MAX_PATH_CHARS];
70
+ char conform_path[MAX_PATH_CHARS];
71
+ short path_id = class_getpath (c);
72
+ fs::path result;
73
+
74
+ #ifdef __APPLE__
75
+ const char * ext_filename = " %s.mxo" ;
76
+ #else
77
+ const char * ext_filename = " %s.mxe64" ;
78
+ #endif
79
+ snprintf_zero (external_name, MAX_FILENAME_CHARS, ext_filename, c->c_sym ->s_name );
80
+ path_toabsolutesystempath (path_id, external_name, external_path);
81
+ path_nameconform (external_path, conform_path, PATH_STYLE_NATIVE,
82
+ PATH_TYPE_TILDE);
83
+ result = fs::path (external_path);
84
+ if (subpath != NULL ) {
85
+ result /= subpath;
86
+ }
87
+ return result.string ();
88
+ }
89
+
90
+
91
+ /* *
92
+ * @brief Return path to package with optional subpath
93
+ *
94
+ * @param c t_class instance
95
+ * @param subpath The subpath or NULL (if not)
96
+ *
97
+ * @return path to package + (optional subpath)
98
+ */
99
+ std::string get_path_to_package (t_class* c, char * subpath)
100
+ {
101
+ fs::path external_path = fs::path (get_path_to_external (c, NULL ));
102
+ fs::path externals_folder = external_path.parent_path ();
103
+ fs::path package_folder = externals_folder.parent_path ();
104
+
105
+ if (subpath != NULL ) {
106
+ package_folder /= subpath;
107
+ }
108
+
109
+ return package_folder.string ();
110
+ }
111
+
112
+ #else
113
+
48
114
/* *
49
115
* @brief Return path to external with optional subpath
50
116
*
@@ -112,6 +178,8 @@ t_string* get_path_to_package(t_class* c, char* subpath)
112
178
return result;
113
179
}
114
180
181
+ #endif
182
+
115
183
116
184
/* *
117
185
* @brief Create a new object from a box text
0 commit comments