Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

oscsetting: add autobuild feature

  • Loading branch information...
commit b264ce5b30e32913164d785a7dfca182ea863f6e 1 parent d9f461d
authored

Showing 1 changed file with 87 additions and 5 deletions. Show diff stats Hide diff stats

  1. 92  src/oscsettings.c
92  src/oscsettings.c
@@ -16,9 +16,13 @@
16 16
  */
17 17
 
18 18
 #include <bsp.h>
  19
+#include <sys/types.h>
  20
+#include <sys/stat.h>
19 21
 #include <stdio.h>
20 22
 #include <stdlib.h>
21 23
 #include <string.h>
  24
+#include <dirent.h>
  25
+#include <unistd.h>
22 26
 #include <mtklib.h>
23 27
 
24 28
 #include "util.h"
@@ -26,6 +30,7 @@
26 30
 #include "cp.h"
27 31
 #include "messagebox.h"
28 32
 #include "filedialog.h"
  33
+#include "performance.h"
29 34
 
30 35
 #include "oscsettings.h"
31 36
 
@@ -166,6 +171,82 @@ static void addupdate_callback(mtk_event *e, void *arg)
166 171
 	mtk_cmd(appid, "e_filename.set(-text \"\")");
167 172
 }
168 173
 
  174
+static int cmpstringp(const void *p1, const void *p2)
  175
+{
  176
+	return strcmp(*(char * const *)p1, *(char * const *)p2);
  177
+}
  178
+
  179
+static void autobuild(int si, char *folder)
  180
+{
  181
+	DIR *d;
  182
+	struct dirent *entry;
  183
+	struct stat s;
  184
+	char fullname[384];
  185
+	char *c;
  186
+	char *files[384];
  187
+	int n_files;
  188
+	int max_files = 64 - si;
  189
+	int i;
  190
+
  191
+	d = opendir(folder);
  192
+	if(!d) {
  193
+		messagebox("Auto build failed", "Unable to open directory");
  194
+		return;
  195
+	}
  196
+	n_files = 0;
  197
+	while((entry = readdir(d))) {
  198
+		if(entry->d_name[0] == '.') continue;
  199
+		strncpy(fullname, folder, sizeof(fullname));
  200
+		strncat(fullname, entry->d_name, sizeof(fullname));
  201
+		lstat(fullname, &s);
  202
+		if(!S_ISDIR(s.st_mode)) {
  203
+			c = strrchr(entry->d_name, '.');
  204
+			if((c != NULL) && (strcmp(c, ".fnp") == 0)) {
  205
+				if(n_files < 384) {
  206
+					files[n_files] = strdup(entry->d_name);
  207
+					n_files++;
  208
+				}
  209
+			}
  210
+		}
  211
+	}
  212
+	closedir(d);
  213
+
  214
+	qsort(files, n_files, sizeof(char *), cmpstringp);
  215
+
  216
+	for(i=0;i<n_files;i++) {
  217
+		if(i < max_files)
  218
+			sprintf(osc_bindings[si+i], "%s/%s", folder, files[i]);
  219
+		free(files[i]);
  220
+	}
  221
+}
  222
+
  223
+static void autobuild_callback(mtk_event *e, void *arg)
  224
+{
  225
+	char key[8];
  226
+	int sindex;
  227
+	char *c;
  228
+	char filename[384];
  229
+	int i;
  230
+
  231
+	mtk_req(appid, key, sizeof(key), "e_number.text");
  232
+	mtk_req(appid, filename, sizeof(filename), "e_filename.text");
  233
+	sindex = strtol(key, &c, 0);
  234
+	if((*c != 0x00) || (sindex < 0) || (sindex > 63)) {
  235
+		messagebox("Error", "Invalid start number.\nUse a decimal or hexadecimal (0x...) number between 0 and 63.");
  236
+		return;
  237
+	}
  238
+
  239
+	if(filename[0] == 0x00)
  240
+		strcpy(filename, SIMPLE_PATCHES_FOLDER);
  241
+
  242
+	i = strlen(filename);
  243
+	if(filename[i-1] == '/')
  244
+		filename[i-1] = 0x00;
  245
+
  246
+	autobuild(sindex, filename);
  247
+	update_list();
  248
+}
  249
+
169 250
 void init_oscsettings()
170 251
 {
171 252
 	appid = mtk_init_app("OSC");
@@ -190,7 +271,7 @@ void init_oscsettings()
190 271
 		"g_addedit0.place(s_addedit1, -column 1 -row 1)",
191 272
 		"g_addedit0.place(l_addedit, -column 2 -row 1)",
192 273
 		"g_addedit0.place(s_addedit2, -column 3 -row 1)",
193  
-		
  274
+
194 275
 		"g_addedit1 = new Grid()",
195 276
 		"l_number = new Label(-text \"Number:\")",
196 277
 		"e_number = new Entry()",
@@ -207,7 +288,7 @@ void init_oscsettings()
207 288
 		"g_addedit1.columnconfig(3, -size 0)",
208 289
 		"g_addedit1.columnconfig(4, -size 0)",
209 290
 		"b_addupdate = new Button(-text \"Add/update\")",
210  
-
  291
+		"b_autobuild = new Button(-text \"Auto build\")",
211 292
 		"g_btn = new Grid()",
212 293
 		"b_ok = new Button(-text \"OK\")",
213 294
 		"b_cancel = new Button(-text \"Cancel\")",
@@ -221,8 +302,9 @@ void init_oscsettings()
221 302
 		"g.place(g_addedit0, -column 1 -row 3)",
222 303
 		"g.place(g_addedit1, -column 1 -row 4)",
223 304
 		"g.place(b_addupdate, -column 1 -row 5)",
224  
-		"g.rowconfig(6, -size 10)",
225  
-		"g.place(g_btn, -column 1 -row 7)",
  305
+		"g.place(b_autobuild, -column 1 -row 6)",
  306
+		"g.rowconfig(7, -size 10)",
  307
+		"g.place(g_btn, -column 1 -row 8)",
226 308
 
227 309
 		"w = new Window(-content g -title \"OSC settings\")",
228 310
 		0);
@@ -232,7 +314,7 @@ void init_oscsettings()
232 314
 	mtk_bind(appid, "b_filename", "commit", browse_callback, NULL);
233 315
 	mtk_bind(appid, "b_filenameclear", "commit", clear_callback, NULL);
234 316
 	mtk_bind(appid, "b_addupdate", "commit", addupdate_callback, NULL);
235  
-
  317
+	mtk_bind(appid, "b_autobuild", "commit", autobuild_callback, NULL);
236 318
 	mtk_bind(appid, "b_ok", "commit", ok_callback, NULL);
237 319
 	mtk_bind(appid, "b_cancel", "commit", cancel_callback, NULL);
238 320
 

0 notes on commit b264ce5

Please sign in to comment.
Something went wrong with that request. Please try again.