// ------------------------------------------------------ // Fill the list with the content of the relevant directory void Read_SMPT(void) { int i; lt_items[Scopish] = 0; list_counter[Scopish] = 0; #if defined(__WIN32__) struct _finddata_t c_file; #endif long hFile; nbr_dirs = 0; switch(Scopish) { case SCOPE_ZONE_MOD_DIR: cur_dir = Dir_Mods; break; case SCOPE_ZONE_INSTR_DIR: cur_dir = Dir_Instrs; break; case SCOPE_ZONE_PRESET_DIR: cur_dir = Dir_Presets; break; case SCOPE_ZONE_REVERB_DIR: cur_dir = Dir_Reverbs; break; case SCOPE_ZONE_PATTERN_DIR: cur_dir = Dir_Patterns; break; case SCOPE_ZONE_SAMPLE_DIR: cur_dir = Dir_Samples; break; case SCOPE_ZONE_MIDICFG_DIR: cur_dir = Dir_MidiCfg; break; } CHDIR(cur_dir); // Find first .c file in current directory strcpy(Dir_Act, cur_dir); #if defined(__WIN32__) strcat(Dir_Act, "\\*.*"); if((hFile = _findfirst(Dir_Act, &c_file)) == -1L) { Add_Entry("No files in current directory.", 0); } else { // The first directory if(c_file.attrib & _A_SUBDIR) { if(strcmp(c_file.name, ".") && strcmp(c_file.name, "..")) { nbr_dirs++; Add_Entry(c_file.name, _A_SUBDIR); } } // Find the rest of the directories while(_findnext(hFile, &c_file) == 0) { if(c_file.attrib & _A_SUBDIR) { if(strcmp(c_file.name, ".") && strcmp(c_file.name, "..")) { nbr_dirs++; Add_Entry(c_file.name, _A_SUBDIR); } } } // End dir _findclose(hFile); if((hFile = _findfirst(Dir_Act, &c_file)) != -1L) { // The first file if(!(c_file.attrib & _A_SUBDIR)) { Add_Entry(c_file.name, 0); } // Find the rest of the files while(_findnext(hFile, &c_file) == 0) { if(!(c_file.attrib & _A_SUBDIR)) { Add_Entry(c_file.name, 0); } } // while _findclose(hFile); if(sort_files) { qsort(&SMPT_LIST[0], list_counter[Scopish], sizeof(FILEENTRY), &FileComp_Files); //Insert_List_Separators(); } //else { Insert_Entry("", _A_SEP, 0); } Insert_Entry("..", _A_SUBDIR, 0); Insert_Entry(".", _A_SUBDIR, 0); } } // Add the available drives to the bottom of the list char *Ptr_Drives; GetLogicalDriveStrings(1024, List_Drives); Ptr_Drives = List_Drives; i = 0; if(Ptr_Drives[0]) Add_Entry("", _A_SEP); while(Ptr_Drives[0]) { Add_Entry(Ptr_Drives, _A_SUBDIR); Ptr_Drives += strlen(Ptr_Drives) + 1; } #elif defined(__AMIGAOS4__) || defined(__AROS__) #if defined(__AMIGAOS4__) #define LockDosList(f) IDOS->LockDosList(f) #define NextDosEntry(d,f) IDOS->NextDosEntry(d, f) #define CopyStringBSTRToC(bin,sout,len) IDOS->CopyStringBSTRToC(bin, sout, len) #define UnLockDosList(f) IDOS->UnLockDosList(f) #endif if (!strcmp(Dir_Act, "/")) { // Only display volumes struct DosList *dl; const uint32 flags = LDF_VOLUMES | LDF_READ; char BString[1024]; dl = LockDosList(flags); while ((dl = NextDosEntry(dl, flags)) != NULL) { // Convert it first CopyStringBSTRToC(dl->dol_Name, BString, sizeof(BString)); Add_Entry(BString, _A_SUBDIR); } UnLockDosList(flags); } else { DIR *dirp; struct dirent *dp; dirp = opendir(Dir_Act); if (dirp) { // Add the directories first while ((dp = readdir(dirp)) != NULL) { if(dp->d_type == DT_DIR) { nbr_dirs++; Add_Entry(dp->d_name, _A_SUBDIR); } } closedir(dirp); } dirp = opendir(Dir_Act); if (dirp) { // Then add the files while ((dp = readdir(dirp)) != NULL) { if(dp->d_type != DT_DIR) { Add_Entry(dp->d_name, 0); } } closedir(dirp); } if(sort_files) { qsort(&SMPT_LIST[0], list_counter[Scopish], sizeof(FILEENTRY), &FileComp_Files); //Insert_List_Separators(); } //else { Insert_Entry("", _A_SEP, 0); } // Insert parent directory at the top Insert_Entry("/", _A_SUBDIR, 0); } #else // Enum them nftw(Dir_Act, &list_file, FTW_PHYS, 0); if(sort_files) { qsort(&SMPT_LIST[0], list_counter[Scopish], sizeof(FILEENTRY), &FileComp_Files); //Insert_List_Separators(); } //else { Insert_Entry("", _A_SEP, 0); } // Always insert them at the top of the list Insert_Entry("../", _A_SUBDIR, 0); Insert_Entry("./", _A_SUBDIR, 0); #endif // Insert a separator between files and directories if(nbr_dirs) { for(i = list_counter[Scopish] - 1; i >= 0; i--) { if(SMPT_LIST[i].Type == _A_FILE) { Insert_Entry("", _A_SEP, i + 1); break; } } } }
BOOL FileNameComplete(Object *obj, BOOL backwards, struct InstData *data) { BOOL edited = FALSE; ENTER(); if(data->FNCBuffer != NULL) { if(data->FileEntries == 1) { DisplayBeep(NULL); } else { if(backwards) { if(--data->FileNumber < 0) data->FileNumber = data->FileEntries-1; } else { if(++data->FileNumber >= data->FileEntries) data->FileNumber = 0; } } InsertFileName(data->FileNameStart, data); edited = TRUE; } else { LONG pos = DoMethod(obj, MUIM_BetterString_FileNameStart, data->Contents, data->BufferPos); switch(pos) { case MUIR_BetterString_FileNameStart_Volume: { struct DosList *dl; STRPTR volumeName = NULL; char tmpBuffer[256]; UWORD cut; pos = VolumeStart(data->Contents, data->BufferPos); if((cut = data->BufferPos-pos) != 0) { dl = LockDosList(LDF_READ|LDF_DEVICES|LDF_VOLUMES|LDF_ASSIGNS); while((dl = NextDosEntry(dl, LDF_READ|LDF_DEVICES|LDF_VOLUMES|LDF_ASSIGNS)) != NULL) { #ifdef __AROS__ strlcpy(tmpBuffer, dl->dol_Ext.dol_AROS.dol_DevName, sizeof tmpBuffer); #else // dol_Name is a BSTR, we have to convert it to a regular C string char *bstr = BADDR(dl->dol_Name); // a BSTR cannot exceed 255 characters, hence the buffer size of 256 is enough in any case strlcpy(tmpBuffer, &bstr[1], (unsigned char)bstr[0]); #endif if(Strnicmp(tmpBuffer, data->Contents+pos, cut) == 0) { volumeName = tmpBuffer; break; } } if(volumeName != NULL) { if(OverwriteA(volumeName, pos, cut, strlen(volumeName)+1, data)) data->Contents[data->BufferPos-1] = ':'; edited = TRUE; } UnLockDosList(LDF_READ|LDF_DEVICES|LDF_VOLUMES|LDF_ASSIGNS); } } break; default: { struct FNCData *fncbuffer; struct FNCData *fncframe; struct ExAllControl *control; BPTR dirlock; char pattern[42]; UWORD namestart = data->BufferPos; char oldletter = '\0'; BOOL filename = TRUE; while(filename) { switch(*(data->Contents+namestart-1)) { case '/': case ':': filename = FALSE; break; default: namestart--; break; } } if((data->BufferPos-namestart) < 32) { strlcpy(pattern, data->Contents+namestart, sizeof(pattern)); strlcat(pattern, "~(#?.info)", sizeof(pattern)); oldletter = data->Contents[namestart]; data->Contents[namestart] = '\0'; if((fncbuffer = (struct FNCData *)SharedPoolAlloc(4100)) != NULL) { fncbuffer->next = NULL; if((control = (struct ExAllControl *)AllocDosObject(DOS_EXALLCONTROL, NULL))) { char tokenized[sizeof(pattern) * 2 + 2]; if(ParsePatternNoCase(pattern, tokenized, sizeof(tokenized)) != -1) control->eac_MatchString = tokenized; if((dirlock = Lock(data->Contents+pos, ACCESS_READ))) { UWORD entries = 0; fncframe = fncbuffer; while(fncframe && ExAll(dirlock, &fncframe->buffer, 4096, ED_TYPE, control)) { entries += control->eac_Entries; if((fncframe->next = (struct FNCData *)SharedPoolAlloc(4100))) fncframe->next->next = NULL; fncframe = fncframe->next; } control->eac_Entries += entries; data->FileNumber = backwards ? control->eac_Entries-1 : 0; data->FileEntries = control->eac_Entries; data->FileNameStart = namestart; data->FNCBuffer = fncbuffer; if(control->eac_Entries) { data->Contents[namestart] = oldletter; InsertFileName(namestart, data); edited = TRUE; } UnLock(dirlock); } else { SharedPoolFree(fncbuffer); } FreeDosObject(DOS_EXALLCONTROL, (APTR)control); } } } if(edited == FALSE) data->Contents[namestart] = oldletter; } break; } } RETURN(edited); return edited; }