LookinHierarchyFile.m 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. //
  2. // LookinHierarchyFile.m
  3. // Lookin
  4. //
  5. // Created by Li Kai on 2019/5/12.
  6. // https://lookin.work
  7. //
  8. #import "LookinHierarchyFile.h"
  9. #import "NSArray+Lookin.h"
  10. @implementation LookinHierarchyFile
  11. - (void)encodeWithCoder:(NSCoder *)aCoder {
  12. [aCoder encodeInt:self.serverVersion forKey:@"serverVersion"];
  13. [aCoder encodeObject:self.hierarchyInfo forKey:@"hierarchyInfo"];
  14. [aCoder encodeObject:self.soloScreenshots forKey:@"soloScreenshots"];
  15. [aCoder encodeObject:self.groupScreenshots forKey:@"groupScreenshots"];
  16. }
  17. - (instancetype)initWithCoder:(NSCoder *)aDecoder {
  18. if (self = [super init]) {
  19. self.serverVersion = [aDecoder decodeIntForKey:@"serverVersion"];
  20. self.hierarchyInfo = [aDecoder decodeObjectForKey:@"hierarchyInfo"];
  21. self.soloScreenshots = [aDecoder decodeObjectForKey:@"soloScreenshots"];
  22. self.groupScreenshots = [aDecoder decodeObjectForKey:@"groupScreenshots"];
  23. }
  24. return self;
  25. }
  26. + (BOOL)supportsSecureCoding {
  27. return YES;
  28. }
  29. + (NSError *)verifyHierarchyFile:(LookinHierarchyFile *)hierarchyFile {
  30. if (![hierarchyFile isKindOfClass:[LookinHierarchyFile class]]) {
  31. return LookinErr_Inner;
  32. }
  33. if (hierarchyFile.serverVersion < LOOKIN_SUPPORTED_SERVER_MIN) {
  34. // 文件版本太旧
  35. // 如果不存在 serverVersion 这个字段,说明版本是 6
  36. int fileVersion = hierarchyFile.serverVersion ? : 6;
  37. NSString *detail = [NSString stringWithFormat:NSLocalizedString(@"The document was created by a Lookin app with too old version. Current Lookin app version is %@, but the document version is %@.", nil), @(LOOKIN_CLIENT_VERSION), @(fileVersion)];
  38. return [NSError errorWithDomain:LookinErrorDomain code:LookinErrCode_ServerVersionTooLow userInfo:@{NSLocalizedDescriptionKey:NSLocalizedString(@"Failed to open the document.", nil), NSLocalizedRecoverySuggestionErrorKey:detail}];
  39. }
  40. if (hierarchyFile.serverVersion > LOOKIN_SUPPORTED_SERVER_MAX) {
  41. // 文件版本太新
  42. NSString *detail = [NSString stringWithFormat:NSLocalizedString(@"Current Lookin app is too old to open this document. Current Lookin app version is %@, but the document version is %@.", nil), @(LOOKIN_CLIENT_VERSION), @(hierarchyFile.serverVersion)];
  43. return [NSError errorWithDomain:LookinErrorDomain code:LookinErrCode_ServerVersionTooHigh userInfo:@{NSLocalizedDescriptionKey:NSLocalizedString(@"Failed to open the document.", nil), NSLocalizedRecoverySuggestionErrorKey:detail}];
  44. }
  45. return nil;
  46. }
  47. @end