LookinHierarchyFile.m 2.6 KB

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