Skip to content

Commit

Permalink
Fix GetAllFilesOfExtension to skip folders that don't work.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnpierson committed Jul 17, 2023
1 parent f498184 commit e481853
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 8 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@
<data name="NotificationMsg" xml:space="preserve">
<value>The source folder contains {0} Dynamo graphs.</value>
</data>
<data name="NotificationMsgWarningTargetCannotBeSource" xml:space="preserve">
<value>Target path cannot be the same path as the source path!</value>
</data>
<data name="OptionalFixesMsg" xml:space="preserve">
<value>Optional</value>
</data>
Expand Down
43 changes: 41 additions & 2 deletions DynamoGraphMigrationAssistantViewExtension/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,50 @@ public static bool IsValidPath(string path)
/// <returns></returns>
public static IEnumerable<string> GetAllFilesOfExtension(string path, string extension = ".dyn")
{
var files = Directory.EnumerateFiles(path, "*.*", SearchOption.AllDirectories)
.Where(x => extension.Equals(Path.GetExtension(x).ToLowerInvariant()));
List<string> files = new List<string>();

var folders = ShowAllFoldersUnder(path);

foreach (var folder in folders)
{
try
{
files.AddRange(Directory.EnumerateFiles(folder, "*.*", SearchOption.TopDirectoryOnly)
.Where(x => extension.Equals(Path.GetExtension(x).ToLowerInvariant())));
}
catch (UnauthorizedAccessException) // ignore directories which the user does not have access to
{ }

}
return files;
}

public static List<string> ShowAllFoldersUnder(string path)
{
List<string> folders = new List<string>();
try
{
if ((File.GetAttributes(path) & FileAttributes.ReparsePoint)
!= FileAttributes.ReparsePoint)
{
foreach (string folder in Directory.GetDirectories(path))
{
folders.Add(folder);

ShowAllFoldersUnder(folder);
}
}
}
catch (UnauthorizedAccessException)
{

}

return folders;
}



/// <summary>
/// Returns the calculated version for the given graph path.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,8 @@ public GraphMigrationAssistantViewModel(ViewLoadedParams p)

_dispatcher.Hooks.DispatcherInactive += OnDispatcherFinished;

TargetPathViewModel.PropertyChanged += SourcePathPropertyChanged;
SourcePathViewModel.PropertyChanged += SourcePathPropertyChanged;
TargetPathViewModel.PropertyChanged += PathPropertyChanged;
SourcePathViewModel.PropertyChanged += PathPropertyChanged;

ExportGraphsCommand = new DelegateCommand(ExportGraphs);
CancelCommand = new DelegateCommand(Cancel);
Expand All @@ -383,8 +383,8 @@ public GraphMigrationAssistantViewModel(ViewLoadedParams p)



// Handles the source path being changed
private void SourcePathPropertyChanged(object sender, PropertyChangedEventArgs propertyChangedEventArgs)
// Handles the path being changed
private void PathPropertyChanged(object sender, PropertyChangedEventArgs propertyChangedEventArgs)
{
var pathVM = sender as PathViewModel;
if (pathVM == null) return;
Expand Down Expand Up @@ -486,6 +486,17 @@ private void SourceFolderChanged(PathViewModel pathVm)

private void TargetFolderChanged()
{
//throw error if the user picks the source path as the target path.
if (TargetPathViewModel.FolderPath.Equals(SourcePathViewModel.FolderPath))
{
NotificationMessage = Properties.Resources.NotificationMsgWarningTargetCannotBeSource;
TargetPathViewModel.FolderPath = string.Empty;
MessageBox.Show(Properties.Resources.NotificationMsgWarningTargetCannotBeSource);
return;
}



var log = GetLogFileInformation();

// Do not enqueue the file if it is already in the log file
Expand All @@ -499,6 +510,7 @@ private void TargetFolderChanged()

NotificationMessage = String.Format(Properties.Resources.NotificationMsg, Graphs.Count.ToString());
RaisePropertyChanged(nameof(Graphs));
RaisePropertyChanged(nameof(CanExport));
}

internal void CheckVersions()
Expand Down Expand Up @@ -1079,8 +1091,8 @@ private void Reset()
/// </summary>
public void Dispose()
{
TargetPathViewModel.PropertyChanged -= SourcePathPropertyChanged;
SourcePathViewModel.PropertyChanged -= SourcePathPropertyChanged;
TargetPathViewModel.PropertyChanged -=PathPropertyChanged;
SourcePathViewModel.PropertyChanged -= PathPropertyChanged;
_dispatcher.Hooks.DispatcherInactive -= OnDispatcherFinished;

CurrentWorkspace = null;
Expand Down

0 comments on commit e481853

Please sign in to comment.