Skip to content

Commit

Permalink
v2.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
CreaterOS committed Mar 3, 2021
1 parent 6e4f8e5 commit e714e6d
Show file tree
Hide file tree
Showing 14 changed files with 433 additions and 64 deletions.
26 changes: 24 additions & 2 deletions Paintinglite/Paintinglite.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
68EB381C249083FD00DFC0CA /* PaintingliteUUID.m in Sources */ = {isa = PBXBuildFile; fileRef = 68EB381B249083FD00DFC0CA /* PaintingliteUUID.m */; };
68EDCA84248747E200031B41 /* PaintingliteIntellegenceSelect.m in Sources */ = {isa = PBXBuildFile; fileRef = 68EDCA83248747E200031B41 /* PaintingliteIntellegenceSelect.m */; };
68F260B224D1209700652C03 /* PaintingliteJSContext.m in Sources */ = {isa = PBXBuildFile; fileRef = 68F260B124D1209700652C03 /* PaintingliteJSContext.m */; };
EEFE2E1C25EF32A1005990B9 /* PaintingliteWarningHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = EEFE2E1B25EF32A1005990B9 /* PaintingliteWarningHelper.m */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -200,6 +201,8 @@
68EDCA852487A57700031B41 /* PaintingliteExecHeader.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PaintingliteExecHeader.h; sourceTree = "<group>"; };
68F260B024D1209700652C03 /* PaintingliteJSContext.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PaintingliteJSContext.h; sourceTree = "<group>"; };
68F260B124D1209700652C03 /* PaintingliteJSContext.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PaintingliteJSContext.m; sourceTree = "<group>"; };
EEFE2E1A25EF32A1005990B9 /* PaintingliteWarningHelper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PaintingliteWarningHelper.h; sourceTree = "<group>"; };
EEFE2E1B25EF32A1005990B9 /* PaintingliteWarningHelper.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PaintingliteWarningHelper.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -336,6 +339,8 @@
68DE9956247C9B9F0078EDD5 /* Paintinglite */ = {
isa = PBXGroup;
children = (
EEFE2E2025EF7339005990B9 /* Cache */,
EEFE2E1925EF3274005990B9 /* Helper */,
68DCAAFE2533579400D67C86 /* aes */,
68DCAAF02533578900D67C86 /* minizip */,
68DCAAEE2533577100D67C86 /* SSZipArchive.h */,
Expand All @@ -347,8 +352,6 @@
68DE9958247C9C260078EDD5 /* PaintingliteSessionManager.m */,
6888B26A24B9BF61003345D9 /* PaintingliteFileManager.h */,
6888B26B24B9BF61003345D9 /* PaintingliteFileManager.m */,
6888B26D24B9DBFA003345D9 /* PaintingliteCache.h */,
6888B26E24B9DBFA003345D9 /* PaintingliteCache.m */,
68DE9960247CA1140078EDD5 /* PaintingliteSessionFactory.h */,
68DE9961247CA1140078EDD5 /* PaintingliteSessionFactory.m */,
68DE9963247CA2490078EDD5 /* PaintingliteConfiguration.h */,
Expand Down Expand Up @@ -415,6 +418,24 @@
name = Frameworks;
sourceTree = "<group>";
};
EEFE2E1925EF3274005990B9 /* Helper */ = {
isa = PBXGroup;
children = (
EEFE2E1A25EF32A1005990B9 /* PaintingliteWarningHelper.h */,
EEFE2E1B25EF32A1005990B9 /* PaintingliteWarningHelper.m */,
);
path = Helper;
sourceTree = "<group>";
};
EEFE2E2025EF7339005990B9 /* Cache */ = {
isa = PBXGroup;
children = (
6888B26D24B9DBFA003345D9 /* PaintingliteCache.h */,
6888B26E24B9DBFA003345D9 /* PaintingliteCache.m */,
);
path = Cache;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -569,6 +590,7 @@
68DE9959247C9C260078EDD5 /* PaintingliteSessionManager.m in Sources */,
68DCAB1A2533579400D67C86 /* pwd2key.m in Sources */,
6883B28A24CC2E0500BAA3C2 /* XMLReader.m in Sources */,
EEFE2E1C25EF32A1005990B9 /* PaintingliteWarningHelper.m in Sources */,
6879F980248E66F300E66ABB /* PaintingliteCascadeShowerIUD.m in Sources */,
6800074E2488D19000FF75DE /* PaintingliteCUDOptions.m in Sources */,
68DE9926247C9B6A0078EDD5 /* AppDelegate.m in Sources */,
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Bucket
uuid = "E4B88C6F-06F9-4D47-ABC8-616245B2B7B9"
type = "1"
version = "2.0">
</Bucket>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>Paintinglite.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
</dict>
</plist>
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
#define STRONG_SELF __strong typeof(weakSelf) self = weakSelf;

@interface PaintingliteCache()<UIApplicationDelegate>

@property (nonatomic,assign)NSTimeInterval lauchTime; /// 启动时间
@property (nonatomic,strong)CADisplayLink *displayLink;
@end

@implementation PaintingliteCache
Expand All @@ -35,25 +36,48 @@ - (instancetype)init
if (self) {
//注册通知写日志
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pushCacheToLogFile) name:@"PaintingliteWriteTableLogNotification" object:self];
#if SD_UIKIT
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidEnterBackground:) name:UIApplicationDidEnterBackgroundNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillTerminate:) name:UIApplicationWillTerminateNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceiveMemoryWarning) name:UIApplicationDidReceiveMemoryWarningNotification object:nil];
#endif
//#if SD_UIKIT
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidFinishLaunching:) name:UIApplicationDidFinishLaunchingNotification object:nil];
// [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidEnterBackground:) name:UIApplicationDidEnterBackgroundNotification object:nil];
// [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillTerminate:) name:UIApplicationWillTerminateNotification object:nil];
/**
v1.3.3 开启退出写入缓存
*/
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillResignActive:) name:UIApplicationWillResignActiveNotification object:nil];
// [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidReceiveMemoryWarning:) name:UIApplicationDidReceiveMemoryWarningNotification object:nil];
//#endif
}
return self;
}

