Skip to content

Commit

Permalink
Merge pull request #60 from deadlydog:AllowUrlEncodingOfPaths
Browse files Browse the repository at this point in the history
Features:

- Add new URL Encode Paths option for the both the GUI and command line app.
- Reset Options button now also clears out grid sorting, since there's no native way to do with using the mouse or keyboard.
- Update UI to group Search Options and Replacement Options separately.
  • Loading branch information
deadlydog authored Feb 21, 2021
2 parents d89f503 + cc33185 commit 25bf082
Show file tree
Hide file tree
Showing 10 changed files with 185 additions and 113 deletions.
8 changes: 8 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## v1.11.0 - February 20, 2021

Features:

- Add new URL Encode Paths option for the both the GUI and command line app.
- Reset Options button now also clears out grid sorting, since there's no native way to do with using the mouse or keyboard.
- Update UI to group Search Options and Replacement Options separately.

## v1.10.0 - February 20, 2021

Features:
Expand Down
2 changes: 1 addition & 1 deletion build/azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ variables:
buildConfiguration: 'Release'
appBinariesDirectory: 'src\PathLengthCheckerGUI\bin\$(buildConfiguration)'

version.MajorMinor: '1.10' # Manually adjust the version number as needed for semantic versioning. Revision is auto-incremented.
version.MajorMinor: '1.11' # Manually adjust the version number as needed for semantic versioning. Revision is auto-incremented.
version.Revision: $[counter(variables['version.MajorMinor'], 0)]
versionNumber: '$(version.MajorMinor).$(version.Revision)'

Expand Down
5 changes: 5 additions & 0 deletions src/PathLengthChecker/ArgumentParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class ArgumentParser
"SearchPattern= | The pattern to match files against. '*' is a wildcard character. Default is '*' to match against everything.\n" +
"MinLength= | An integer indicating the minimum length that a path must contain in order to be returned in the results. Default is -1 to ignore this flag.\n" +
"MaxLength= | An integer indicating the maximum length that a path may have in order to be returned in the results. Default is -1 to ignore this flag.\n" +
"UrlEncodePaths=[True|False] | If true the paths returned will be URL encoded. e.g. Spaces will be replaced with %20, backslashes with %5C, etc. Default is false.\n" +
"Output=[MinLength|MaxLength|All] | Indicates if you just want the Min/Max path length to be outputted, or if you want all of the paths to be outputted. Default is All.\n" +
"\n" +
"Example: PathLengthChecker.exe RootDirectory=\"C:\\MyDir\" TypesToInclude=OnlyFiles SearchPattern=*FindThis* MinLength=25";
Expand Down Expand Up @@ -76,6 +77,10 @@ public static PathLengthSearchOptions ParseArgs(IEnumerable<string> args)
if (int.TryParse(value, out maxLength))
searchOptions.MaximumPathLength = maxLength;
break;
case "UrlEncodePaths":
if (string.Equals(value, "True", StringComparison.OrdinalIgnoreCase))
searchOptions.UrlEncodePaths = true;
break;
case "Output":
OutputTypes outputType = OutputTypes.Paths;
if (Enum.TryParse(value, out outputType))
Expand Down
8 changes: 6 additions & 2 deletions src/PathLengthChecker/PathRetriever.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,14 @@ public static IEnumerable<string> GetPaths(PathSearchOptions searchOptions, Canc
if (cancellationToken.IsCancellationRequested)
yield break;

var transformedPath = path;
if (searchOptions.UrlEncodePaths)
transformedPath = System.Uri.EscapeDataString(path);

if (searchOptions.RootDirectoryReplacement == null)
yield return path;
yield return transformedPath;
else
yield return path.Replace(searchOptions.RootDirectory, searchOptions.RootDirectoryReplacement);
yield return transformedPath.Replace(searchOptions.RootDirectory, searchOptions.RootDirectoryReplacement);
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/PathLengthChecker/PathSearchOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,10 @@ public class PathSearchOptions
/// Specify null to leave the original paths unmodified.
/// </summary>
public string RootDirectoryReplacement = null;

/// <summary>
/// If true the returned paths will be URL encoded, such as replacing spaces with "%20".
/// </summary>
public bool UrlEncodePaths = false;
}
}
241 changes: 132 additions & 109 deletions src/PathLengthCheckerGUI/MainWindow.xaml

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion src/PathLengthCheckerGUI/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ private async Task BuildSearchOptionsAndGetPaths(string rootDirectory, string ro
SearchOption = (chkIncludeSubdirectories.IsChecked ?? false) ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly,
TypesToGet = (FileSystemTypes)cmbTypesToInclude.SelectedValue,
RootDirectoryReplacement = rootDirectoryReplacement,
UrlEncodePaths = (chkUrlEncodePaths.IsChecked ?? false),
MinimumPathLength = minPathLength,
MaximumPathLength = maxPathLength
};
Expand Down Expand Up @@ -439,14 +440,16 @@ protected internal void SetUIControlsFromSearchOptions(PathLengthSearchOptions a
txtReplaceRootDirectory.Text = argSearchOptions.RootDirectoryReplacement;
chkReplaceRootDirectory.IsChecked = true;
}
chkUrlEncodePaths.IsChecked = argSearchOptions.UrlEncodePaths;

numMinPathLength.Value = argSearchOptions.MinimumPathLength;
numMaxPathLength.Value = argSearchOptions.MaximumPathLength;
}

private void btnResetSearchOptions_Click(object sender, RoutedEventArgs e)
private void btnResetAllOptions_Click(object sender, RoutedEventArgs e)
{
ResetAllUiSearchOptionsToDefaultValues();
ResetGridSorting();
}

private void ResetAllUiSearchOptionsToDefaultValues()
Expand All @@ -464,6 +467,12 @@ private void ResetAllUiSearchOptionsToDefaultValues()

txtReplaceRootDirectory.Text = string.Empty;
chkReplaceRootDirectory.IsChecked = false;
chkUrlEncodePaths.IsChecked = false;
}

private void ResetGridSorting()
{
SetGridColumnSortDescriptions(Enumerable.Empty<SortDescription>());
}
}
}
12 changes: 12 additions & 0 deletions src/PathLengthCheckerGUI/Properties/Settings.Designer.cs

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

3 changes: 3 additions & 0 deletions src/PathLengthCheckerGUI/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,8 @@
<Setting Name="ResultsGridColumnSortDescriptionCollection" Type="System.ComponentModel.SortDescriptionCollection" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="SearchOption_UrlEncodePaths" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
</Settings>
</SettingsFile>
3 changes: 3 additions & 0 deletions src/PathLengthCheckerGUI/app.config
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
<setting name="SearchOption_RootDirectoryReplacementText" serializeAs="String">
<value />
</setting>
<setting name="SearchOption_UrlEncodePaths" serializeAs="String">
<value>False</value>
</setting>
</PathLengthCheckerGUI.Properties.Settings>
</userSettings>
</configuration>

0 comments on commit 25bf082

Please sign in to comment.