Browse Source

【FixBug】修复下载主题无法读取Bug

xcbosa mbp16 1 year ago
parent
commit
acb1f54483
2 changed files with 12 additions and 2 deletions
  1. 11 1
      XCTheme/Classes/Impl/XCThemeService.m
  2. 1 1
      XCTheme/Classes/Impl/XCThemeSpec.swift

+ 11 - 1
XCTheme/Classes/Impl/XCThemeService.m

@@ -73,7 +73,7 @@
         BOOL isDir = NO;
         [NSFileManager.defaultManager fileExistsAtPath:filePath isDirectory:&isDir];
         if (isDir) {
-            XCThemeSpec *theme = [[XCThemeSpec alloc] initWithThemeId:filePath];
+            XCThemeSpec *theme = [[XCThemeSpec alloc] initWithThemeId:file];
             if (theme) {
                 XCThemeSpecModel *specModel = [[XCThemeSpecModel alloc] initWithWrappedObject:theme];
                 [specs addObject:specModel];
@@ -123,6 +123,16 @@
     }
     
     NSString *rootPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject;
+    NSString *themeResourcesPath = [rootPath stringByAppendingString:@"/ThemeResources"];
+    BOOL isDirectory;
+    if ([NSFileManager.defaultManager fileExistsAtPath:themeResourcesPath isDirectory:&isDirectory]) {
+        if (!isDirectory) {
+            [NSFileManager.defaultManager removeItemAtPath:themeResourcesPath error:nil];
+            [NSFileManager.defaultManager createDirectoryAtPath:themeResourcesPath withIntermediateDirectories:YES attributes:nil error:nil];
+        }
+    } else {
+        [NSFileManager.defaultManager createDirectoryAtPath:themeResourcesPath withIntermediateDirectories:YES attributes:nil error:nil];
+    }
     NSString *downloadTHMPath = [rootPath stringByAppendingFormat:@"/ThemeResources/%@.thm", themeId];
     NSString *extractPath = [rootPath stringByAppendingFormat:@"/ThemeResources/%@", themeId];
     self.downloadBlock(themeId, downloadTHMPath, ^(BOOL success, NSString * _Nonnull reason) {

+ 1 - 1
XCTheme/Classes/Impl/XCThemeSpec.swift

@@ -54,7 +54,7 @@ public class XCThemeSpec: NSObject {
     
     public var themeRootPath: String {
         let searchPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first ?? ""
-        let documentPath = searchPath + "/\(themeId)"
+        let documentPath = searchPath + "/ThemeResources/\(themeId)"
         let isDir = UnsafeMutablePointer<ObjCBool>.allocate(capacity: 1)
         defer {
             isDir.deallocate()