+//
+// Find all disks images top level call
+//
+void DiskSelector::FindHardDisks(void)
+{
+ hdList.clear();
+ FindHardDisks(settings.disksPath);
+ std::sort(hdList.begin(), hdList.end(), FileStruct());
+ WriteLog("GUI (DiskSelector)::FindHardDisks(): # of HDs is %i\n", hdList.size());
+}
+
+
+//
+// Find all hard disk images within path (recursive call does depth first search)
+//
+void DiskSelector::FindHardDisks(const char * path)
+{
+ DIR * dir = opendir(path);
+
+ if (!dir)
+ {
+ WriteLog("GUI (DiskSelector)::FindHardDisks: Could not open directory \"%s\%!\n", path);
+ return;
+ }
+
+ dirent * ent;
+
+ while ((ent = readdir(dir)) != NULL)
+ {
+ char buf[0x10000];
+ sprintf(buf, "%s/%s", path, ent->d_name);
+
+ // Cross-platform way to test if it's a directory (test = NULL -> file)
+ DIR * test = opendir(buf);
+
+ if (test == NULL)
+ {
+ const char * ext = strrchr(ent->d_name, '.');
+
+ if ((ext != NULL) && (strcasecmp(ext, ".2mg") == 0))
+ {
+ FileStruct fs;
+ fs.image = ent->d_name;
+ fs.fullPath = buf;
+ hdList.push_back(fs);
+ }
+ }
+ else
+ {
+ // Make sure we close the thing, since it's a bona-fide dir!
+ closedir(test);
+
+ // Only recurse if the directory is not one of the special ones...
+ if ((strcmp(ent->d_name, "..") != 0)
+ && (strcmp(ent->d_name, ".") != 0))
+ {
+ FindHardDisks(buf);
+ }
+ }
+ }
+
+ closedir(dir);
+}
+
+