1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
/* Copyright (c) MediaArea.net SARL. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license that can
* be found in the License.html file in the root of the source tree.
*/
// Created by Max Pozdeev on 14.02.12.
#import "MediaInfoExporter.h"
@implementation MediaInfoExporter
@synthesize extensionHidden;
- (id)initWithObj:(oMediaInfoList*)obj {
if(self = [super init]) {
mil = [obj retain];
extensionHidden = NO;
}
return self;
}
- (void)dealloc {
[mil release];
mil = nil;
[super dealloc];
}
#pragma mark -
- (BOOL)exportToText:(NSURL*)url
{
NSString *text = [mil inform];
return [self saveData:[text dataUsingEncoding:NSUTF8StringEncoding] toUrl:url];
}
- (BOOL)exportFormat:(NSString*)format toUrl:(NSURL*)url
{
[mil setOption:@"Inform" withValue:format];
NSString *text = [mil inform];
[mil setOption:@"Inform" withValue:@""]; //reset
return [self saveData:[text dataUsingEncoding:NSUTF8StringEncoding] toUrl:url];
}
- (BOOL)saveData:(NSData*)aData toUrl:(NSURL*)url {
NSFileManager *fmgr = [[NSFileManager alloc] init]; //thread-safe instance
NSString *path = [url path];
BOOL fileExists = [fmgr fileExistsAtPath:path];
if(![aData writeToURL:url atomically:NO]) {
[fmgr release];
return NO;
}
//set attributes only for newly created file
if(!fileExists && extensionHidden) {
NSDictionary *attrs = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:extensionHidden], NSFileExtensionHidden,
nil];
[fmgr setAttributes:attrs ofItemAtPath:path error:nil];
}
[fmgr release];
return YES;
}
@end
|