private async void SetAssetCollection() { try { // indicate we are doing something AssetSpinnerVisibility = Visibility.Visible; MissingSpinnerVisibility = Visibility.Visible; // get the assets in the project directory on disk Status.Text = "Scanning project directory"; var projectFolderFiles = AssetWrangler.GetProjectFiles(_maxFileFolderPath); _logger.Debug($"found '{projectFolderFiles.Keys.Count}' files in the project directory: '{_maxFileFolderPath}'"); // process the scene files and any missing assets await ProcessSceneFiles(projectFolderFiles); // find and add any missing assets to the list await ProcessMissingAssets(); Status.Text = "Asset scanning completed"; SetButtonState(true); } catch (Exception ex) { _logger.Error($"Failed to get or display assets from scene: {ex.Message}. {ex}"); } }
/// <summary> /// Get the assets from the scene and make sure they exist in the project directory. Any /// that don't add them to the missing asset list. Any folders we encounter we add to the /// asset folder list. /// </summary> /// <param name="projectFolderFiles"></param> private async Task <bool> ProcessSceneFiles(IReadOnlyDictionary <string, List <string> > projectFolderFiles) { Status.Text = "Loading assets from the scene file, this can take a while"; var sceneFiles = await _maxRequestHandler.GetFoundSceneAssets(); // TODO: Debug ... remove foreach log. _logger.Debug($"found '{sceneFiles.Count}' scene assets"); foreach (var asset in sceneFiles) { var assetName = Path.GetFileName(asset.FileName) ?? ""; if (projectFolderFiles.ContainsKey(assetName)) { // found a file with the same name in the project directory, get the locations as it could exist in more than one folder on disk var locations = projectFolderFiles[assetName]; if (string.IsNullOrEmpty(locations.Find(file => file == asset.FullFilePath))) { // the filename exists in the project direrctory, but not with the same path // see if we can match up any directories and make a guess if its the correct one. _logger.Debug($"Did not find: {asset.FullFilePath}, locations: {locations.Count}"); var matchingDirCount = AssetWrangler.FindMatchingDirectories(asset.FullFilePath, locations); if (matchingDirCount == 0) { // add it to the missing asset list for the user to find MissingAssets.Add(asset); _logger.Debug($"Add to missing asset list: {asset.FileName} :: {asset.FullFilePath}"); } else { _logger.Debug($"Found partial match for [{asset.FullFilePath}] in [{string.Join(":::", locations)}] with '{matchingDirCount}' matching dirs"); } } else { // no else needed as we found it and it matches the path. do nothing. _logger.Debug($"Found in project directory: {asset.FullFilePath}"); } } else { // asset was not found in project directory, but Max has a reference to it elsewhere. add folder to collection _logger.Debug($"Asset '{assetName}' was not found in project directory, but Max has a reference to it elsewhere: [{asset.FullFilePath}] -> [{asset.FileName}]"); SafeAddAssetFolder(Path.GetDirectoryName(asset.FullFilePath)); } } AssetSpinnerVisibility = Visibility.Collapsed; return(true); }