#pragma mark - Life Cricle
- (void)applicationDidFinishLaunching:(NSNotification *)notification {
/// 记录登陆时间
self.lauchTime = [[NSDate date] timeIntervalSince1970];
}

- (void)applicationWillResignActive:(NSNotification *)notification {
/// 程序退出写入缓存
__weak typeof(self) weakself = self;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[weakself pushCacheToLogFile];
});
}

#pragma mark - 添加表名称缓存
- (void)addSnapTableNameCache:(NSString *__nonnull)tableName{

if (tableName == NULL || tableName == (id)[NSNull null] || tableName.length == 0) {
return ;
}

NSUInteger tableCount = self.tableCount;

[self setObject:tableName forKey:[NSString stringWithFormat:@"snap_tableName_%zd",tableCount]];

tableCount++;
self.tableCount = tableCount;
}

#pragma mark - 添加表结构缓存
- (void)addSnapTableInfoNameCache:(NSArray *)infoArray tableName:(NSString *)tableName{
[self setObject:infoArray forKey:[NSString stringWithFormat:@"snap_%@_info",tableName]];
Expand All @@ -72,13 +96,32 @@ - (void)addDatabaseOptionsCache:(NSString *)optStr{

[self setObject:optStr forKey:[NSString stringWithFormat:@"database_opt_%d",count]];

/**
v1.3.3 添加程序运行超过10分钟写一次缓存
*/
CADisplayLink *displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(sendTimeByPushCache)];
[displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];
self.displayLink = displayLink;


if(count >= self.baseReleaseLine){
/* 发送通知,写入缓存文件 */
[[NSNotificationCenter defaultCenter] postNotificationName:@"PaintingliteWriteTableLogNotification" object:self];
count = 0;
}
}

