/// <summary> /// Searches all the files, starting from a user-selected directory, for the filename /// specified by 'uri'</summary> /// <param name="uri"></param> /// <param name="newUri">either 'uri' or a replacement URI</param> /// <param name="askUser">asks the user for the search directory. If false, the user /// will only be asked the first time.</param> /// <returns>true if a replacement was chosen, otherwise false</returns> private static bool SearchForFile(Uri uri, out Uri newUri, bool askUser) { // default return value newUri = uri; // ask the user for a directory to search in or use last search bool doSearch = true; if (askUser || s_searchRoot == string.Empty) { var dlg = new BrowseForFolderDialog { InitialFolder = s_searchRoot != string.Empty ? s_searchRoot : Directory.GetCurrentDirectory() }; if (dlg.ShowDialog(Application.Current.MainWindow) == true) { s_searchRoot = dlg.SelectedFolder; } else { doSearch = false; } } // do the search and if successful, add the result to our mapping if (doSearch) { string searchName = Path.GetFileName(uri.LocalPath); foreach (string newPath in DirectoryUtil.GetFilesIteratively(s_searchRoot, searchName)) { // The search can be stopped after the first match. newUri = new Uri(newPath); s_localPathMap.Add(uri.LocalPath, newUri); return(true); } } return(false); }