From eb15ceafd2ffa5be7594007a91158761049502e0 Mon Sep 17 00:00:00 2001 From: Alessandro Volz Date: Thu, 29 Mar 2018 11:15:48 +0200 Subject: [PATCH 1/3] moving Weasis customization path to Library/Application Support/Horos/Weasis --- Horos/Sources/Horos.h | 2 ++ Horos/Sources/Horos.m | 4 ++++ Horos/Sources/WebPortalConnection.mm | 5 +++-- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Horos/Sources/Horos.h b/Horos/Sources/Horos.h index b5f483df58..115c8fc332 100644 --- a/Horos/Sources/Horos.h +++ b/Horos/Sources/Horos.h @@ -47,6 +47,8 @@ NS_ASSUME_NONNULL_BEGIN + (NSDateComponents *)components:(NSCalendarUnit)flags fromDate:(NSDate *)date; + (NSString *):(NSDate *)date descriptionWithCalendarFormat:(NSString *)format; ++ (NSArray *)WeasisCustomizationPaths; + @end NS_ASSUME_NONNULL_END diff --git a/Horos/Sources/Horos.m b/Horos/Sources/Horos.m index d83c02590b..c0213599dd 100644 --- a/Horos/Sources/Horos.m +++ b/Horos/Sources/Horos.m @@ -106,4 +106,8 @@ + (NSDateComponents *)components:(NSCalendarUnit)flags fromDate:(NSDate *)date { #pragma clang diagnostic pop } ++ (NSArray *)WeasisCustomizationPaths { + return @[ [@"~/Library/Application Support/Horos/Weasis" stringByExpandingTildeInPath], @"/Library/Application Support/Horos/Weasis" ]; +} + @end diff --git a/Horos/Sources/WebPortalConnection.mm b/Horos/Sources/WebPortalConnection.mm index 36a15c8218..668c1e58eb 100644 --- a/Horos/Sources/WebPortalConnection.mm +++ b/Horos/Sources/WebPortalConnection.mm @@ -75,6 +75,7 @@ This file is part of the Horos Project (www.horosproject.org) #import "N2Alignment.h" #import "AppController.h" #import "PluginManager.h" +#import "Horos.h" #import "JSON.h" @@ -495,8 +496,8 @@ - (void) alive:(id) sender { #ifndef OSIRIX_LIGHT BOOL assigned = false; - for (NSString *dir in self.portal.dirsToScanForFiles) { - NSString *path = [dir stringByAppendingPathComponent:self.requestedPath]; + for (NSString *dir in [Horos WeasisCustomizationPaths]) { + NSString *path = [dir stringByAppendingPathComponent:[self.requestedPath substringFromIndex:8]]; BOOL isDir; if ([[NSFileManager defaultManager] fileExistsAtPath:path isDirectory:&isDir] && !isDir) if ((response.data = [NSData dataWithContentsOfFile:path])) { From 9f64a6171db6e6865ce88cacc2f1d13a2e58c024 Mon Sep 17 00:00:00 2001 From: Alessandro Volz Date: Thu, 29 Mar 2018 11:32:32 +0200 Subject: [PATCH 2/3] include customization files when burning Weasis onto a CD/DVD/USBKey/DiskImage --- Horos/Sources/BurnerWindowController.m | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Horos/Sources/BurnerWindowController.m b/Horos/Sources/BurnerWindowController.m index 6de326e07c..8a9368deae 100644 --- a/Horos/Sources/BurnerWindowController.m +++ b/Horos/Sources/BurnerWindowController.m @@ -61,6 +61,7 @@ This file is part of the Horos Project (www.horosproject.org) #import "DicomFileDCMTKCategory.h" #import "DCMUIDs.h" #import "DicomDatabase+DCMTK.h" +#import "Horos.h" @implementation BurnerWindowController @@ -1045,10 +1046,16 @@ - (void) prepareCDContent: (NSMutableArray*) dbObjects :(NSMutableArray*) origin { thread.name = NSLocalizedString( @"Burning...", nil); thread.status = NSLocalizedString( @"Adding Weasis...", nil); + NSString* weasisPath = [[AppController sharedAppController] weasisBasePath]; for (NSString* subpath in [[NSFileManager defaultManager] contentsOfDirectoryAtPath:weasisPath error:NULL]) [[NSFileManager defaultManager] copyItemAtPath:[weasisPath stringByAppendingPathComponent:subpath] toPath:[burnFolder stringByAppendingPathComponent:subpath] error:NULL]; + NSString *burnWeasisPath = [burnFolder stringByAppendingPathComponent:@"weasis"]; + for (NSString *weasisPath in [Horos WeasisCustomizationPaths]) + for (NSString* subpath in [[NSFileManager defaultManager] contentsOfDirectoryAtPath:weasisPath error:NULL]) + [[NSFileManager defaultManager] copyItemAtPath:[weasisPath stringByAppendingPathComponent:subpath] toPath:[burnWeasisPath stringByAppendingPathComponent:subpath] error:NULL]; + // Change Label in Autorun.inf NSStringEncoding encoding; NSString *autorunInf = [NSString stringWithContentsOfFile: [burnFolder stringByAppendingPathComponent: @"Autorun.inf"] usedEncoding: &encoding error: nil]; From 9cfd2325db6efecd2bf0d3f9fb05bf2f301c1e85 Mon Sep 17 00:00:00 2001 From: Alessandro Volz Date: Thu, 29 Mar 2018 12:03:07 +0200 Subject: [PATCH 3/3] when burning Weasis customization files, merge directories --- Horos/Sources/BurnerWindowController.m | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/Horos/Sources/BurnerWindowController.m b/Horos/Sources/BurnerWindowController.m index 8a9368deae..ebfb3c3fa2 100644 --- a/Horos/Sources/BurnerWindowController.m +++ b/Horos/Sources/BurnerWindowController.m @@ -1052,9 +1052,21 @@ - (void) prepareCDContent: (NSMutableArray*) dbObjects :(NSMutableArray*) origin [[NSFileManager defaultManager] copyItemAtPath:[weasisPath stringByAppendingPathComponent:subpath] toPath:[burnFolder stringByAppendingPathComponent:subpath] error:NULL]; NSString *burnWeasisPath = [burnFolder stringByAppendingPathComponent:@"weasis"]; - for (NSString *weasisPath in [Horos WeasisCustomizationPaths]) - for (NSString* subpath in [[NSFileManager defaultManager] contentsOfDirectoryAtPath:weasisPath error:NULL]) - [[NSFileManager defaultManager] copyItemAtPath:[weasisPath stringByAppendingPathComponent:subpath] toPath:[burnWeasisPath stringByAppendingPathComponent:subpath] error:NULL]; + NSArray *skips = @[ @".DS_Store" ]; + for (NSString *weasisPath in [[Horos WeasisCustomizationPaths] reverseObjectEnumerator]) { // reversed to mimic the WebPortal priorities + NSDirectoryEnumerator *de = [[NSFileManager defaultManager] enumeratorAtPath:weasisPath]; + for (NSString *subpath in de) + if (![skips containsObject:subpath.lastPathComponent]) { + NSString *source = [weasisPath stringByAppendingPathComponent:subpath], *dest = [burnWeasisPath stringByAppendingPathComponent:subpath];; + if ([de.fileAttributes[NSFileType] isEqual:NSFileTypeDirectory]) { + [[NSFileManager defaultManager] createDirectoryAtPath:dest withIntermediateDirectories:YES attributes:nil error:NULL]; + } else { + if ([[NSFileManager defaultManager] fileExistsAtPath:dest]) + [[NSFileManager defaultManager] removeItemAtPath:dest error:NULL]; + [[NSFileManager defaultManager] copyItemAtPath:[weasisPath stringByAppendingPathComponent:subpath] toPath:dest error:NULL]; + } + } + } // Change Label in Autorun.inf NSStringEncoding encoding;