bool gIsDir(const char *path) { bool ret; #if defined(__linux__) struct stat s1; stat(path, &s1); ret = S_ISDIR(s1.st_mode); #elif defined(__APPLE__) if (strcmp(path, "")==0) ret = false; else { struct stat s1; stat(path, &s1); ret = S_ISDIR(s1.st_mode); /* check if ret is a bundle, a special OS X folder which must be * shown as a regular file (VST). * FIXME - consider native functions CFBundle... */ if (ret) { std::string tmp = path; tmp += "/Contents/Info.plist"; if (gFileExists(tmp.c_str())) ret = false; } } #elif defined(__WIN32) unsigned dwAttrib = GetFileAttributes(path); ret = (dwAttrib != INVALID_FILE_ATTRIBUTES && (dwAttrib & FILE_ATTRIBUTE_DIRECTORY)); #endif return ret & !gIsProject(path); }
int glue_saveProject(const char *folderPath, const char *projName) { if (gIsProject(folderPath)) { puts("[glue] the project folder already exists"); // don't exit } else if (!gMkdir(folderPath)) { puts("[glue] unable to make project directory!"); return 0; } /* copy all samples inside the folder. Takes and logical ones are saved * with glue_saveSample() */ for (int i=0; i<MAX_NUM_CHAN; i++) { if (G_Mixer.chan[i] == NULL) continue; /* update the new samplePath: everything now comes from the project folder */ char samplePath[PATH_MAX]; sprintf(samplePath, "%s/%s.wav", folderPath, G_Mixer.chan[i]->name.c_str()); /* remove any existing file */ if (gFileExists(samplePath)) remove(samplePath); if (glue_saveSample(i, samplePath)) G_Mixer.chan[i]->pathfile = samplePath; } std::string projNameClean = stripExt(projName); char gptcPath[PATH_MAX]; sprintf(gptcPath, "%s/%s.gptc", folderPath, projNameClean.c_str()); glue_savePatch(gptcPath, projName); return 1; }
void gdBrowser::__cb_save_sample() { if (strcmp(name->value(), "") == 0) { /// FIXME glue business gdAlert("Please choose a file name."); return; } /* bruteforce check extension. */ std::string filename = gStripExt(name->value()); char fullpath[PATH_MAX]; sprintf(fullpath, "%s/%s.wav", where->value(), filename.c_str()); if (gFileExists(fullpath)) if (!gdConfirmWin("Warning", "File exists: overwrite?")) return; if (((SampleChannel*)ch)->save(fullpath)) do_callback(); else gdAlert("Unable to save this sample!"); }
void gdBrowser::__cb_save_patch() { if (strcmp(name->value(), "") == 0) { /// FIXME glue business gdAlert("Please choose a file name."); return; } /* if name->value() contains ".gptc" */ char ext[6] = ".gptc"; if (strstr(name->value(), ".gptc") != NULL) ext[0] = '\0'; char fullpath[PATH_MAX]; sprintf(fullpath, "%s/%s%s", where->value(), name->value(), ext); if (gFileExists(fullpath)) if (!gdConfirmWin("Warning", "File exists: overwrite?")) return; if (glue_savePatch(fullpath, name->value(), false)) // false == not a project do_callback(); else gdAlert("Unable to save the patch!"); }