From 6e71f93b13fe1aeba09d408b3ec75f0cf80e40ff Mon Sep 17 00:00:00 2001 From: emsquared Date: Sun, 5 Aug 2012 10:53:54 -0400 Subject: [PATCH] Limit number of lines in TLOFileLogger. --- Classes/Headers/NSDictionaryHelper.h | 5 ++- Classes/Headers/TLOFileLogger.h | 5 +-- .../Cocoa (Objective-C)/NSDictionaryHelper.m | 22 ++++-------- Classes/Library/TLOFileLogger.m | 34 ++++++++++++++++++- Classes/Views/Channel View/TVCLogController.m | 3 ++ Resources/Info.plist | 4 +-- 6 files changed, 50 insertions(+), 23 deletions(-) diff --git a/Classes/Headers/NSDictionaryHelper.h b/Classes/Headers/NSDictionaryHelper.h index 3599dcc75a..4ee0124de7 100755 --- a/Classes/Headers/NSDictionaryHelper.h +++ b/Classes/Headers/NSDictionaryHelper.h @@ -56,7 +56,8 @@ - (NSString *)keyIgnoringCase:(NSString *)baseKey; -- (NSDictionary *)sortedDictionary; +- (NSArray *)sortedDictionaryKeys; +- (id)sortedDictionary; @end @interface NSMutableDictionary (TXMutableDictionaryHelper) @@ -66,6 +67,4 @@ - (void)setLongLong:(long long)value forKey:(NSString *)key; - (void)setDouble:(TXNSDouble)value forKey:(NSString *)key; - (void)setPointer:(void *)value forKey:(NSString *)key; - -- (NSMutableDictionary *)sortedDictionary; @end \ No newline at end of file diff --git a/Classes/Headers/TLOFileLogger.h b/Classes/Headers/TLOFileLogger.h index e57b460b87..f68ef46cdc 100755 --- a/Classes/Headers/TLOFileLogger.h +++ b/Classes/Headers/TLOFileLogger.h @@ -57,6 +57,7 @@ @property (nonatomic, weak) IRCChannel *channel; @property (nonatomic, assign) BOOL writePlainText; // Plain text or property list. @property (nonatomic, assign) BOOL hashFilename; // UUID based, flat directory structure. +@property (nonatomic, assign) NSInteger maxEntryCount; // Only used if (writePlainText == NO) @property (nonatomic, strong) NSString *filename; @property (nonatomic, strong) NSString *fileWritePath; @property (nonatomic, strong) NSFileHandle *file; @@ -66,8 +67,8 @@ - (void)reset; - (void)reopenIfNeeded; -- (id)data; // Types: (NSData if writePlainText == YES), - // (NSDictionary if writePlainText == NO) +- (id)data; // Types: (NSData writePlainText == YES), + // (NSDictionary writePlainText == NO) // or nil - (NSString *)buildPath; diff --git a/Classes/Helpers/Cocoa (Objective-C)/NSDictionaryHelper.m b/Classes/Helpers/Cocoa (Objective-C)/NSDictionaryHelper.m index 78fd86957f..f3106632ba 100755 --- a/Classes/Helpers/Cocoa (Objective-C)/NSDictionaryHelper.m +++ b/Classes/Helpers/Cocoa (Objective-C)/NSDictionaryHelper.m @@ -180,9 +180,14 @@ - (NSString *)keyIgnoringCase:(NSString *)baseKey return nil; } -- (NSDictionary *)sortedDictionary +- (NSArray *)sortedDictionaryKeys { - NSArray *sortedKeys = [self.allKeys sortedArrayUsingSelector:@selector(compare:)]; + return [self.allKeys sortedArrayUsingSelector:@selector(compare:)]; +} + +- (id)sortedDictionary +{ + NSArray *sortedKeys = [self sortedDictionaryKeys]; NSMutableDictionary *newDict = [NSMutableDictionary dictionary]; @@ -229,17 +234,4 @@ - (void)setPointer:(void *)value forKey:(NSString *)key self[key] = [NSValue valueWithPointer:value]; } -- (NSMutableDictionary *)sortedDictionary -{ - NSArray *sortedKeys = [self.allKeys sortedArrayUsingSelector:@selector(compare:)]; - - NSMutableDictionary *newDict = [NSMutableDictionary dictionary]; - - for (NSString *key in sortedKeys) { - newDict[key] = self[key]; - } - - return newDict; -} - @end \ No newline at end of file diff --git a/Classes/Library/TLOFileLogger.m b/Classes/Library/TLOFileLogger.m index 21102e3e21..1c5c08f160 100755 --- a/Classes/Library/TLOFileLogger.m +++ b/Classes/Library/TLOFileLogger.m @@ -57,10 +57,42 @@ - (id)data } else { NSMutableDictionary *propertyList = self.propertyList.mutableCopy; + // ---- // + if (NSObjectIsNotEmpty(_temporaryPropertyListItems)) { [propertyList addEntriesFromDictionary:_temporaryPropertyListItems]; } - + + // ---- // + + if (self.maxEntryCount >= 1) { + if (propertyList.count >= self.maxEntryCount) { + NSArray *reverKkeys = propertyList.sortedDictionaryKeys.reverseObjectEnumerator.allObjects; + + NSMutableDictionary *newDict = [NSMutableDictionary dictionary]; + + NSInteger loopCount = 0; + + // ---- // + + for (NSString *key in reverKkeys) { + if (loopCount >= self.maxEntryCount) { + break; + } + + [newDict setObject:[propertyList objectForKey:key] forKey:key]; + + loopCount += 1; + } + + // ---- // + + return [newDict sortedDictionary]; + } + } + + // ---- // + return [propertyList sortedDictionary]; } diff --git a/Classes/Views/Channel View/TVCLogController.m b/Classes/Views/Channel View/TVCLogController.m index e4db591a50..5ef9e6b7fc 100755 --- a/Classes/Views/Channel View/TVCLogController.m +++ b/Classes/Views/Channel View/TVCLogController.m @@ -79,6 +79,8 @@ - (void)setMaxLines:(NSInteger)value [self savePosition]; [self setNeedsLimitNumberOfLines]; } + + self.logFile.maxEntryCount = [TPCPreferences maxLogLines]; } #pragma mark - @@ -109,6 +111,7 @@ - (void)setUp self.logFile.hashFilename = YES; self.logFile.writePlainText = NO; self.logFile.fileWritePath = [TPCPreferences whereTemporaryPath]; + self.logFile.maxEntryCount = [TPCPreferences maxLogLines]; self.view = [[TVCLogView alloc] initWithFrame:NSZeroRect]; diff --git a/Resources/Info.plist b/Resources/Info.plist index b11331e63b..4b65bac6bb 100755 --- a/Resources/Info.plist +++ b/Resources/Info.plist @@ -47,8 +47,8 @@ TXBundleBuildCodeName Turtle Soup TXBundleBuildNumber - 12263 + 12269 TXBundleBuildReference - 2.1.1-274-g363c972-appstore + 2.1.1-275-g410ffa5-debug