├── ArchiveOrgCollectionSync
├── App.xaml.cs
├── archive.ico
├── App.xaml
├── FileCollection.cs
├── File.cs
├── PatientWebClient.cs
├── LogItem.cs
├── license.txt
├── NumericUpDown.xaml
├── ArchiveOrgCollectionSync.csproj
├── NumericUpDown.xaml.cs
├── MainWindow.xaml
└── MainWindow.xaml.cs
├── README.md
├── LICENSE
└── .gitignore
/ArchiveOrgCollectionSync/App.xaml.cs:
--------------------------------------------------------------------------------
1 | namespace ArchiveOrgCollectionSync
2 | {
3 | public partial class App
4 | {
5 | }
6 | }
--------------------------------------------------------------------------------
/ArchiveOrgCollectionSync/archive.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jasonunbrokensoftware/ArchiveOrgCollectionSync/HEAD/ArchiveOrgCollectionSync/archive.ico
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Archive.org Collection Sync
2 | Easily download and sync collections from archive.org to a local folder. Compares checksums to ensure that all files are downloaded successfully.
3 |
4 | Requires the .NET Framework 4.7.2.
5 |
6 | Licensed under the MIT License.
7 |
--------------------------------------------------------------------------------
/ArchiveOrgCollectionSync/App.xaml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/ArchiveOrgCollectionSync/FileCollection.cs:
--------------------------------------------------------------------------------
1 | namespace ArchiveOrgCollectionSync
2 | {
3 | using System;
4 | using System.Xml.Serialization;
5 |
6 | [XmlRoot("files")]
7 | public class FileCollection
8 | {
9 | public FileCollection()
10 | {
11 | this.Files = Array.Empty();
12 | }
13 |
14 | [XmlElement("file")]
15 | public File[] Files { get; set; }
16 | }
17 | }
--------------------------------------------------------------------------------
/ArchiveOrgCollectionSync/File.cs:
--------------------------------------------------------------------------------
1 | namespace ArchiveOrgCollectionSync
2 | {
3 | using System.Xml.Serialization;
4 |
5 | public class File
6 | {
7 | public File()
8 | {
9 | this.Name = string.Empty;
10 | this.Md5 = string.Empty;
11 | }
12 |
13 | [XmlAttribute("name")]
14 | public string Name { get; set; }
15 |
16 | [XmlElement("size")]
17 | public long Size { get; set; }
18 |
19 | [XmlElement("md5")]
20 | public string Md5 { get; set; }
21 | }
22 | }
--------------------------------------------------------------------------------
/ArchiveOrgCollectionSync/PatientWebClient.cs:
--------------------------------------------------------------------------------
1 | namespace ArchiveOrgCollectionSync
2 | {
3 | using System;
4 | using System.Net;
5 |
6 | public class PatientWebClient : WebClient
7 | {
8 | protected override WebRequest GetWebRequest(Uri address)
9 | {
10 | var request = base.GetWebRequest(address);
11 |
12 | if (request != null)
13 | {
14 | request.Timeout = (int)TimeSpan.FromMinutes(60).TotalMilliseconds;
15 | }
16 |
17 | return request;
18 | }
19 | }
20 | }
--------------------------------------------------------------------------------
/ArchiveOrgCollectionSync/LogItem.cs:
--------------------------------------------------------------------------------
1 | namespace ArchiveOrgCollectionSync
2 | {
3 | using System.Windows;
4 | using System.Windows.Media;
5 |
6 | public class LogItem
7 | {
8 | public LogItem(string message, bool error, bool complete)
9 | {
10 | this.Message = message;
11 |
12 | if (error)
13 | {
14 | this.Brush = new SolidColorBrush(Colors.Red);
15 | }
16 | else if (complete)
17 | {
18 | this.Brush = new SolidColorBrush(Colors.Green);
19 | }
20 | else
21 | {
22 | this.Brush = SystemColors.ControlTextBrush;
23 | }
24 | }
25 |
26 | public string Message { get; set; }
27 |
28 | public Brush Brush { get; set; }
29 | }
30 | }
--------------------------------------------------------------------------------
/ArchiveOrgCollectionSync/license.txt:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2022 Unbroken Software, LLC
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6 |
7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8 |
9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2022 Unbroken Software, LLC
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/ArchiveOrgCollectionSync/NumericUpDown.xaml:
--------------------------------------------------------------------------------
1 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
21 | ▲
23 | ▼
25 |
26 |
--------------------------------------------------------------------------------
/ArchiveOrgCollectionSync/ArchiveOrgCollectionSync.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | WinExe
5 | net6.0-windows
6 | enable
7 | true
8 | Unbroken Software, LLC
9 | Unbroken Software, LLC
10 | Archive.org Collection Sync
11 | Copyright © Unbroken Software, LLC 2023
12 | https://github.com/jasonunbrokensoftware/ArchiveOrgCollectionSync
13 | en-US
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 | Never
28 |
29 |
30 | Never
31 |
32 |
33 |
34 |
35 |
36 | Code
37 |
38 |
39 | Component
40 |
41 |
42 |
43 |
44 |
45 | Designer
46 |
47 |
48 | Designer
49 |
50 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/ArchiveOrgCollectionSync/NumericUpDown.xaml.cs:
--------------------------------------------------------------------------------
1 | namespace ArchiveOrgCollectionSync
2 | {
3 | using System.Reflection;
4 | using System.Windows;
5 | using System.Windows.Controls;
6 | using System.Windows.Controls.Primitives;
7 | using System.Windows.Input;
8 |
9 | public partial class NumericUpDown
10 | {
11 | public NumericUpDown()
12 | {
13 | this.InitializeComponent();
14 | this.MaxValue = 100;
15 | this.TextBox.Text = this.Value.ToString();
16 | }
17 |
18 | public static readonly DependencyProperty MinValueProperty = DependencyProperty.Register(
19 | nameof(NumericUpDown.MinValue),
20 | typeof(int),
21 | typeof(NumericUpDown));
22 |
23 | public static readonly DependencyProperty MaxValueProperty = DependencyProperty.Register(
24 | nameof(NumericUpDown.MaxValue),
25 | typeof(int),
26 | typeof(NumericUpDown));
27 |
28 | public static readonly DependencyProperty ValueProperty = DependencyProperty.Register(
29 | nameof(NumericUpDown.Value),
30 | typeof(int),
31 | typeof(NumericUpDown));
32 |
33 | public int MinValue
34 | {
35 | get
36 | {
37 | return (int)this.GetValue(NumericUpDown.MinValueProperty);
38 | }
39 |
40 | set
41 | {
42 | this.SetValue(NumericUpDown.MinValueProperty, value);
43 | }
44 | }
45 |
46 | public int MaxValue
47 | {
48 | get
49 | {
50 | return (int)this.GetValue(NumericUpDown.MaxValueProperty);
51 | }
52 |
53 | set
54 | {
55 | this.SetValue(NumericUpDown.MaxValueProperty, value);
56 | }
57 | }
58 |
59 | public int Value
60 | {
61 | get
62 | {
63 | return (int)this.GetValue(NumericUpDown.ValueProperty);
64 | }
65 |
66 | set
67 | {
68 | this.SetValue(NumericUpDown.ValueProperty, value);
69 | }
70 | }
71 |
72 | private void UpButton_Click(object sender, RoutedEventArgs e)
73 | {
74 | int value = this.Value + 1;
75 |
76 | if (value > this.MaxValue)
77 | {
78 | return;
79 | }
80 |
81 | this.TextBox.Text = value.ToString();
82 | this.Value = value;
83 | }
84 |
85 | private void DownButton_Click(object sender, RoutedEventArgs e)
86 | {
87 | int value = this.Value - 1;
88 |
89 | if (value < this.MinValue)
90 | {
91 | return;
92 | }
93 |
94 | this.TextBox.Text = value.ToString();
95 | this.Value = value;
96 | }
97 |
98 | private void TextBox_PreviewKeyDown(object sender, KeyEventArgs e)
99 | {
100 | if (e.Key == Key.Up)
101 | {
102 | this.UpButton.RaiseEvent(new RoutedEventArgs(ButtonBase.ClickEvent));
103 | typeof(Button).GetMethod("set_IsPressed", BindingFlags.Instance | BindingFlags.NonPublic)?.Invoke(this.UpButton, new object[] { true });
104 | }
105 |
106 | if (e.Key == Key.Down)
107 | {
108 | this.DownButton.RaiseEvent(new RoutedEventArgs(ButtonBase.ClickEvent));
109 | typeof(Button).GetMethod("set_IsPressed", BindingFlags.Instance | BindingFlags.NonPublic)?.Invoke(this.DownButton, new object[] { true });
110 | }
111 | }
112 |
113 | private void TextBox_PreviewKeyUp(object sender, KeyEventArgs e)
114 | {
115 | if (e.Key == Key.Up)
116 | {
117 | typeof(Button).GetMethod("set_IsPressed", BindingFlags.Instance | BindingFlags.NonPublic)?.Invoke(this.UpButton, new object[] { false });
118 | }
119 |
120 | if (e.Key == Key.Down)
121 | {
122 | typeof(Button).GetMethod("set_IsPressed", BindingFlags.Instance | BindingFlags.NonPublic)?.Invoke(this.DownButton, new object[] { false });
123 | }
124 | }
125 |
126 | private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
127 | {
128 | int value = 0;
129 |
130 | if (!string.IsNullOrWhiteSpace(this.TextBox.Text))
131 | {
132 | if (!int.TryParse(this.TextBox.Text, out value))
133 | {
134 | this.TextBox.Text = this.Value.ToString();
135 | }
136 | }
137 |
138 | if (value > this.MaxValue)
139 | {
140 | this.TextBox.Text = this.MaxValue.ToString();
141 | }
142 |
143 | if (value < this.MinValue)
144 | {
145 | this.TextBox.Text = this.MinValue.ToString();
146 | }
147 |
148 | this.TextBox.SelectionStart = this.TextBox.Text.Length;
149 |
150 | if (!string.IsNullOrWhiteSpace(this.TextBox.Text))
151 | {
152 | this.Value = int.Parse(this.TextBox.Text);
153 | }
154 | }
155 |
156 | private void NumericUpDown_OnLoaded(object sender, RoutedEventArgs e)
157 | {
158 | this.TextBox.Text = this.Value.ToString();
159 | }
160 | }
161 | }
--------------------------------------------------------------------------------
/ArchiveOrgCollectionSync/MainWindow.xaml:
--------------------------------------------------------------------------------
1 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 | Archive.org Collection URL:
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 | Destination Folder:
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 | Maximum Simultaneous Downloads:
42 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 | But God showed his great love for us by sending Christ to die for us while we were still sinners. - Romans 5:8 (NLT)
60 | Version 1.2 - Released June 29, 2022
61 | MIT License
62 | Copyright (c) 2023 Unbroken Software, LLC
63 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
64 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
65 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 | ##
4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
5 |
6 | # User-specific files
7 | *.rsuser
8 | *.suo
9 | *.user
10 | *.userosscache
11 | *.sln.docstates
12 |
13 | # User-specific files (MonoDevelop/Xamarin Studio)
14 | *.userprefs
15 |
16 | # Mono auto generated files
17 | mono_crash.*
18 |
19 | # Build results
20 | [Dd]ebug/
21 | [Dd]ebugPublic/
22 | [Rr]elease/
23 | [Rr]eleases/
24 | x64/
25 | x86/
26 | [Aa][Rr][Mm]/
27 | [Aa][Rr][Mm]64/
28 | bld/
29 | [Bb]in/
30 | [Oo]bj/
31 | [Ll]og/
32 | [Ll]ogs/
33 |
34 | # Visual Studio 2015/2017 cache/options directory
35 | .vs/
36 | # Uncomment if you have tasks that create the project's static files in wwwroot
37 | #wwwroot/
38 |
39 | # Visual Studio 2017 auto generated files
40 | Generated\ Files/
41 |
42 | # MSTest test Results
43 | [Tt]est[Rr]esult*/
44 | [Bb]uild[Ll]og.*
45 |
46 | # NUnit
47 | *.VisualState.xml
48 | TestResult.xml
49 | nunit-*.xml
50 |
51 | # Build Results of an ATL Project
52 | [Dd]ebugPS/
53 | [Rr]eleasePS/
54 | dlldata.c
55 |
56 | # Benchmark Results
57 | BenchmarkDotNet.Artifacts/
58 |
59 | # .NET Core
60 | project.lock.json
61 | project.fragment.lock.json
62 | artifacts/
63 |
64 | # StyleCop
65 | StyleCopReport.xml
66 |
67 | # Files built by Visual Studio
68 | *_i.c
69 | *_p.c
70 | *_h.h
71 | *.ilk
72 | *.meta
73 | *.obj
74 | *.iobj
75 | *.pch
76 | *.pdb
77 | *.ipdb
78 | *.pgc
79 | *.pgd
80 | *.rsp
81 | *.sbr
82 | *.tlb
83 | *.tli
84 | *.tlh
85 | *.tmp
86 | *.tmp_proj
87 | *_wpftmp.csproj
88 | *.log
89 | *.vspscc
90 | *.vssscc
91 | .builds
92 | *.pidb
93 | *.svclog
94 | *.scc
95 |
96 | # Chutzpah Test files
97 | _Chutzpah*
98 |
99 | # Visual C++ cache files
100 | ipch/
101 | *.aps
102 | *.ncb
103 | *.opendb
104 | *.opensdf
105 | *.sdf
106 | *.cachefile
107 | *.VC.db
108 | *.VC.VC.opendb
109 |
110 | # Visual Studio profiler
111 | *.psess
112 | *.vsp
113 | *.vspx
114 | *.sap
115 |
116 | # Visual Studio Trace Files
117 | *.e2e
118 |
119 | # TFS 2012 Local Workspace
120 | $tf/
121 |
122 | # Guidance Automation Toolkit
123 | *.gpState
124 |
125 | # ReSharper is a .NET coding add-in
126 | _ReSharper*/
127 | *.[Rr]e[Ss]harper
128 | *.DotSettings.user
129 |
130 | # TeamCity is a build add-in
131 | _TeamCity*
132 |
133 | # DotCover is a Code Coverage Tool
134 | *.dotCover
135 |
136 | # AxoCover is a Code Coverage Tool
137 | .axoCover/*
138 | !.axoCover/settings.json
139 |
140 | # Visual Studio code coverage results
141 | *.coverage
142 | *.coveragexml
143 |
144 | # NCrunch
145 | _NCrunch_*
146 | .*crunch*.local.xml
147 | nCrunchTemp_*
148 |
149 | # MightyMoose
150 | *.mm.*
151 | AutoTest.Net/
152 |
153 | # Web workbench (sass)
154 | .sass-cache/
155 |
156 | # Installshield output folder
157 | [Ee]xpress/
158 |
159 | # DocProject is a documentation generator add-in
160 | DocProject/buildhelp/
161 | DocProject/Help/*.HxT
162 | DocProject/Help/*.HxC
163 | DocProject/Help/*.hhc
164 | DocProject/Help/*.hhk
165 | DocProject/Help/*.hhp
166 | DocProject/Help/Html2
167 | DocProject/Help/html
168 |
169 | # Click-Once directory
170 | publish/
171 |
172 | # Publish Web Output
173 | *.[Pp]ublish.xml
174 | *.azurePubxml
175 | # Note: Comment the next line if you want to checkin your web deploy settings,
176 | # but database connection strings (with potential passwords) will be unencrypted
177 | *.pubxml
178 | *.publishproj
179 |
180 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
181 | # checkin your Azure Web App publish settings, but sensitive information contained
182 | # in these scripts will be unencrypted
183 | PublishScripts/
184 |
185 | # NuGet Packages
186 | *.nupkg
187 | # NuGet Symbol Packages
188 | *.snupkg
189 | # The packages folder can be ignored because of Package Restore
190 | **/[Pp]ackages/*
191 | # except build/, which is used as an MSBuild target.
192 | !**/[Pp]ackages/build/
193 | # Uncomment if necessary however generally it will be regenerated when needed
194 | #!**/[Pp]ackages/repositories.config
195 | # NuGet v3's project.json files produces more ignorable files
196 | *.nuget.props
197 | *.nuget.targets
198 |
199 | # Microsoft Azure Build Output
200 | csx/
201 | *.build.csdef
202 |
203 | # Microsoft Azure Emulator
204 | ecf/
205 | rcf/
206 |
207 | # Windows Store app package directories and files
208 | AppPackages/
209 | BundleArtifacts/
210 | Package.StoreAssociation.xml
211 | _pkginfo.txt
212 | *.appx
213 | *.appxbundle
214 | *.appxupload
215 |
216 | # Visual Studio cache files
217 | # files ending in .cache can be ignored
218 | *.[Cc]ache
219 | # but keep track of directories ending in .cache
220 | !?*.[Cc]ache/
221 |
222 | # Others
223 | ClientBin/
224 | ~$*
225 | *~
226 | *.dbmdl
227 | *.dbproj.schemaview
228 | *.jfm
229 | *.pfx
230 | *.publishsettings
231 | orleans.codegen.cs
232 |
233 | # Including strong name files can present a security risk
234 | # (https://github.com/github/gitignore/pull/2483#issue-259490424)
235 | #*.snk
236 |
237 | # Since there are multiple workflows, uncomment next line to ignore bower_components
238 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
239 | #bower_components/
240 |
241 | # RIA/Silverlight projects
242 | Generated_Code/
243 |
244 | # Backup & report files from converting an old project file
245 | # to a newer Visual Studio version. Backup files are not needed,
246 | # because we have git ;-)
247 | _UpgradeReport_Files/
248 | Backup*/
249 | UpgradeLog*.XML
250 | UpgradeLog*.htm
251 | ServiceFabricBackup/
252 | *.rptproj.bak
253 |
254 | # SQL Server files
255 | *.mdf
256 | *.ldf
257 | *.ndf
258 |
259 | # Business Intelligence projects
260 | *.rdl.data
261 | *.bim.layout
262 | *.bim_*.settings
263 | *.rptproj.rsuser
264 | *- [Bb]ackup.rdl
265 | *- [Bb]ackup ([0-9]).rdl
266 | *- [Bb]ackup ([0-9][0-9]).rdl
267 |
268 | # Microsoft Fakes
269 | FakesAssemblies/
270 |
271 | # GhostDoc plugin setting file
272 | *.GhostDoc.xml
273 |
274 | # Node.js Tools for Visual Studio
275 | .ntvs_analysis.dat
276 | node_modules/
277 |
278 | # Visual Studio 6 build log
279 | *.plg
280 |
281 | # Visual Studio 6 workspace options file
282 | *.opt
283 |
284 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
285 | *.vbw
286 |
287 | # Visual Studio LightSwitch build output
288 | **/*.HTMLClient/GeneratedArtifacts
289 | **/*.DesktopClient/GeneratedArtifacts
290 | **/*.DesktopClient/ModelManifest.xml
291 | **/*.Server/GeneratedArtifacts
292 | **/*.Server/ModelManifest.xml
293 | _Pvt_Extensions
294 |
295 | # Paket dependency manager
296 | .paket/paket.exe
297 | paket-files/
298 |
299 | # FAKE - F# Make
300 | .fake/
301 |
302 | # CodeRush personal settings
303 | .cr/personal
304 |
305 | # Python Tools for Visual Studio (PTVS)
306 | __pycache__/
307 | *.pyc
308 |
309 | # Cake - Uncomment if you are using it
310 | # tools/**
311 | # !tools/packages.config
312 |
313 | # Tabs Studio
314 | *.tss
315 |
316 | # Telerik's JustMock configuration file
317 | *.jmconfig
318 |
319 | # BizTalk build output
320 | *.btp.cs
321 | *.btm.cs
322 | *.odx.cs
323 | *.xsd.cs
324 |
325 | # OpenCover UI analysis results
326 | OpenCover/
327 |
328 | # Azure Stream Analytics local run output
329 | ASALocalRun/
330 |
331 | # MSBuild Binary and Structured Log
332 | *.binlog
333 |
334 | # NVidia Nsight GPU debugger configuration file
335 | *.nvuser
336 |
337 | # MFractors (Xamarin productivity tool) working folder
338 | .mfractor/
339 |
340 | # Local History for Visual Studio
341 | .localhistory/
342 |
343 | # BeatPulse healthcheck temp database
344 | healthchecksdb
345 |
346 | # Backup folder for Package Reference Convert tool in Visual Studio 2017
347 | MigrationBackup/
348 |
349 | # Ionide (cross platform F# VS Code tools) working folder
350 | .ionide/
351 |
--------------------------------------------------------------------------------
/ArchiveOrgCollectionSync/MainWindow.xaml.cs:
--------------------------------------------------------------------------------
1 | namespace ArchiveOrgCollectionSync
2 | {
3 | using System;
4 | using System.IO;
5 | using System.Linq;
6 | using System.Security.Cryptography;
7 | using System.Threading;
8 | using System.Threading.Tasks;
9 | using System.Windows;
10 | using System.Windows.Controls;
11 | using System.Windows.Media;
12 | using System.Xml.Serialization;
13 |
14 | using Microsoft.WindowsAPICodePack.Dialogs;
15 |
16 | public partial class MainWindow
17 | {
18 | public MainWindow()
19 | {
20 | this.InitializeComponent();
21 | this.UrlTextBox.Focus();
22 | }
23 |
24 | private void PasteButton_Click(object sender, RoutedEventArgs e)
25 | {
26 | this.UrlTextBox.Text = Clipboard.GetText();
27 | this.UrlTextBox.Focus();
28 | this.UrlTextBox.SelectAll();
29 | }
30 |
31 | private void BrowseButton_Click(object sender, RoutedEventArgs e)
32 | {
33 | string? folder = string.IsNullOrWhiteSpace(this.FolderTextBox.Text) || !Directory.Exists(this.FolderTextBox.Text) ? null : this.FolderTextBox.Text;
34 |
35 | var dialog = new CommonOpenFileDialog
36 | {
37 | Title = "Browse for Destination Folder",
38 | IsFolderPicker = true,
39 | AddToMostRecentlyUsedList = false,
40 | AllowNonFileSystemItems = false,
41 | EnsureFileExists = true,
42 | EnsurePathExists = true,
43 | EnsureReadOnly = false,
44 | EnsureValidNames = true,
45 | Multiselect = false,
46 | ShowPlacesList = true,
47 | InitialDirectory = folder,
48 | DefaultDirectory = folder
49 | };
50 |
51 | if (dialog.ShowDialog(Application.Current.Windows.OfType().Single(x => x.IsActive)) != CommonFileDialogResult.Ok)
52 | {
53 | return;
54 | }
55 |
56 | this.FolderTextBox.Text = dialog.FileName;
57 | this.FolderTextBox.Focus();
58 | this.FolderTextBox.SelectAll();
59 | }
60 |
61 | private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
62 | {
63 | this.StartButton.IsEnabled = this.FolderTextBox.Text.Trim().Length > 0 && this.UrlTextBox.Text.Trim().Length > 0;
64 | }
65 |
66 | private void StartButton_Click(object sender, RoutedEventArgs e)
67 | {
68 | string collectionName;
69 |
70 | if (this.UrlTextBox.Text.Trim().StartsWith("https://archive.org/download/", StringComparison.OrdinalIgnoreCase)
71 | && this.UrlTextBox.Text.Length >= 30)
72 | {
73 | collectionName = this.UrlTextBox.Text.Trim()[29..];
74 | }
75 | else if (this.UrlTextBox.Text.Trim().StartsWith("https://archive.org/details/", StringComparison.OrdinalIgnoreCase)
76 | && this.UrlTextBox.Text.Trim().Length >= 29)
77 | {
78 | collectionName = this.UrlTextBox.Text.Trim()[28..];
79 | }
80 | else
81 | {
82 | MessageBox.Show(this, "Incorrect Archive.org Collection URL. A URL in the format of https://archive.org/details/ or https://archive.org/download/ is expected.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
83 | return;
84 | }
85 |
86 | if (collectionName.Contains('/'))
87 | {
88 | collectionName = collectionName[..collectionName.IndexOf("/", StringComparison.OrdinalIgnoreCase)];
89 | }
90 |
91 | string folder = this.FolderTextBox.Text.Trim();
92 |
93 | if (!Directory.Exists(folder))
94 | {
95 | MessageBox.Show(this, "Destination folder does not exist.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
96 | return;
97 | }
98 |
99 | this.Start(collectionName, folder, this.DeleteFilesCheckBox.IsChecked == true, this.MaxDownloadsNumericUpDown.Value);
100 | }
101 |
102 | private void ChangeState(bool running)
103 | {
104 | this.Dispatcher.Invoke(() =>
105 | {
106 | this.StartButton.IsEnabled =
107 | this.UrlTextBox.IsEnabled =
108 | this.FolderTextBox.IsEnabled =
109 | this.PasteButton.IsEnabled =
110 | this.BrowseButton.IsEnabled =
111 | this.DeleteFilesCheckBox.IsEnabled =
112 | this.MaxDownloadsNumericUpDown.IsEnabled =
113 | !running;
114 |
115 | if (!running)
116 | {
117 | this.ProgressBar.Value = 0;
118 | }
119 | });
120 | }
121 |
122 | private void Report(string message, bool error = false, bool complete = false)
123 | {
124 | this.Dispatcher.Invoke(() =>
125 | {
126 | this.ProgressTextBlock.Text = message;
127 | this.ProgressTextBlock.Visibility = Visibility.Visible;
128 |
129 | if (error)
130 | {
131 | this.ProgressTextBlock.Foreground = new SolidColorBrush(Colors.Red);
132 | }
133 | else if (complete)
134 | {
135 | this.ProgressTextBlock.Foreground = new SolidColorBrush(Colors.Green);
136 | }
137 | else
138 | {
139 | this.ProgressTextBlock.Foreground = SystemColors.ControlTextBrush;
140 | }
141 |
142 | var item = new LogItem(message, error, complete);
143 | this.LogListBox.Items.Add(item);
144 | this.LogListBox.SelectedIndex = this.LogListBox.Items.Count - 1;
145 | this.LogListBox.ScrollIntoView(item);
146 | });
147 | }
148 |
149 | private void Start(string collectionName, string folder, bool deleteFiles, int threads)
150 | {
151 | ThreadPool.QueueUserWorkItem(_ =>
152 | {
153 | this.ChangeState(true);
154 | this.Report("Scanning archive.org collection files...");
155 |
156 | string collectionXmlUrl = $"https://archive.org/download/{collectionName}/{collectionName}_files.xml";
157 | string collectionXml;
158 |
159 | try
160 | {
161 | using var client = new PatientWebClient();
162 | collectionXml = client.DownloadString(collectionXmlUrl);
163 | }
164 | catch (Exception ex)
165 | {
166 | this.Report($"Unable to parse collection metadata; the XML list of files could not be downloaded. - {ex.Message}", true);
167 | return;
168 | }
169 |
170 | File[] files;
171 |
172 | try
173 | {
174 | var serializer = new XmlSerializer(typeof(FileCollection));
175 |
176 | using var reader = new StringReader(collectionXml);
177 | files = ((FileCollection)(serializer.Deserialize(reader) ?? throw new NullReferenceException())).Files;
178 | }
179 | catch (Exception ex)
180 | {
181 | this.Report($"Unable to deserialize the list of files from archive.org. - {ex.Message}", true);
182 | return;
183 | }
184 |
185 | this.Dispatcher.Invoke(() => this.ProgressBar.Maximum = files.Length);
186 |
187 | int count = 0;
188 | int skippingCount = 0;
189 | int downloadErrorCount = 0;
190 | int downloadCorruptCount = 0;
191 | int downloadSuccessCount = 0;
192 | int deletedCount = 0;
193 | int deletedErrorCount = 0;
194 |
195 | if (deleteFiles)
196 | {
197 | foreach (string filePath in Directory.GetFiles(folder, "*.*", SearchOption.AllDirectories))
198 | {
199 | string relativeFilePath = filePath.Replace(folder + "\\", string.Empty).Replace('\\', '/');
200 |
201 | if (files.Any(f => string.Equals(f.Name, relativeFilePath, StringComparison.OrdinalIgnoreCase)))
202 | {
203 | continue;
204 | }
205 |
206 | try
207 | {
208 | this.Report($"Deleting file {Path.GetFileName(filePath)} because it does not exist in the Archive.org collection.");
209 | System.IO.File.Delete(filePath);
210 | deletedCount++;
211 | }
212 | catch (Exception ex)
213 | {
214 | this.Report($"Unable to delete file {Path.GetFileName(filePath)} from disk. - {ex.Message}", true);
215 | deletedErrorCount++;
216 | }
217 | }
218 | }
219 |
220 | Parallel.ForEach(
221 | files,
222 | new ParallelOptions { MaxDegreeOfParallelism = threads },
223 | file =>
224 | {
225 | count++;
226 |
227 | this.Dispatcher.Invoke(
228 | () =>
229 | {
230 | this.ProgressBar.Value = count;
231 | });
232 |
233 | this.Report($"Reading disk file {file.Name}...");
234 |
235 | string destinationFilePath = Path.Combine(folder, file.Name);
236 | Directory.CreateDirectory(Path.GetDirectoryName(destinationFilePath) ?? throw new InvalidOperationException());
237 |
238 | if (System.IO.File.Exists(destinationFilePath))
239 | {
240 | if (destinationFilePath.EndsWith($"{collectionName}_files.xml") ||
241 | new FileInfo(destinationFilePath).Length == file.Size && MainWindow.ConfirmMd5(destinationFilePath, file.Md5))
242 | {
243 | this.Report($"File {file.Name} already exists with the correct file size and checksum. Skipping!");
244 | skippingCount++;
245 | return;
246 | }
247 |
248 | this.Report($"Existing file {file.Name} has an incorrect file size or checksum! Re-downloading file...", true);
249 | System.IO.File.Delete(destinationFilePath);
250 | }
251 | else
252 | {
253 | this.Report($"File {file.Name} does not exist on disk! Downloading file...");
254 | }
255 |
256 | using (var client = new PatientWebClient())
257 | {
258 | try
259 | {
260 | client.DownloadFile($"https://archive.org/download/{collectionName}/{file.Name}", destinationFilePath);
261 | }
262 | catch (Exception ex)
263 | {
264 | this.Report($"An error occurred downloading file {file.Name}. - {ex.Message}", true);
265 | downloadErrorCount++;
266 | return;
267 | }
268 | }
269 |
270 | if (destinationFilePath.EndsWith($"{collectionName}_files.xml") || MainWindow.ConfirmMd5(destinationFilePath, file.Md5))
271 | {
272 | this.Report($"File {file.Name} downloaded successfully and checksum confirmed!");
273 | downloadSuccessCount++;
274 | }
275 | else
276 | {
277 | this.Report($"Checksum does not match on file {file.Name} after downloading!", true);
278 | downloadCorruptCount++;
279 | }
280 | });
281 |
282 | this.Report($"{count} file(s) from Archive.org were processed!", false, true);
283 | this.Report($"{skippingCount} file(s) already existed with the correct file size and checksum.", false, true);
284 | this.Report($"{downloadSuccessCount} file(s) were successfully downloaded.", false, true);
285 | this.Report($"{downloadErrorCount} file(s) were not downloaded successfully.", downloadErrorCount > 0, downloadErrorCount == 0);
286 | this.Report($"{downloadCorruptCount} file(s) had an incorrect checksum after downloading.", downloadCorruptCount > 0, downloadCorruptCount == 0);
287 |
288 | if (deleteFiles)
289 | {
290 | this.Report($"{deletedCount} file(s) were deleted because they are not in the Archive.org collection.", false, true);
291 | this.Report($"{deletedErrorCount} file(s) could not be deleted from the destination folder.", deletedErrorCount > 0, deletedErrorCount == 0);
292 | }
293 |
294 | this.Report("Process is complete!", false, true);
295 | this.ChangeState(false);
296 | });
297 | }
298 |
299 | private static bool ConfirmMd5(string filePath, string md5Hash)
300 | {
301 | using var stream = System.IO.File.OpenRead(filePath);
302 | using var md5 = MD5.Create();
303 | return BitConverter.ToString(md5.ComputeHash(stream)).Replace("-", "").ToLowerInvariant() == md5Hash;
304 | }
305 |
306 | private void LogTabItem_Selected(object sender, RoutedEventArgs e)
307 | {
308 | this.LogListBox.ScrollIntoView(this.LogListBox.SelectedItem);
309 | }
310 | }
311 | }
--------------------------------------------------------------------------------