diff --git a/build-library.sh b/build-library.sh index 2f9925be8..f89924a2a 100755 --- a/build-library.sh +++ b/build-library.sh @@ -8,8 +8,8 @@ if [ "$#" -eq 0 ]; then echo " target: osx ios iossimulator ioscatalyst androidarm androidarm64 androidx86 androidx86_64" echo "To control iOS, macOS builds set environment variables:" echo " minimum deployment target" - echo " - MACOSX_DEPLOYMENT_TARGET=10.15" - echo " - IPHONEOS_DEPLOYMENT_TARGET=12.0" + echo " - MACOSX_DEPLOYMENT_TARGET=11.0" + echo " - IPHONEOS_DEPLOYMENT_TARGET=13.0" echo " archs to build on macOS/iOS" echo " - ARCHS=\"x86_64 arm64\" (macOS)" echo " - ARCHS=\"arm64\" (iOS)" @@ -73,7 +73,7 @@ case "$@" in ;; esac TARGET_PATH=/Library/libdigidocpp.${TARGET} - : ${IPHONEOS_DEPLOYMENT_TARGET:="12.0"} + : ${IPHONEOS_DEPLOYMENT_TARGET:="13.0"} export IPHONEOS_DEPLOYMENT_TARGET CMAKEARGS=" -DCMAKE_OSX_SYSROOT=${SYSROOT} \ @@ -89,7 +89,7 @@ case "$@" in TARGET=macOS TARGET_PATH=/Library/libdigidocpp : ${ARCHS:="x86_64 arm64"} - : ${MACOSX_DEPLOYMENT_TARGET:="10.15"} + : ${MACOSX_DEPLOYMENT_TARGET:="11.0"} export MACOSX_DEPLOYMENT_TARGET esac diff --git a/examples/ios/libdigidocpp.xcodeproj/project.pbxproj b/examples/ios/libdigidocpp.xcodeproj/project.pbxproj index 17740beaa..4a999b2e6 100644 --- a/examples/ios/libdigidocpp.xcodeproj/project.pbxproj +++ b/examples/ios/libdigidocpp.xcodeproj/project.pbxproj @@ -9,12 +9,12 @@ /* Begin PBXBuildFile section */ 4E25CC401B5D1D85005E0B79 /* test.bdoc in Resources */ = {isa = PBXBuildFile; fileRef = 4E25CC3F1B5D1D85005E0B79 /* test.bdoc */; }; 4E25CC421B5D1EDA005E0B79 /* schema in Resources */ = {isa = PBXBuildFile; fileRef = 4E25CC411B5D1EDA005E0B79 /* schema */; }; + 4E26A2292AB4E38600E2B732 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4E26A2282AB4E38600E2B732 /* LaunchScreen.storyboard */; }; 4E76639E1B5A37AC00672ACF /* main.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4E76639D1B5A37AC00672ACF /* main.mm */; }; 4E7663A11B5A37AC00672ACF /* AppDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4E7663A01B5A37AC00672ACF /* AppDelegate.mm */; }; 4E7663A41B5A37AC00672ACF /* MasterViewController.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4E7663A31B5A37AC00672ACF /* MasterViewController.mm */; }; 4E7663AA1B5A37AC00672ACF /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4E7663A81B5A37AC00672ACF /* Main.storyboard */; }; 4E7663AC1B5A37AC00672ACF /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4E7663AB1B5A37AC00672ACF /* Images.xcassets */; }; - 4E7663AF1B5A37AC00672ACF /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4E7663AD1B5A37AC00672ACF /* LaunchScreen.xib */; }; 4E85E5F7285364BF00A65763 /* libdigidocpp_util.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 4E85E5F6285364BF00A65763 /* libdigidocpp_util.a */; }; 4ECD5FAA2010A15A00BCC616 /* libcrypto.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 4ECD5FA92010A15A00BCC616 /* libcrypto.a */; }; 4ECD5FB02010A1B700BCC616 /* libssl.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 4ECD5FAB2010A1B700BCC616 /* libssl.a */; }; @@ -32,6 +32,7 @@ /* Begin PBXFileReference section */ 4E25CC3F1B5D1D85005E0B79 /* test.bdoc */ = {isa = PBXFileReference; lastKnownFileType = file; path = test.bdoc; sourceTree = ""; }; 4E25CC411B5D1EDA005E0B79 /* schema */ = {isa = PBXFileReference; lastKnownFileType = folder; name = schema; path = "$(SDKPATH)/etc/digidocpp/schema"; sourceTree = ""; }; + 4E26A2282AB4E38600E2B732 /* LaunchScreen.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = LaunchScreen.storyboard; sourceTree = ""; }; 4E7663981B5A37AC00672ACF /* libdigidocpp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = libdigidocpp.app; sourceTree = BUILT_PRODUCTS_DIR; }; 4E76639C1B5A37AC00672ACF /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 4E76639D1B5A37AC00672ACF /* main.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = main.mm; sourceTree = ""; }; @@ -40,7 +41,6 @@ 4E7663A31B5A37AC00672ACF /* MasterViewController.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = MasterViewController.mm; sourceTree = ""; }; 4E7663A91B5A37AC00672ACF /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 4E7663AB1B5A37AC00672ACF /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; - 4E7663AE1B5A37AC00672ACF /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; 4E85E5F6285364BF00A65763 /* libdigidocpp_util.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libdigidocpp_util.a; path = "$(SDKPATH)/lib/libdigidocpp_util.a"; sourceTree = ""; }; 4EAC9AA729125D5200A39880 /* libdigidocpp.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = libdigidocpp.entitlements; sourceTree = ""; }; 4ECD5FA92010A15A00BCC616 /* libcrypto.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libcrypto.a; path = "$(SDKPATH)/lib/libcrypto.a"; sourceTree = ""; }; @@ -106,8 +106,8 @@ 4E7663A01B5A37AC00672ACF /* AppDelegate.mm */, 4E7663A31B5A37AC00672ACF /* MasterViewController.mm */, 4E7663A81B5A37AC00672ACF /* Main.storyboard */, + 4E26A2282AB4E38600E2B732 /* LaunchScreen.storyboard */, 4E7663AB1B5A37AC00672ACF /* Images.xcassets */, - 4E7663AD1B5A37AC00672ACF /* LaunchScreen.xib */, 4E76639B1B5A37AC00672ACF /* Supporting Files */, ); path = libdigidocpp; @@ -204,8 +204,8 @@ files = ( 4E25CC421B5D1EDA005E0B79 /* schema in Resources */, 4E7663AA1B5A37AC00672ACF /* Main.storyboard in Resources */, - 4E7663AF1B5A37AC00672ACF /* LaunchScreen.xib in Resources */, 4E7663AC1B5A37AC00672ACF /* Images.xcassets in Resources */, + 4E26A2292AB4E38600E2B732 /* LaunchScreen.storyboard in Resources */, 4E25CC401B5D1D85005E0B79 /* test.bdoc in Resources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -234,14 +234,6 @@ name = Main.storyboard; sourceTree = ""; }; - 4E7663AD1B5A37AC00672ACF /* LaunchScreen.xib */ = { - isa = PBXVariantGroup; - children = ( - 4E7663AE1B5A37AC00672ACF /* Base */, - ); - name = LaunchScreen.xib; - sourceTree = ""; - }; /* End PBXVariantGroup section */ /* Begin XCBuildConfiguration section */ @@ -249,16 +241,19 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; @@ -271,12 +266,12 @@ CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = NO; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - ENABLE_BITCODE = NO; + DEBUG_INFORMATION_FORMAT = dwarf; ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; GCC_C_LANGUAGE_STANDARD = gnu11; @@ -287,14 +282,13 @@ "DEBUG=1", "$(inherited)", ); - GCC_SYMBOLS_PRIVATE_EXTERN = NO; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; GCC_WARN_UNDECLARED_SELECTOR = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 12.0; + IPHONEOS_DEPLOYMENT_TARGET = 13.0; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; @@ -305,16 +299,19 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; @@ -327,12 +324,12 @@ CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = NO; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - ENABLE_BITCODE = NO; ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; GCC_C_LANGUAGE_STANDARD = gnu11; @@ -343,7 +340,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 12.0; + IPHONEOS_DEPLOYMENT_TARGET = 13.0; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; @@ -358,10 +355,6 @@ CODE_SIGN_ENTITLEMENTS = libdigidocpp/libdigidocpp.entitlements; CODE_SIGN_IDENTITY = "iPhone Developer"; CURRENT_PROJECT_VERSION = "$(BUILD_NUMBER)"; - FRAMEWORK_SEARCH_PATHS = ( - "$(inherited)", - "$(PROJECT_DIR)/libdigidocpp", - ); GCC_PREPROCESSOR_DEFINITIONS = ( "$(inherited)", "TESTING=$(TESTING)", @@ -372,19 +365,12 @@ "$(MINIZIP)", ); INFOPLIST_FILE = libdigidocpp/Info.plist; - INFOPLIST_KEY_CFBundleDisplayName = Libdigidocpp; INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.productivity"; - INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen.xib; + INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; + INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen; INFOPLIST_KEY_UIMainStoryboardFile = Main; INFOPLIST_KEY_UISupportedInterfaceOrientations = "UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown"; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - ); - LIBRARY_SEARCH_PATHS = ( - "$(SDKPATH)/lib", - "$(PROJECT_DIR)", - ); + LIBRARY_SEARCH_PATHS = "$(SDKPATH)/lib"; MARKETING_VERSION = 1.0; MINIZIP = "$(PROJECT_DIR)/../../src/minizip"; PRODUCT_BUNDLE_IDENTIFIER = "ee.ria.$(PRODUCT_NAME:rfc1034identifier)"; @@ -392,10 +378,8 @@ SDKPATH = /Library/libdigidocpp.iphoneos; "SDKPATH[sdk=iphonesimulator*]" = /Library/libdigidocpp.iphonesimulator; "SDKPATH[sdk=macosx*]" = /Library/libdigidocpp.iphonecatalyst; - SUPPORTED_PLATFORMS = "iphoneos iphonesimulator"; SUPPORTS_MACCATALYST = YES; SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO; - TARGETED_DEVICE_FAMILY = "1,2"; TESTING = 0; }; name = Debug; @@ -408,10 +392,6 @@ CODE_SIGN_ENTITLEMENTS = libdigidocpp/libdigidocpp.entitlements; CODE_SIGN_IDENTITY = "iPhone Developer"; CURRENT_PROJECT_VERSION = "$(BUILD_NUMBER)"; - FRAMEWORK_SEARCH_PATHS = ( - "$(inherited)", - "$(PROJECT_DIR)/libdigidocpp", - ); GCC_PREPROCESSOR_DEFINITIONS = ( "$(inherited)", "TESTING=$(TESTING)", @@ -422,19 +402,12 @@ "$(MINIZIP)", ); INFOPLIST_FILE = libdigidocpp/Info.plist; - INFOPLIST_KEY_CFBundleDisplayName = Libdigidocpp; INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.productivity"; - INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen.xib; + INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; + INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen; INFOPLIST_KEY_UIMainStoryboardFile = Main; INFOPLIST_KEY_UISupportedInterfaceOrientations = "UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown"; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - ); - LIBRARY_SEARCH_PATHS = ( - "$(SDKPATH)/lib", - "$(PROJECT_DIR)", - ); + LIBRARY_SEARCH_PATHS = "$(SDKPATH)/lib"; MARKETING_VERSION = 1.0; MINIZIP = "$(PROJECT_DIR)/../../src/minizip"; PRODUCT_BUNDLE_IDENTIFIER = "ee.ria.$(PRODUCT_NAME:rfc1034identifier)"; @@ -442,10 +415,8 @@ SDKPATH = /Library/libdigidocpp.iphoneos; "SDKPATH[sdk=iphonesimulator*]" = /Library/libdigidocpp.iphonesimulator; "SDKPATH[sdk=macosx*]" = /Library/libdigidocpp.iphonecatalyst; - SUPPORTED_PLATFORMS = "iphoneos iphonesimulator"; SUPPORTS_MACCATALYST = YES; SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO; - TARGETED_DEVICE_FAMILY = "1,2"; TESTING = 0; }; name = Release; diff --git a/examples/ios/libdigidocpp/AppDelegate.mm b/examples/ios/libdigidocpp/AppDelegate.mm index 8f8463ad2..dca970e74 100644 --- a/examples/ios/libdigidocpp/AppDelegate.mm +++ b/examples/ios/libdigidocpp/AppDelegate.mm @@ -48,7 +48,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( digidoc::initialize("libdigidocpp iOS"); // Skip URL will be opened in application: openURL: if (launchOptions[UIApplicationLaunchOptionsURLKey] == nil) { - [self openFile:[NSBundle.mainBundle pathForResource:@"test" ofType:@"bdoc"] copy:YES]; + [self openFile:[NSBundle.mainBundle pathForResource:@"test" ofType:@"bdoc"]]; } } catch(const digidoc::Exception &e) { NSLog(@"%s", e.msg().c_str()); @@ -59,30 +59,14 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary *)options { delete self.doc; self.doc = nullptr; - BOOL result = [self openFile:url.path copy:YES]; + BOOL result = [self openFile:url.path]; UITableViewController *master = (UITableViewController*)self.window.rootViewController; [master.tableView reloadData]; return result; } -- (BOOL)openFile:(NSString*)from copy:(BOOL)copy { +- (BOOL)openFile:(NSString*)path { try { - NSArray *documentPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); - NSString *path = [NSString stringWithFormat:@"%@/%@", documentPath.firstObject, from.lastPathComponent]; - NSError *error; - [NSFileManager.defaultManager removeItemAtPath:path error:&error]; - if (error) { - NSLog(@"Failed to remove file %@", error); - error = nil; - } - if (copy) - [NSFileManager.defaultManager copyItemAtPath:from toPath:path error:&error]; - else - [NSFileManager.defaultManager moveItemAtPath:from toPath:path error:&error]; - if (error) { - NSLog(@"Failed to copy/move file %@", error); - return NO; - } self.doc = digidoc::Container::openPtr(path.UTF8String).release(); return YES; } catch(const digidoc::Exception &e) { diff --git a/examples/ios/libdigidocpp/Base.lproj/LaunchScreen.xib b/examples/ios/libdigidocpp/Base.lproj/LaunchScreen.xib deleted file mode 100644 index 2971f2fa1..000000000 --- a/examples/ios/libdigidocpp/Base.lproj/LaunchScreen.xib +++ /dev/null @@ -1,43 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/examples/ios/libdigidocpp/Base.lproj/Main.storyboard b/examples/ios/libdigidocpp/Base.lproj/Main.storyboard index 427e7ef55..33bf72114 100644 --- a/examples/ios/libdigidocpp/Base.lproj/Main.storyboard +++ b/examples/ios/libdigidocpp/Base.lproj/Main.storyboard @@ -1,9 +1,10 @@ - + - + + @@ -14,7 +15,7 @@ - + @@ -85,4 +86,9 @@ + + + + + diff --git a/examples/ios/libdigidocpp/Info.plist b/examples/ios/libdigidocpp/Info.plist index 3132b7414..5a4507387 100644 --- a/examples/ios/libdigidocpp/Info.plist +++ b/examples/ios/libdigidocpp/Info.plist @@ -2,6 +2,8 @@ + LSSupportsOpeningDocumentsInPlace + CFBundleDocumentTypes diff --git a/examples/ios/libdigidocpp/LaunchScreen.storyboard b/examples/ios/libdigidocpp/LaunchScreen.storyboard new file mode 100644 index 000000000..af34ebaa1 --- /dev/null +++ b/examples/ios/libdigidocpp/LaunchScreen.storyboard @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/ios/libdigidocpp/MasterViewController.mm b/examples/ios/libdigidocpp/MasterViewController.mm index 42c368a3c..01ae6c152 100644 --- a/examples/ios/libdigidocpp/MasterViewController.mm +++ b/examples/ios/libdigidocpp/MasterViewController.mm @@ -85,7 +85,7 @@ - (IBAction)runTest:(id)sender { if(unzResult != UNZ_OK) break; std::string fileNameTmp(fileInfo.size_filename, 0); - unzResult = unzGetCurrentFileInfo(open, &fileInfo, &fileNameTmp[0], uLong(fileNameTmp.size()), nullptr, 0, nullptr, 0); + unzResult = unzGetCurrentFileInfo(open, &fileInfo, fileNameTmp.c_str(), uLong(fileNameTmp.size()), nullptr, 0, nullptr, 0); if(unzResult != UNZ_OK) break; @@ -115,11 +115,11 @@ - (IBAction)runTest:(id)sender { try { std::unique_ptr d(digidoc::Container::open(file.UTF8String)); for (const digidoc::DataFile *f: d->dataFiles()) { - NSMutableDictionary *tmp = [[NSMutableDictionary alloc] init]; - tmp[@"f"] = [NSString stdstring:f->fileName()]; - tmp[@"m"] = [NSString stdstring:f->mediaType()]; - tmp[@"s"] = @(f->fileSize()); - [dataFiles addObject:tmp]; + [dataFiles addObject:@{ + @"f": [NSString stdstring:f->fileName()], + @"m": [NSString stdstring:f->mediaType()], + @"s": @(f->fileSize()), + }]; } for (const digidoc::Signature *s: d->signatures()) { diff --git a/prepare_osx_build_environment.sh b/prepare_osx_build_environment.sh index 042408048..2ca55b517 100755 --- a/prepare_osx_build_environment.sh +++ b/prepare_osx_build_environment.sh @@ -5,7 +5,7 @@ XERCES_DIR=xerces-c-3.2.4 XALAN_DIR=xalan_c-1.12 XMLSEC_DIR=xml-security-c-2.0.4 XSD=xsd-4.0.0-i686-macosx -OPENSSL_DIR=openssl-3.0.9 +OPENSSL_DIR=openssl-3.0.10 LIBXML2_DIR=libxml2-2.10.3 ANDROID_NDK=android-ndk-r25 FREETYPE_DIR=freetype-2.10.1 @@ -67,7 +67,7 @@ case "$@" in CONFIGURE="--host=arm-apple-darwin --enable-static --disable-shared --disable-dependency-tracking" SYSROOT=$(xcrun -sdk iphonesimulator --show-sdk-path) : ${ARCHS:="x86_64"} - : ${IPHONEOS_DEPLOYMENT_TARGET:="12.0"} + : ${IPHONEOS_DEPLOYMENT_TARGET:="13.0"} export IPHONEOS_DEPLOYMENT_TARGET export CFLAGS="-arch ${ARCHS// / -arch } -isysroot ${SYSROOT}" ;; @@ -77,7 +77,7 @@ case "$@" in CONFIGURE="--host=x86_64-apple-darwin --enable-static --disable-shared --disable-dependency-tracking" SYSROOT=$(xcrun -sdk macosx --show-sdk-path) : ${ARCHS:="x86_64 arm64"} - : ${IPHONEOS_DEPLOYMENT_TARGET:="12.0"} + : ${IPHONEOS_DEPLOYMENT_TARGET:="13.0"} export IPHONEOS_DEPLOYMENT_TARGET export CFLAGS="-arch ${ARCHS// / -arch } -target x86_64-apple-ios-macabi -isysroot ${SYSROOT}" ;; @@ -87,7 +87,7 @@ case "$@" in CONFIGURE="--host=arm-apple-darwin --enable-static --disable-shared --disable-dependency-tracking" SYSROOT=$(xcrun -sdk iphoneos --show-sdk-path) : ${ARCHS:="arm64"} - : ${IPHONEOS_DEPLOYMENT_TARGET:="12.0"} + : ${IPHONEOS_DEPLOYMENT_TARGET:="13.0"} export IPHONEOS_DEPLOYMENT_TARGET export CFLAGS="-arch ${ARCHS// / -arch } -isysroot ${SYSROOT}" ;; @@ -97,7 +97,7 @@ case "$@" in CONFIGURE="--disable-static --enable-shared --disable-dependency-tracking" SYSROOT=$(xcrun -sdk macosx --show-sdk-path) : ${ARCHS:="x86_64 arm64"} - : ${MACOSX_DEPLOYMENT_TARGET:="10.15"} + : ${MACOSX_DEPLOYMENT_TARGET:="11.0"} export MACOSX_DEPLOYMENT_TARGET export CFLAGS="-arch ${ARCHS// / -arch } " ;; @@ -423,8 +423,8 @@ case "$@" in echo " tasks: xerces, xalan, openssl, xmlsec, xsd, all, help" echo "To control iOS, macOS builds set environment variables:" echo " minimum deployment target" - echo " - MACOSX_DEPLOYMENT_TARGET=10.15" - echo " - IPHONEOS_DEPLOYMENT_TARGET=12.0" + echo " - MACOSX_DEPLOYMENT_TARGET=11.0" + echo " - IPHONEOS_DEPLOYMENT_TARGET=13.0" echo " archs to build on macOS/iOS" echo " - ARCHS=\"x86_64 arm64\" (macOS)" echo " - ARCHS=\"arm64\" (iOS)" diff --git a/src/ASiContainer.cpp b/src/ASiContainer.cpp index d77705984..5f158ce8d 100644 --- a/src/ASiContainer.cpp +++ b/src/ASiContainer.cpp @@ -152,7 +152,7 @@ unique_ptr ASiContainer::dataStream(const string &path, const ZipSeria { unique_ptr data; if(d->properties[path].size > MAX_MEM_FILE) - data = make_unique(File::encodeName(File::tempFileName()), fstream::in|fstream::out|fstream::binary|fstream::trunc); + data = make_unique(File::tempFileName(), fstream::in|fstream::out|fstream::binary|fstream::trunc); else data = make_unique(); z.extract(path, *data); diff --git a/src/digidoc-tool.cpp b/src/digidoc-tool.cpp index dcdf5c2a7..3a2cdfeb6 100644 --- a/src/digidoc-tool.cpp +++ b/src/digidoc-tool.cpp @@ -32,7 +32,6 @@ #include "util/log.h" #include -#include #include #include #include diff --git a/src/util/File.cpp b/src/util/File.cpp index a9aecd2cc..9d896714d 100644 --- a/src/util/File.cpp +++ b/src/util/File.cpp @@ -23,7 +23,6 @@ #include #include -#include #include #include #include @@ -62,7 +61,7 @@ using f_statbuf = struct stat; using f_utimbuf = struct utimbuf; #endif -stack File::tempFiles; +stack File::tempFiles; string File::confPath() { @@ -73,63 +72,21 @@ string File::confPath() #elif defined(_WIN32) return dllPath("digidocpp.dll"); #else - return path(env("SNAP"), DIGIDOCPP_CONFIG_DIR "/"); + fs::path result; + if(char *var = getenv("SNAP")) + result = fs::path(var); + return (result / DIGIDOCPP_CONFIG_DIR "/").u8string(); #endif } -#ifndef _WIN32 -string File::env(string_view varname) -{ - if(char *var = getenv(varname.data())) - return decodeName(var); - return {}; -} -#endif - /** * Encodes path to compatible std lib * @param fileName path * @return encoded path */ -File::f_string File::encodeName(string_view fileName) -{ - if(fileName.empty()) - return {}; -#ifdef __APPLE__ - CFStringRef ref = CFStringCreateWithBytesNoCopy({}, (UInt8 *)fileName.data(), - CFIndex(fileName.size()), kCFStringEncodingUTF8, FALSE, kCFAllocatorNull); - string out(fileName.size() * 2, 0); - CFStringGetFileSystemRepresentation(ref, out.data(), CFIndex(out.size())); - CFRelease(ref); - out.resize(strlen(out.c_str())); -#else - f_string out = fs::u8path(fileName); -#endif - return out; -} - -/** - * Decodes path from std lib path - * @param localFileName path - * @return decoded path - */ -string File::decodeName(const f_string_view &localFileName) +fs::path File::encodeName(string_view fileName) { - if(localFileName.empty()) - return {}; -#ifdef __APPLE__ - CFMutableStringRef ref = CFStringCreateMutable(nullptr, 0); - CFStringAppendCString(ref, localFileName.data(), kCFStringEncodingUTF8); - CFStringNormalize(ref, kCFStringNormalizationFormC); - - string out(localFileName.size() * 2, 0); - CFStringGetCString(ref, out.data(), CFIndex(out.size()), kCFStringEncodingUTF8); - CFRelease(ref); - out.resize(strlen(out.c_str())); -#else - string out = fs::path(localFileName).u8string(); -#endif - return out; + return fs::u8path(fileName); } /** @@ -140,8 +97,7 @@ string File::decodeName(const f_string_view &localFileName) */ bool File::fileExists(const string& path) { - f_statbuf fileInfo; - return f_stat(encodeName(path).c_str(), &fileInfo) == 0 && (fileInfo.st_mode & S_IFMT) == S_IFREG; + return fs::is_regular_file(fs::u8path(path)); } #ifdef _WIN32 @@ -167,14 +123,13 @@ string File::dllPath(string_view dll) time_t File::modifiedTime(const string &path) { f_statbuf fileInfo; - return f_stat(encodeName(path).c_str(), &fileInfo) ? time(nullptr) : fileInfo.st_mtime; + return f_stat(fs::u8path(path).c_str(), &fileInfo) ? time(nullptr) : fileInfo.st_mtime; } void File::updateModifiedTime(const string &path, time_t time) { - f_string _path = encodeName(path); f_utimbuf u_time { time, time }; - if(f_utime(_path.c_str(), &u_time)) + if(f_utime(fs::u8path(path).c_str(), &u_time)) THROW("Failed to update file modified time."); } @@ -193,8 +148,7 @@ string File::fileExtension(const string &path) */ unsigned long File::fileSize(const string &path) { - f_statbuf fileInfo; - return f_stat(encodeName(path).c_str(), &fileInfo) ? 0 : (unsigned long)fileInfo.st_size; + return fs::file_size(fs::u8path(path)); } /** @@ -266,26 +220,22 @@ string File::path(string dir, string_view relativePath) /** * @return returns temporary filename. */ -string File::tempFileName() +fs::path File::tempFileName() { #ifdef _WIN32 // requires TMP environment variable to be set wchar_t *fileName = _wtempnam(nullptr, nullptr); // TODO: static buffer, not thread-safe if(!fileName) THROW("Failed to create a temporary file name."); - string path = fs::path(fileName).u8string(); + tempFiles.emplace(fileName); free(fileName); #else -#ifdef __APPLE__ - string path = File::path(env("TMPDIR"), "XXXXXX"); -#else - string path = "/tmp/XXXXXX"; -#endif - if(mkstemp(path.data()) == -1) + string tmp = "XXXXXX"; + if(mkstemp(tmp.data()) == -1) THROW("Failed to create a temporary file name."); + tempFiles.push(fs::temp_directory_path() / tmp); #endif - tempFiles.push(path); - return path; + return tempFiles.top(); } /** @@ -300,7 +250,7 @@ void File::createDirectory(string path) THROW("Can not create directory with no name."); if(path.back() == '/' || path.back() == '\\') path.pop_back(); - f_string _path = encodeName(path); + auto _path = fs::u8path(path); #ifdef _WIN32 int result = _wmkdir(_path.c_str()); #else @@ -327,7 +277,9 @@ string File::digidocppPath() CoTaskMemFree(knownFolder); return appData; #elif defined(ANDROID) - return path(env("HOME"), ".digidocpp"); + if(char *var = getenv("HOME")) + return (fs::path(var) / ".digidocpp").u8string(); + return {}; #else string buf(sysconf(_SC_GETPW_R_SIZE_MAX), 0); passwd pwbuf {}; @@ -363,21 +315,19 @@ string File::fullPathUrl(const string &path) */ void File::deleteTempFiles() { + error_code ec; while(!tempFiles.empty()) { - if(!removeFile(tempFiles.top())) - WARN( "Tried to remove the temporary file or directory '%s', but failed.", tempFiles.top().c_str() ); + if(!fs::remove(tempFiles.top(), ec) || ec) + WARN("Tried to remove the temporary file or directory '%s', but failed.", tempFiles.top().u8string().c_str()); tempFiles.pop(); } } bool File::removeFile(const string &path) { -#ifdef _WIN32 - return _wremove(fs::u8path(path).c_str()) == 0; -#else - return remove(encodeName(path).c_str()) == 0; -#endif + error_code ec; + return fs::remove(fs::u8path(path), ec); } /** diff --git a/src/util/File.h b/src/util/File.h index 65983e980..48faf5399 100644 --- a/src/util/File.h +++ b/src/util/File.h @@ -21,6 +21,7 @@ #include "../Exception.h" +#include #include namespace digidoc @@ -34,18 +35,9 @@ namespace digidoc class File { public: -#ifdef _WIN32 - using f_string = std::wstring; - using f_string_view = std::wstring_view; -#else - using f_string = std::string; - using f_string_view = std::string_view; -#endif static std::string confPath(); static std::string digidocppPath(); - static f_string encodeName(std::string_view fileName); - static std::string decodeName(const f_string_view &localFileName); - static bool isRelative(const std::string &path); + static std::filesystem::path encodeName(std::string_view fileName); static time_t modifiedTime(const std::string &path); static void updateModifiedTime(const std::string &path, time_t time); static bool fileExists(const std::string& path); @@ -55,7 +47,7 @@ namespace digidoc static std::string directory(const std::string& path); static std::string path(std::string dir, std::string_view relativePath); static std::string fullPathUrl(const std::string &path); - static std::string tempFileName(); + static std::filesystem::path tempFileName(); static void createDirectory(std::string path); static void deleteTempFiles(); static bool removeFile(const std::string &path); @@ -71,10 +63,7 @@ namespace digidoc #ifdef __APPLE__ static std::string frameworkResourcesPath(std::string_view name); #endif - static std::stack tempFiles; -#ifndef _WIN32 - static std::string env(std::string_view varname); -#endif + static std::stack tempFiles; }; } diff --git a/src/util/ZipSerialize.cpp b/src/util/ZipSerialize.cpp index cae1ebe95..c3236cc77 100644 --- a/src/util/ZipSerialize.cpp +++ b/src/util/ZipSerialize.cpp @@ -20,7 +20,6 @@ #include "ZipSerialize.h" #include "DateTime.h" -#include "File.h" #include "log.h" #include @@ -30,6 +29,7 @@ #endif #include +#include #include using namespace digidoc; @@ -63,14 +63,14 @@ ZipSerialize::ZipSerialize(string path, bool create) if(create) { DEBUG("ZipSerialize::create(%s)", d->path.c_str()); - d->create = zipOpen2((const char*)util::File::encodeName(d->path).c_str(), APPEND_STATUS_CREATE, nullptr, &d->def); + d->create = zipOpen2((const char*)filesystem::u8path(d->path).c_str(), APPEND_STATUS_CREATE, nullptr, &d->def); if(!d->create) THROW("Failed to create ZIP file '%s'.", d->path.c_str()); } else { DEBUG("ZipSerialize::open(%s)", d->path.c_str()); - d->open = unzOpen2((const char*)util::File::encodeName(d->path).c_str(), &d->def); + d->open = unzOpen2((const char*)filesystem::u8path(d->path).c_str(), &d->def); if(!d->open) THROW("Failed to open ZIP file '%s'.", d->path.c_str()); } diff --git a/src/xml/URIResolver.cpp b/src/xml/URIResolver.cpp index 514acef02..41a276bbd 100644 --- a/src/xml/URIResolver.cpp +++ b/src/xml/URIResolver.cpp @@ -74,24 +74,21 @@ BinInputStream* URIResolver::resolveURI(const XMLCh *uri) throw XSECException(XSECException::ErrorOpeningURI, "XSECURIResolverXerces - anonymous references not supported in default URI Resolvers"); -#ifdef _WIN32 - string _uri = File::decodeName(reinterpret_cast(uri)); -#else - string _uri = xsd::cxx::xml::transcode(uri); -#endif - if(strncmp(_uri.c_str(), "/", 1) == 0) _uri.erase(0, 1); + string _uri = File::fromUriPath(xsd::cxx::xml::transcode(uri)); + if(_uri.front() == '/') + _uri.erase(0); for(const DataFile *file: doc_->dataFiles()) { - if(file->fileName() == File::fromUriPath(_uri)) + if(file->fileName() == _uri) return new IStreamInputStream(static_cast(file)->m_is.get()); } if(doc_->mediaType() == ASiC_E::MIMETYPE_ADOC) { - ASiC_E *adoc = static_cast(doc_); + auto *adoc = static_cast(doc_); for(const DataFile *file: adoc->metaFiles()) { - if(file->fileName() == File::fromUriPath(_uri)) + if(file->fileName() == _uri) return new IStreamInputStream(static_cast(file)->m_is.get()); } }