- (void)sendTimeByPushCache {
/// 获得当前时间
long long int currentTime = (long long int)[[NSDate date] timeIntervalSince1970];

/// 十分钟上传一次
if (currentTime - (long long int)self.lauchTime >= 60 * 10) {
/// 写入日志
[self pushCacheToLogFile];
}
}

#pragma mark - 缓存写入日志文件
- (void)pushCacheToLogFile{
for (NSUInteger i = 1; i <= self.optCount; i++) {
Expand All @@ -90,7 +133,13 @@ - (void)pushCacheToLogFile{
NSArray<NSString *> *strArray = [optAndStatus componentsSeparatedByString:@" | "];

//写入文件
[[PaintingliteLog sharePaintingliteLog] writeLogFileOptions:[strArray firstObject] status:([[strArray lastObject] isEqualToString:@"success"]) ? PaintingliteLogSuccess : PaintingliteLogError completeHandler:nil];
@synchronized ([PaintingliteLog sharePaintingliteLog]) {
if ([strArray firstObject] == NULL) {
return ;
}
[[PaintingliteLog sharePaintingliteLog] writeLogFileOptions:[strArray firstObject] status:([[strArray lastObject] isEqualToString:@"success"]) ? PaintingliteLogSuccess : PaintingliteLogError completeHandler:nil];
}

/* 清除缓存 */
[self removeObjectForKey:cacheKey];
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// PaintingliteWarningHelper.h
// Paintinglite
//
// Created by CreaterOS on 2021/3/3.
// Copyright © 2021 Bryant Reyn. All rights reserved.
//

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@interface PaintingliteWarningHelper : NSObject

/// 警告
/// @param reason 原因
/// @param time 触发时间
/// @param solve 解决方案
/// @param args 其他参数
+ (void)warningReason:(NSString *)reason time:(NSDate *)time solve:(NSString *)solve args:(id __nullable)args;

/// 警告
/// @param reason 原因
/// @param session 会话
/// @param time 触发时间
/// @param solve 解决方案
/// @param args 其他参数
+ (void)warningReason:(NSString *)reason session:(NSString *)session time:(NSDate *)time solve:(NSString *)solve args:(id)args;

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//
// PaintingliteWarningHelper.m
// Paintinglite
//
// Created by CreaterOS on 2021/3/3.
// Copyright © 2021 Bryant Reyn. All rights reserved.
//

#import "PaintingliteWarningHelper.h"

@implementation PaintingliteWarningHelper

+ (void)warningReason:(NSString *)reason time:(NSDate *)time solve:(NSString *)solve args:(id)args {
#if DEBUG
/// 调试状态下进行输出
NSLog(@"Reson: %@",NSLocalizedString(reason, nil));
NSLog(@"Time: %@",time);
NSLog(@"Solve: %@",NSLocalizedString(solve, nil));

if (args != NULL && args != (id)[NSNull null]) {
NSError *error = nil;
NSData *data = [NSJSONSerialization dataWithJSONObject:args options:NSJSONWritingSortedKeys error:&error];
NSString *argStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"Args: %@",argStr);
}
#endif
}

+ (void)warningReason:(NSString *)reason session:(NSString *)session time:(NSDate *)time solve:(NSString *)solve args:(id)args {
#if DEBUG
/// 调试状态下进行输出
NSLog(@"Reson: %@",NSLocalizedString(reason, nil));
NSLog(@"Session: %@",NSLocalizedString(session, nil));
NSLog(@"Time: %@",time);
NSLog(@"Solve: %@",NSLocalizedString(solve, nil));

if (args != NULL && args != (id)[NSNull null]) {
NSError *error = nil;
NSData *data = [NSJSONSerialization dataWithJSONObject:args options:NSJSONWritingSortedKeys error:&error];
NSString *argStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"Args: %@",argStr);
}
#endif
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#import "PaintingliteSessionFactory.h"
#import "PaintingliteExec.h"
#import "PaintingliteLog.h"
#import "PaintingliteWarningHelper.h"

@interface PaintingliteDataBaseOptions()
@property (nonatomic,strong)PaintingliteExec *exec; //执行语句
Expand Down Expand Up @@ -45,6 +46,10 @@ - (Boolean)execTableOptForSQL:(sqlite3 *)ppDb sql:(NSString *)sql{
}

- (Boolean)execTableOptForSQL:(sqlite3 *)ppDb sql:(NSString *)sql completeHandler:(void (^)(PaintingliteSessionError * _Nonnull, Boolean))completeHandler{
if (sql == NULL || sql == (id)[NSNull null] || sql.length == 0) {
return NO;
}

Boolean flag = [self.exec sqlite3Exec:ppDb sql:sql];

if (completeHandler != nil) {
Expand All @@ -60,7 +65,11 @@ - (Boolean)createTableForName:(sqlite3 *)ppDb tableName:(NSString *)tableName co
}

- (Boolean)createTableForName:(sqlite3 *)ppDb tableName:(NSString *)tableName content:(NSString *)content completeHandler:(void (^)(PaintingliteSessionError * _Nonnull, Boolean))completeHandler{
NSAssert(tableName != NULL, @"Table Name IS Not Empty");
/// 表名称为空
if (tableName == NULL || tableName == (id)[NSNull null] || tableName.length == 0) {
[PaintingliteWarningHelper warningReason:@"TableName IS NULL OR TableName Len IS 0" time:[NSDate date] solve:@"Reset The TableName" args:nil];
return NO;
}

Boolean flag = [self.exec sqlite3Exec:ppDb tableName:tableName content:content];

Expand All @@ -78,6 +87,11 @@ - (Boolean)createTableForObj:(sqlite3 *)ppDb obj:(id)obj createStyle:(Paintingli
}

- (Boolean)createTableForObj:(sqlite3 *)ppDb obj:(id)obj createStyle:(PaintingliteDataBaseOptionsPrimaryKeyStyle)createStyle completeHandler:(void (^)(PaintingliteSessionError * _Nonnull, Boolean))completeHandler{
/// 对象为空
if (obj == NULL || obj == (id)[NSNull null]) {
[PaintingliteWarningHelper warningReason:@"Object IS NULL OR Object IS [NSNull null]" time:[NSDate date] solve:@"Reset The Object" args:nil];
return NO;
}

Boolean success = [self.exec sqlite3Exec:ppDb obj:obj status:PaintingliteExecCreate createStyle:createStyle];

Expand All @@ -96,6 +110,18 @@ - (BOOL)alterTableForName:(sqlite3 *)ppDb oldName:(NSString *__nonnull)oldName n
}

- (BOOL)alterTableForName:(sqlite3 *)ppDb oldName:(NSString *__nonnull)oldName newName:(NSString *__nonnull)newName completeHandler:(void (^)(PaintingliteSessionError * _Nonnull, Boolean))completeHandler{
/// 旧表名称
if (oldName == NULL || oldName == (id)[NSNull null] || oldName.length == 0) {
[PaintingliteWarningHelper warningReason:@"TableName IS NULL OR TableName Len IS 0" time:[NSDate date] solve:@"Reset The TableName" args:nil];
return NO;
}

/// 新表名称
if (newName == NULL || newName == (id)[NSNull null] || newName.length == 0) {
[PaintingliteWarningHelper warningReason:@"New TableName IS NULL OR New TableName Len IS 0" time:[NSDate date] solve:@"Reset The New TableName" args:nil];
return NO;
}

Boolean success = [self.exec sqlite3Exec:ppDb obj:@[oldName,newName] status:PaintingliteExecAlterRename createStyle:PaintingliteDataBaseOptionsDefault];

if (completeHandler != nil) {
Expand All @@ -110,6 +136,17 @@ - (BOOL)alterTableAddColumn:(sqlite3 *)ppDb tableName:(NSString *)tableName colu
}

- (BOOL)alterTableAddColumn:(sqlite3 *)ppDb tableName:(NSString *)tableName columnName:(NSString *)columnName columnType:(NSString *)columnType completeHandler:(void (^)(PaintingliteSessionError * _Nonnull, Boolean))completeHandler{

if (tableName == NULL || tableName == (id)[NSNull null] || tableName.length == 0) {
[PaintingliteWarningHelper warningReason:@"TableName IS NULL OR TableName Len IS 0" time:[NSDate date] solve:@"Reset The TableName" args:nil];
return NO;
}

if (columnName == NULL || columnName == (id)[NSNull null] || columnName.length == 0) {
[PaintingliteWarningHelper warningReason:@"ColumnName IS NULL OR ColumnName Len IS 0" time:[NSDate date] solve:@"Reset The ColumnName" args:nil];
return NO;
}

Boolean success = [self.exec sqlite3Exec:ppDb obj:@[tableName,columnName,columnType] status:PaintingliteExecAlterAddColumn createStyle:PaintingliteDataBaseOptionsDefault];

if (completeHandler != nil) {
Expand All @@ -128,6 +165,11 @@ - (BOOL)alterTableForObj:(sqlite3 *)ppDb obj:(id)obj{
}

- (BOOL)alterTableForObj:(sqlite3 *)ppDb obj:(id)obj completeHandler:(void (^)(PaintingliteSessionError * _Nonnull, Boolean))completeHandler{
if (obj == NULL || obj == (id)[NSNull null]) {
[PaintingliteWarningHelper warningReason:@"Object IS NULL OR Object IS [NSNull null]" time:[NSDate date] solve:@"Reset The Object" args:nil];
return NO;
}

Boolean success = [self.exec sqlite3Exec:ppDb obj:obj status:PaintingliteExecAlterObj createStyle:PaintingliteDataBaseOptionsDefault];

if (completeHandler != nil) {
Expand All @@ -143,7 +185,10 @@ - (Boolean)dropTableForTableName:(sqlite3 *)ppDb tableName:(NSString *)tableName
}

- (Boolean)dropTableForTableName:(sqlite3 *)ppDb tableName:(NSString *)tableName completeHandler:(void (^)(PaintingliteSessionError * _Nonnull, Boolean))completeHandler{
NSAssert(tableName != NULL, @"Table Name IS Not Empty");
if (tableName == NULL || tableName == (id)[NSNull null] || tableName.length == 0) {
[PaintingliteWarningHelper warningReason:@"TableName IS NULL OR TableName Len IS 0" time:[NSDate date] solve:@"Reset The TableName" args:nil];
return NO;
}

Boolean success = [self.exec sqlite3Exec:ppDb tableName:tableName];

Expand All @@ -160,6 +205,11 @@ - (Boolean)dropTableForObj:(sqlite3 *)ppDb obj:(id)obj{
}

- (Boolean)dropTableForObj:(sqlite3 *)ppDb obj:(id)obj completeHandler:(void (^)(PaintingliteSessionError * _Nonnull, Boolean))completeHandler{
if (obj == NULL || obj == (id)[NSNull null]) {
[PaintingliteWarningHelper warningReason:@"Object IS NULL OR Object IS [NSNull null]" time:[NSDate date] solve:@"Reset The Object" args:nil];
return NO;
}

Boolean success = [self.exec sqlite3Exec:ppDb obj:obj status:PaintingliteExecDrop createStyle:PaintingliteDataBaseOptionsDefault];

if (completeHandler != nil) {
Expand Down
Loading

0 comments on commit e714e6d

Please sign in to comment.