@@ -92,6 +92,8 @@ const char* input2header(const char* input);
92
92
void resetJSON (const char * input );
93
93
94
94
void listExampleDir (char * basePath , char * examplePath );
95
+ /* Function to search for a keyword in a path and return the path up to that keyword */
96
+ char * findKeywordPath (const char * path , const char * keyword );
95
97
96
98
97
99
/* Declear global vairables */
@@ -105,6 +107,7 @@ const char* key_amb_header = "#include";
105
107
const char * key_amb_customized = "CUSTOMIZED" ;
106
108
const char * key_json = "build" ;
107
109
const char * key_amb = "Arduino15" ;
110
+ const char * key_portable = "portable" ;
108
111
const char * key_ino = ".ino" ;
109
112
const char * ext_json = ".json" ;
110
113
const char * ext_cpp = ".cpp" ;
@@ -116,20 +119,23 @@ const char* filename_txt = "ino_validation.txt";
116
119
/* Declear common file paths */
117
120
#ifdef _WIN32
118
121
char * path_arduino15_add = "\\AppData\\Local\\Arduino15\\" ;
122
+ char * path_arduino15_add_portable = "" ; // TODO: added for portable
119
123
char * path_ambpro2_add = "\\packages\\realtek\\hardware\\AmebaPro2\\" ;
120
124
char * path_model_add = "\\variants\\common_nn_models\\" ;
121
125
char * path_library_add = "\\libraries\\" ;
122
126
char * path_txtfile_add = "\\misc\\" ;
123
127
char * backspace = "\\" ;
124
128
#elif __linux__
125
129
char * path_arduino15_add = "/.arduino15/" ;
130
+ char * path_arduino15_add_portable = "" ; // TODO: added for portable
126
131
char * path_ambpro2_add = "/packages/realtek/hardware/AmebaPro2/" ;
127
132
char * path_model_add = "/variants/common_nn_models/" ;
128
133
char * path_library_add = "/libraries/" ;
129
134
char * path_txtfile_add = "/misc/" ;
130
135
char * backspace = "/" ;
131
136
#else
132
137
char * path_arduino15_add = "/Library/Arduino15/" ;
138
+ char * path_arduino15_add_portable = "" ; // TODO: added for portable
133
139
char * path_ambpro2_add = "/packages/realtek/hardware/AmebaPro2/" ;
134
140
char * path_model_add = "/variants/common_nn_models/" ;
135
141
char * path_library_add = "/libraries/" ;
@@ -173,8 +179,12 @@ int main(int argc, char* argv[]) {
173
179
strcpy (path_root , getenv ("HOME" ));
174
180
strcpy (path_arduino15 , getenv ("HOME" ));
175
181
#endif
176
-
177
- strcat (path_arduino15 , path_arduino15_add );
182
+ if (strstr (path_tools , "portable" )) {
183
+ strcpy (path_arduino15 , findKeywordPath (path_tools , key_portable ));
184
+ }
185
+ else {
186
+ strcat (path_arduino15 , path_arduino15_add );
187
+ }
178
188
strcpy (path_pro2 , path_arduino15 );
179
189
strcat (path_pro2 , path_ambpro2_add );
180
190
strcpy (path_model , path_pro2 );
@@ -216,6 +226,29 @@ int main(int argc, char* argv[]) {
216
226
// -------------------------------
217
227
// Functions
218
228
// -------------------------------
229
+
230
+ // Function to search for a keyword in a path and return the path up to that keyword
231
+ char * findKeywordPath (const char * path , const char * keyword ) {
232
+ static char result [1024 ]; // Static buffer for the result
233
+ char * found ;
234
+
235
+ // Search for the keyword in the path
236
+ found = strstr (path , keyword );
237
+ if (found != NULL ) {
238
+ // Calculate the length up to the end of the keyword
239
+ int length = found - path + strlen (keyword );
240
+ // Copy the relevant part of the path to the result
241
+ strncpy (result , path , length );
242
+ // Null-terminate the result string
243
+ result [length ] = '\0' ;
244
+ return result ;
245
+ }
246
+ else {
247
+ // Return NULL if the keyword is not found
248
+ return NULL ;
249
+ }
250
+ }
251
+
219
252
int isDirExists (const char * path ) {
220
253
DIR * dir ;
221
254
struct dirent * entry ;
@@ -365,6 +398,7 @@ const char* dirName(const char* directory_path) {
365
398
DIR * directory = opendir (directory_path );
366
399
const char * sdk_name = "" ;
367
400
// check dir validation
401
+
368
402
if (directory ) {
369
403
while ((entry = readdir (directory )) != NULL ) {
370
404
#ifdef __APPLE__
0 commit comments