Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Improved readability, added using(). |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | develop |
Files: | files | file ages | folders |
SHA1: |
fea5f791778202ab0e0bfa0e70ee8d54 |
User & Date: | tinus 2018-03-21 20:55:56.522 |
Context
2018-03-21
| ||
21:05 | Only update when the version is actually higher. Respect the executable's current caps. check-in: 1909930a85 user: tinus tags: develop | |
20:55 | Improved readability, added using(). check-in: fea5f79177 user: tinus tags: develop | |
20:08 | Bugfix: FileInfo.MoveTo also changes the FileInfo's FullName. :-) check-in: bfd001af76 user: tinus tags: develop | |
Changes
Changes to ZTUpdater/ZTUpdater.cs.
︙ | ︙ | |||
206 207 208 209 210 211 212 | } } // Perform the update based on the downloaded file return UpdateFromFile(ZipFile); } | | > > > | > | | | | | | | | | | | | | | | | | | | > | | | | | | | | | | | | | | | | | | | > | 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 | } } // Perform the update based on the downloaded file return UpdateFromFile(ZipFile); } public int UpdateFromFile(string zipFile) { if (zipFile == null) throw new ArgumentNullException(nameof(zipFile)); int NumFiles = 0; Log($"Extracting files..."); using (var Zip = ZipFile.OpenRead(zipFile)) { foreach (var Entry in Zip.Entries) { var TargetFile = new FileInfo(Path.Combine(ZTreeHome, Entry.FullName.Replace('/', '\\'))); if (TargetFile.Exists) { if (Identical(Entry, TargetFile)) { Log($"\t{Entry.FullName}\tidentical to existing file; skipping."); continue; } // Try moving to version-based folder first; only if that doesn't work, try to rename // to a version-based file name in the same folder. Log($"\t{Entry.FullName}\tbacking up existing file."); try { var BackupName = VersionBasedFolder(TargetFile); try { File.Move(TargetFile.FullName, BackupName); TargetFile.Refresh(); if (TargetFile.Exists) // Then, the move was NOT successful throw new Exception("Unable to move the file."); } catch (Exception ex) { Log($"\t{Entry.FullName}\tFirst attempt: {ex.Message.Trim()}"); BackupName = VersionBasedFilename(TargetFile); File.Move(TargetFile.FullName, BackupName); } } catch (Exception ex) { Log($"\t{Entry.FullName}\tBackup failed: {ex.Message.Trim()}", TraceLevel.Warning); } } Log($"\t{Entry.FullName}\textracting..."); Entry.ExtractToFile(TargetFile.FullName); NumFiles++; } } return NumFiles; } private string VersionBasedFolder(FileInfo File) { var SourceDir = new DirectoryInfo(ZTreeHome); |
︙ | ︙ | |||
369 370 371 372 373 374 375 | } Text = Text.Substring(0, Match.Index) + Replacement + Text.Substring(Match.Index + Match.Length); StartAt = Match.Index + Replacement.Length; } return Text; } | | | > > | 375 376 377 378 379 380 381 382 383 384 385 | } Text = Text.Substring(0, Match.Index) + Replacement + Text.Substring(Match.Index + Match.Length); StartAt = Match.Index + Replacement.Length; } return Text; } } } |