Przeglądaj źródła

fox model scanning #35

AI Agent 001 3 miesięcy temu
rodzic
commit
65da3b2a63
1 zmienionych plików z 42 dodań i 31 usunięć
  1. 42 31
      src/model_manager.cpp

+ 42 - 31
src/model_manager.cpp

@@ -197,38 +197,46 @@ public:
 
         // If in legacy mode or no configured directories matched, check default directory structure
         if (legacyMode || modelTypeDirectories.empty()) {
-            std::string parentPath = filePath.parent_path().filename().string();
-            std::transform(parentPath.begin(), parentPath.end(), parentPath.begin(), ::tolower);
-
-            // Check default directory names
-            if (parentPath == "checkpoints" || parentPath == "stable-diffusion") {
-                if (isExtensionMatch(extension, ModelType::CHECKPOINT)) {
-                    return ModelType::CHECKPOINT;
-                }
-            } else if (parentPath == "controlnet") {
-                if (isExtensionMatch(extension, ModelType::CONTROLNET)) {
-                    return ModelType::CONTROLNET;
-                }
-            } else if (parentPath == "lora") {
-                if (isExtensionMatch(extension, ModelType::LORA)) {
-                    return ModelType::LORA;
-                }
-            } else if (parentPath == "vae") {
-                if (isExtensionMatch(extension, ModelType::VAE)) {
-                    return ModelType::VAE;
-                }
-            } else if (parentPath == "taesd") {
-                if (isExtensionMatch(extension, ModelType::TAESD)) {
-                    return ModelType::TAESD;
-                }
-            } else if (parentPath == "esrgan" || parentPath == "upscaler") {
-                if (isExtensionMatch(extension, ModelType::ESRGAN)) {
-                    return ModelType::ESRGAN;
-                }
-            } else if (parentPath == "embeddings" || parentPath == "textual-inversion") {
-                if (isExtensionMatch(extension, ModelType::EMBEDDING)) {
-                    return ModelType::EMBEDDING;
+            // Check the entire path hierarchy for model type directories
+            fs::path currentPath = filePath.parent_path();
+            
+            while (currentPath.has_filename()) {
+                std::string dirName = currentPath.filename().string();
+                std::transform(dirName.begin(), dirName.end(), dirName.begin(), ::tolower);
+
+                // Check default directory names
+                if (dirName == "checkpoints" || dirName == "stable-diffusion") {
+                    if (isExtensionMatch(extension, ModelType::CHECKPOINT)) {
+                        return ModelType::CHECKPOINT;
+                    }
+                } else if (dirName == "controlnet") {
+                    if (isExtensionMatch(extension, ModelType::CONTROLNET)) {
+                        return ModelType::CONTROLNET;
+                    }
+                } else if (dirName == "lora") {
+                    if (isExtensionMatch(extension, ModelType::LORA)) {
+                        return ModelType::LORA;
+                    }
+                } else if (dirName == "vae") {
+                    if (isExtensionMatch(extension, ModelType::VAE)) {
+                        return ModelType::VAE;
+                    }
+                } else if (dirName == "taesd") {
+                    if (isExtensionMatch(extension, ModelType::TAESD)) {
+                        return ModelType::TAESD;
+                    }
+                } else if (dirName == "esrgan" || dirName == "upscaler") {
+                    if (isExtensionMatch(extension, ModelType::ESRGAN)) {
+                        return ModelType::ESRGAN;
+                    }
+                } else if (dirName == "embeddings" || dirName == "textual-inversion") {
+                    if (isExtensionMatch(extension, ModelType::EMBEDDING)) {
+                        return ModelType::EMBEDDING;
+                    }
                 }
+                
+                // Move up to parent directory
+                currentPath = currentPath.parent_path();
             }
         }
 
@@ -315,6 +323,9 @@ public:
                         // Calculate relative path from the scanned directory (not base models directory)
                         fs::path relativePath = fs::relative(filePath, directory);
                         std::string modelName = relativePath.string();
+                        
+                        // Normalize path separators for consistency
+                        std::replace(modelName.begin(), modelName.end(), '\\', '/');
 
                         // Check if model already exists to avoid duplicates
                         if (modelsMap.find(modelName) == modelsMap.end()) {