Skip to content
This repository was archived by the owner on Jul 6, 2020. It is now read-only.

Commit 87d0720

Browse files
committed
Added output folder.
1 parent 95f93b1 commit 87d0720

File tree

10 files changed

+230
-22
lines changed

10 files changed

+230
-22
lines changed

.nuget/NuGet.Config

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<solution>
4+
<add key="disableSourceControlIntegration" value="true" />
5+
</solution>
6+
</configuration>

.nuget/NuGet.exe

1.59 MB
Binary file not shown.

.nuget/NuGet.targets

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">$(MSBuildProjectDirectory)\..\</SolutionDir>
5+
6+
<!-- Enable the restore command to run before builds -->
7+
<RestorePackages Condition=" '$(RestorePackages)' == '' ">false</RestorePackages>
8+
9+
<!-- Property that enables building a package from a project -->
10+
<BuildPackage Condition=" '$(BuildPackage)' == '' ">false</BuildPackage>
11+
12+
<!-- Determines if package restore consent is required to restore packages -->
13+
<RequireRestoreConsent Condition=" '$(RequireRestoreConsent)' != 'false' ">true</RequireRestoreConsent>
14+
15+
<!-- Download NuGet.exe if it does not already exist -->
16+
<DownloadNuGetExe Condition=" '$(DownloadNuGetExe)' == '' ">true</DownloadNuGetExe>
17+
</PropertyGroup>
18+
19+
<ItemGroup Condition=" '$(PackageSources)' == '' ">
20+
<!-- Package sources used to restore packages. By default, registered sources under %APPDATA%\NuGet\NuGet.Config will be used -->
21+
<!-- The official NuGet package source (https://www.nuget.org/api/v2/) will be excluded if package sources are specified and it does not appear in the list -->
22+
<!--
23+
<PackageSource Include="https://www.nuget.org/api/v2/" />
24+
<PackageSource Include="https://my-nuget-source/nuget/" />
25+
-->
26+
</ItemGroup>
27+
28+
<PropertyGroup Condition=" '$(OS)' == 'Windows_NT'">
29+
<!-- Windows specific commands -->
30+
<NuGetToolsPath>$([System.IO.Path]::Combine($(SolutionDir), ".nuget"))</NuGetToolsPath>
31+
</PropertyGroup>
32+
33+
<PropertyGroup Condition=" '$(OS)' != 'Windows_NT'">
34+
<!-- We need to launch nuget.exe with the mono command if we're not on windows -->
35+
<NuGetToolsPath>$(SolutionDir).nuget</NuGetToolsPath>
36+
</PropertyGroup>
37+
38+
<PropertyGroup>
39+
<PackagesProjectConfig Condition=" '$(OS)' == 'Windows_NT'">$(MSBuildProjectDirectory)\packages.$(MSBuildProjectName.Replace(' ', '_')).config</PackagesProjectConfig>
40+
<PackagesProjectConfig Condition=" '$(OS)' != 'Windows_NT'">$(MSBuildProjectDirectory)\packages.$(MSBuildProjectName).config</PackagesProjectConfig>
41+
</PropertyGroup>
42+
43+
<PropertyGroup>
44+
<PackagesConfig Condition="Exists('$(MSBuildProjectDirectory)\packages.config')">$(MSBuildProjectDirectory)\packages.config</PackagesConfig>
45+
<PackagesConfig Condition="Exists('$(PackagesProjectConfig)')">$(PackagesProjectConfig)</PackagesConfig>
46+
</PropertyGroup>
47+
48+
<PropertyGroup>
49+
<!-- NuGet command -->
50+
<NuGetExePath Condition=" '$(NuGetExePath)' == '' ">$(NuGetToolsPath)\NuGet.exe</NuGetExePath>
51+
<PackageSources Condition=" $(PackageSources) == '' ">@(PackageSource)</PackageSources>
52+
53+
<NuGetCommand Condition=" '$(OS)' == 'Windows_NT'">"$(NuGetExePath)"</NuGetCommand>
54+
<NuGetCommand Condition=" '$(OS)' != 'Windows_NT' ">mono --runtime=v4.0.30319 "$(NuGetExePath)"</NuGetCommand>
55+
56+
<PackageOutputDir Condition="$(PackageOutputDir) == ''">$(TargetDir.Trim('\\'))</PackageOutputDir>
57+
58+
<RequireConsentSwitch Condition=" $(RequireRestoreConsent) == 'true' ">-RequireConsent</RequireConsentSwitch>
59+
<NonInteractiveSwitch Condition=" '$(VisualStudioVersion)' != '' AND '$(OS)' == 'Windows_NT' ">-NonInteractive</NonInteractiveSwitch>
60+
61+
<PaddedSolutionDir Condition=" '$(OS)' == 'Windows_NT'">"$(SolutionDir) "</PaddedSolutionDir>
62+
<PaddedSolutionDir Condition=" '$(OS)' != 'Windows_NT' ">"$(SolutionDir)"</PaddedSolutionDir>
63+
64+
<!-- Commands -->
65+
<RestoreCommand>$(NuGetCommand) install "$(PackagesConfig)" -source "$(PackageSources)" $(NonInteractiveSwitch) $(RequireConsentSwitch) -solutionDir $(PaddedSolutionDir)</RestoreCommand>
66+
<BuildCommand>$(NuGetCommand) pack "$(ProjectPath)" -Properties "Configuration=$(Configuration);Platform=$(Platform)" $(NonInteractiveSwitch) -OutputDirectory "$(PackageOutputDir)" -symbols</BuildCommand>
67+
68+
<!-- We need to ensure packages are restored prior to assembly resolve -->
69+
<BuildDependsOn Condition="$(RestorePackages) == 'true'">
70+
RestorePackages;
71+
$(BuildDependsOn);
72+
</BuildDependsOn>
73+
74+
<!-- Make the build depend on restore packages -->
75+
<BuildDependsOn Condition="$(BuildPackage) == 'true'">
76+
$(BuildDependsOn);
77+
BuildPackage;
78+
</BuildDependsOn>
79+
</PropertyGroup>
80+
81+
<Target Name="CheckPrerequisites">
82+
<!-- Raise an error if we're unable to locate nuget.exe -->
83+
<Error Condition="'$(DownloadNuGetExe)' != 'true' AND !Exists('$(NuGetExePath)')" Text="Unable to locate '$(NuGetExePath)'" />
84+
<!--
85+
Take advantage of MsBuild's build dependency tracking to make sure that we only ever download nuget.exe once.
86+
This effectively acts as a lock that makes sure that the download operation will only happen once and all
87+
parallel builds will have to wait for it to complete.
88+
-->
89+
<MsBuild Targets="_DownloadNuGet" Projects="$(MSBuildThisFileFullPath)" Properties="Configuration=NOT_IMPORTANT;DownloadNuGetExe=$(DownloadNuGetExe)" />
90+
</Target>
91+
92+
<Target Name="_DownloadNuGet">
93+
<DownloadNuGet OutputFilename="$(NuGetExePath)" Condition=" '$(DownloadNuGetExe)' == 'true' AND !Exists('$(NuGetExePath)')" />
94+
</Target>
95+
96+
<Target Name="RestorePackages" DependsOnTargets="CheckPrerequisites">
97+
<Exec Command="$(RestoreCommand)"
98+
Condition="'$(OS)' != 'Windows_NT' And Exists('$(PackagesConfig)')" />
99+
100+
<Exec Command="$(RestoreCommand)"
101+
LogStandardErrorAsError="true"
102+
Condition="'$(OS)' == 'Windows_NT' And Exists('$(PackagesConfig)')" />
103+
</Target>
104+
105+
<Target Name="BuildPackage" DependsOnTargets="CheckPrerequisites">
106+
<Exec Command="$(BuildCommand)"
107+
Condition=" '$(OS)' != 'Windows_NT' " />
108+
109+
<Exec Command="$(BuildCommand)"
110+
LogStandardErrorAsError="true"
111+
Condition=" '$(OS)' == 'Windows_NT' " />
112+
</Target>
113+
114+
<UsingTask TaskName="DownloadNuGet" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
115+
<ParameterGroup>
116+
<OutputFilename ParameterType="System.String" Required="true" />
117+
</ParameterGroup>
118+
<Task>
119+
<Reference Include="System.Core" />
120+
<Using Namespace="System" />
121+
<Using Namespace="System.IO" />
122+
<Using Namespace="System.Net" />
123+
<Using Namespace="Microsoft.Build.Framework" />
124+
<Using Namespace="Microsoft.Build.Utilities" />
125+
<Code Type="Fragment" Language="cs">
126+
<![CDATA[
127+
try {
128+
OutputFilename = Path.GetFullPath(OutputFilename);
129+
130+
Log.LogMessage("Downloading latest version of NuGet.exe...");
131+
WebClient webClient = new WebClient();
132+
webClient.DownloadFile("https://www.nuget.org/nuget.exe", OutputFilename);
133+
134+
return true;
135+
}
136+
catch (Exception ex) {
137+
Log.LogErrorFromException(ex);
138+
return false;
139+
}
140+
]]>
141+
</Code>
142+
</Task>
143+
</UsingTask>
144+
</Project>

RemovePdfLinks.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
1212
README.md = README.md
1313
EndProjectSection
1414
EndProject
15+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{F1978155-B223-4BDC-9A47-89A3B45005B0}"
16+
ProjectSection(SolutionItems) = preProject
17+
.nuget\NuGet.Config = .nuget\NuGet.Config
18+
.nuget\NuGet.exe = .nuget\NuGet.exe
19+
.nuget\NuGet.targets = .nuget\NuGet.targets
20+
EndProjectSection
21+
EndProject
1522
Global
1623
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1724
Release|Any CPU = Release|Any CPU

RemovePdfLinks/MainWindow.xaml

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
xmlns:utils="clr-namespace:RemovePdfLinks.Utils"
77
WindowStartupLocation="CenterScreen"
88
ResizeMode="CanMinimize"
9-
Title="Remove Pdf Links" Height="215" Width="525">
9+
Title="Remove Pdf Links" Height="242" Width="525">
1010
<Window.Resources>
1111
<viewModels:MainWindowViewModel x:Key="MainWindowViewModel" />
1212
</Window.Resources>
@@ -27,20 +27,40 @@
2727
<ColumnDefinition Width="*"/>
2828
<ColumnDefinition Width="Auto"/>
2929
</Grid.ColumnDefinitions>
30-
<TextBlock Text="Folder Path:" Margin="2" Grid.Column="0"/>
31-
<TextBox Margin="2" Grid.Column="1"
32-
Text="{Binding GuiModelData.FolderPath, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
33-
<Button Width="20" x:Name="BtnChooseFolder"
30+
<Grid.RowDefinitions>
31+
<RowDefinition Height="Auto"/>
32+
<RowDefinition Height="Auto"/>
33+
</Grid.RowDefinitions>
34+
<TextBlock Text="Input Folder Path:" Margin="2" Grid.Column="0" Grid.Row="0"/>
35+
<TextBox Margin="2" Grid.Column="1" Grid.Row="0"
36+
Text="{Binding GuiModelData.InputFolderPath, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
37+
<Button Width="20" Grid.Row="0"
3438
ToolTip="Select ..." Content="..." Margin="2" Grid.Column="2">
3539
<i:Interaction.Triggers>
3640
<i:EventTrigger EventName="Click">
3741
<utils:FolderBrowserDialogBehavior
3842
FolderBrowserDescription="Select a folder"
39-
FolderBrowserDialogResultCommand="{Binding GuiModelData.FolderPath, Mode=TwoWay}"
43+
FolderBrowserDialogResultCommand="{Binding GuiModelData.InputFolderPath, Mode=TwoWay}"
4044
/>
4145
</i:EventTrigger>
4246
</i:Interaction.Triggers>
4347
</Button>
48+
49+
<TextBlock Text="Output Folder Path:" Margin="2" Grid.Column="0" Grid.Row="1"/>
50+
<TextBox Margin="2" Grid.Column="1" Grid.Row="1"
51+
Text="{Binding GuiModelData.OutputFolderPath, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
52+
<Button Width="20" Grid.Row="1"
53+
ToolTip="Select ..." Content="..." Margin="2" Grid.Column="2">
54+
<i:Interaction.Triggers>
55+
<i:EventTrigger EventName="Click">
56+
<utils:FolderBrowserDialogBehavior
57+
FolderBrowserDescription="Select a folder"
58+
FolderBrowserDialogResultCommand="{Binding GuiModelData.OutputFolderPath, Mode=TwoWay}"
59+
/>
60+
</i:EventTrigger>
61+
</i:Interaction.Triggers>
62+
</Button>
63+
4464
</Grid>
4565
</GroupBox>
4666

RemovePdfLinks/Models/GuiModel.cs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
using System.ComponentModel;
2+
using System.IO;
3+
using System.Windows.Forms;
24

35
namespace RemovePdfLinks.Models
46
{
57
public class GuiModel : INotifyPropertyChanged
68
{
7-
private string _folderPath;
9+
private string _inputFolderPath;
810
private string _newUrl = "http://www.site.com";
11+
private string _outputFolderPath = Path.Combine(Application.StartupPath, "Mod");
912
private bool _removeAllLinks = true;
1013

1114
public event PropertyChangedEventHandler PropertyChanged;
1215

13-
public string FolderPath
16+
public string InputFolderPath
1417
{
15-
get { return _folderPath; }
18+
get { return _inputFolderPath; }
1619
set
1720
{
18-
_folderPath = value;
19-
notifyPropertyChanged("FolderPath");
21+
_inputFolderPath = value;
22+
notifyPropertyChanged("InputFolderPath");
2023
}
2124
}
2225

@@ -30,6 +33,16 @@ public string NewUrl
3033
}
3134
}
3235

36+
public string OutputFolderPath
37+
{
38+
get { return _outputFolderPath; }
39+
set
40+
{
41+
_outputFolderPath = value;
42+
notifyPropertyChanged("OutputFolderPath");
43+
}
44+
}
45+
3346
public bool RemoveAllLinks
3447
{
3548
get { return _removeAllLinks; }

RemovePdfLinks/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,5 @@
5151
// You can specify all the values or you can default the Build and Revision Numbers
5252
// by using the '*' as shown below:
5353
// [assembly: AssemblyVersion("1.0.*")]
54-
[assembly: AssemblyVersion("1.0.0.0")]
55-
[assembly: AssemblyFileVersion("1.0.0.0")]
54+
[assembly: AssemblyVersion("1.1.0.0")]
55+
[assembly: AssemblyFileVersion("1.1.0.0")]

RemovePdfLinks/RemovePdfLinks.csproj

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
<FileAlignment>512</FileAlignment>
1414
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
1515
<WarningLevel>4</WarningLevel>
16+
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
17+
<RestorePackages>true</RestorePackages>
1618
</PropertyGroup>
1719
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
1820
<PlatformTarget>AnyCPU</PlatformTarget>
@@ -102,6 +104,13 @@
102104
<Resource Include="pdf.ico" />
103105
</ItemGroup>
104106
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
107+
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
108+
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
109+
<PropertyGroup>
110+
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
111+
</PropertyGroup>
112+
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
113+
</Target>
105114
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
106115
Other similar extension points exist, see Microsoft.Common.targets.
107116
<Target Name="BeforeBuild">

RemovePdfLinks/Utils/FolderBrowserDialogBehavior.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ public object FolderBrowserDialogResultCommand
2929

3030
protected override void Invoke(object parameter)
3131
{
32-
using (var folderBrowserDialog = new FolderBrowserDialog { ShowNewFolderButton = true })
32+
using (var folderBrowserDialog = new FolderBrowserDialog
33+
{
34+
ShowNewFolderButton = true,
35+
SelectedPath = System.Windows.Forms.Application.StartupPath
36+
})
3337
{
3438
if (!string.IsNullOrEmpty(FolderBrowserDescription))
3539
{

RemovePdfLinks/ViewModels/MainWindowViewModel.cs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System;
2-
using System.IO;
1+
using System.IO;
32
using RemovePdfLinks.Core;
43
using RemovePdfLinks.Models;
54
using RemovePdfLinks.Utils;
@@ -19,19 +18,25 @@ public MainWindowViewModel()
1918

2019
private void processFiles()
2120
{
22-
if(string.IsNullOrWhiteSpace(GuiModelData.FolderPath))
21+
if (string.IsNullOrWhiteSpace(GuiModelData.InputFolderPath) ||
22+
string.IsNullOrWhiteSpace(GuiModelData.OutputFolderPath))
23+
{
2324
return;
25+
}
2426

25-
var pdfFiles = Directory.GetFiles(GuiModelData.FolderPath, "*.pdf");
26-
foreach (var file in pdfFiles)
27+
if (!Directory.Exists(GuiModelData.OutputFolderPath))
2728
{
28-
if(file.EndsWith("-mod.pdf", StringComparison.OrdinalIgnoreCase)) continue;
29+
Directory.CreateDirectory(GuiModelData.OutputFolderPath);
30+
}
2931

30-
var newFileName = string.Format("{0}-mod.pdf", Path.GetFileNameWithoutExtension(file));
32+
var pdfFiles = Directory.GetFiles(GuiModelData.InputFolderPath, "*.pdf");
33+
foreach (var file in pdfFiles)
34+
{
35+
var newFileName = Path.GetFileName(file);
3136
new ReplacePdfLinks
3237
{
3338
InputPdf = file,
34-
OutputPdf = Path.Combine(GuiModelData.FolderPath, newFileName),
39+
OutputPdf = Path.Combine(GuiModelData.OutputFolderPath, newFileName),
3540
UriToNewUrl = uri =>
3641
{
3742
return GuiModelData.RemoveAllLinks ? string.Empty : GuiModelData.NewUrl;

0 commit comments

Comments
 (0)