Marino Faggiana 7 年之前
父节点
当前提交
25eb1927fd

+ 30 - 2
Nextcloud.xcodeproj/project.pbxproj

@@ -423,6 +423,8 @@
 		F7B1FBC91E72E3D1001781FE /* SwiftWebVCActivityChrome.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7B1FBC21E72E3D1001781FE /* SwiftWebVCActivityChrome.swift */; };
 		F7B1FBCA1E72E3D1001781FE /* SwiftWebVCActivitySafari.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7B1FBC31E72E3D1001781FE /* SwiftWebVCActivitySafari.swift */; };
 		F7B3A4EE1E97818A000DACE8 /* CCLoginWeb.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7B3A4ED1E97818A000DACE8 /* CCLoginWeb.swift */; };
+		F7B4F1CA1F44356F00B53B42 /* libuchardet-ios.a in Frameworks */ = {isa = PBXBuildFile; fileRef = F7B4F1C61F44356F00B53B42 /* libuchardet-ios.a */; };
+		F7B4F1CB1F44356F00B53B42 /* NCUchardet.m in Sources */ = {isa = PBXBuildFile; fileRef = F7B4F1C81F44356F00B53B42 /* NCUchardet.m */; };
 		F7BAADC51ED5A87C00B7EAD4 /* CCCoreData.m in Sources */ = {isa = PBXBuildFile; fileRef = F7BAADB31ED5A87C00B7EAD4 /* CCCoreData.m */; };
 		F7BAADC61ED5A87C00B7EAD4 /* CCCoreData.m in Sources */ = {isa = PBXBuildFile; fileRef = F7BAADB31ED5A87C00B7EAD4 /* CCCoreData.m */; };
 		F7BAADC71ED5A87C00B7EAD4 /* CCCoreData.m in Sources */ = {isa = PBXBuildFile; fileRef = F7BAADB31ED5A87C00B7EAD4 /* CCCoreData.m */; };
@@ -1506,6 +1508,10 @@
 		F7B1FBC21E72E3D1001781FE /* SwiftWebVCActivityChrome.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwiftWebVCActivityChrome.swift; sourceTree = "<group>"; };
 		F7B1FBC31E72E3D1001781FE /* SwiftWebVCActivitySafari.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwiftWebVCActivitySafari.swift; sourceTree = "<group>"; };
 		F7B3A4ED1E97818A000DACE8 /* CCLoginWeb.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CCLoginWeb.swift; sourceTree = "<group>"; };
+		F7B4F1C61F44356F00B53B42 /* libuchardet-ios.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = "libuchardet-ios.a"; sourceTree = "<group>"; };
+		F7B4F1C71F44356F00B53B42 /* NCUchardet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NCUchardet.h; sourceTree = "<group>"; };
+		F7B4F1C81F44356F00B53B42 /* NCUchardet.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NCUchardet.m; sourceTree = "<group>"; };
+		F7B4F1C91F44356F00B53B42 /* uchardet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = uchardet.h; sourceTree = "<group>"; };
 		F7B61E861DC13C20009E938F /* MagicalRecord.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = MagicalRecord.xcodeproj; path = "Libraries external/MagicalRecord/MagicalRecord.xcodeproj"; sourceTree = SOURCE_ROOT; };
 		F7BAADB21ED5A87C00B7EAD4 /* CCCoreData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCCoreData.h; sourceTree = "<group>"; };
 		F7BAADB31ED5A87C00B7EAD4 /* CCCoreData.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CCCoreData.m; sourceTree = "<group>"; };
@@ -1948,6 +1954,7 @@
 				F714526D1DC1523B0006A5D4 /* libMagicalRecord.a in Frameworks */,
 				F75EDFAC1E8C106900E6F369 /* FirebaseAnalytics.framework in Frameworks */,
 				F75EDFAE1E8C106900E6F369 /* FirebaseInstanceID.framework in Frameworks */,
+				F7B4F1CA1F44356F00B53B42 /* libuchardet-ios.a in Frameworks */,
 				F7A377161EB2364A002856D3 /* Crashlytics.framework in Frameworks */,
 				F75EDFB11E8C106900E6F369 /* Protobuf.framework in Frameworks */,
 				F7FC7D561DC1F93800BB2C6A /* libz.tbd in Frameworks */,
@@ -3052,6 +3059,17 @@
 			path = Resources;
 			sourceTree = "<group>";
 		};
+		F7B4F1C51F44356F00B53B42 /* NCUchardet */ = {
+			isa = PBXGroup;
+			children = (
+				F7B4F1C61F44356F00B53B42 /* libuchardet-ios.a */,
+				F7B4F1C71F44356F00B53B42 /* NCUchardet.h */,
+				F7B4F1C81F44356F00B53B42 /* NCUchardet.m */,
+				F7B4F1C91F44356F00B53B42 /* uchardet.h */,
+			);
+			path = NCUchardet;
+			sourceTree = "<group>";
+		};
 		F7B61E871DC13C20009E938F /* Products */ = {
 			isa = PBXGroup;
 			children = (
@@ -3530,6 +3548,7 @@
 				F7D423A31F063B81009C9782 /* CTAssetsPickerController */,
 				F762CB9C1EACB89C00B38484 /* LMMediaPlayer */,
 				F7F54CAD1E5B14C700E19C62 /* MWPhotoBrowser */,
+				F7B4F1C51F44356F00B53B42 /* NCUchardet */,
 				F762CB7B1EACB81000B38484 /* REMenu */,
 				F7B1FBAF1E72E3D1001781FE /* SwiftWebVC */,
 				F762CB8B1EACB84400B38484 /* TWMessageBarManager */,
@@ -4658,6 +4677,7 @@
 				F73CC0691E813DFF006E3047 /* BKPasscodeDummyViewController.m in Sources */,
 				F762CB1A1EACB66200B38484 /* XLForm.m in Sources */,
 				F762CB051EACB66200B38484 /* XLFormTextFieldCell.m in Sources */,
+				F7B4F1CB1F44356F00B53B42 /* NCUchardet.m in Sources */,
 				F77B0E5B1D118A16002130FE /* UIImage+Rotating.m in Sources */,
 				F7A321561E9E2A070069AD1B /* CCFavoritesCell.m in Sources */,
 				F7D4237D1F0596C6009C9782 /* ReaderContentView.m in Sources */,
@@ -5293,7 +5313,11 @@
 				INFOPLIST_FILE = "$(SRCROOT)/iOSClient/Brand/iOSClient.plist";
 				IPHONEOS_DEPLOYMENT_TARGET = 8.0;
 				LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks";
-				LIBRARY_SEARCH_PATHS = "\"Libraries external\"/**";
+				LIBRARY_SEARCH_PATHS = (
+					Libraries,
+					"external/**",
+					"$(PROJECT_DIR)/iOSClient/Library/NCUchardet",
+				);
 				OTHER_LDFLAGS = (
 					"-Obj-C",
 					"-all_load",
@@ -5341,7 +5365,11 @@
 				INFOPLIST_FILE = "$(SRCROOT)/iOSClient/Brand/iOSClient.plist";
 				IPHONEOS_DEPLOYMENT_TARGET = 8.0;
 				LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks";
-				LIBRARY_SEARCH_PATHS = "\"Libraries external\"/**";
+				LIBRARY_SEARCH_PATHS = (
+					Libraries,
+					"external/**",
+					"$(PROJECT_DIR)/iOSClient/Library/NCUchardet",
+				);
 				OTHER_LDFLAGS = (
 					"-Obj-C",
 					"-all_load",

+ 32 - 0
iOSClient/Library/NCUchardet/NCUchardet.h

@@ -0,0 +1,32 @@
+//
+//  NCUchardet.h
+//  Crypto Cloud Technology Nextcloud
+//
+//  Created by Marino Faggiana on 16/08/17.
+//  Copyright (c) 2017 TWS. All rights reserved.
+//
+//  Author Marino Faggiana <m.faggiana@twsweb.it>
+//
+//  This program is free software: you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation, either version 3 of the License, or
+//  (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+//
+
+#import <Foundation/Foundation.h>
+
+@interface NCUchardet : NSObject
+
++ (NCUchardet *)sharedNUCharDet;
+
+- (NSString *)encodingDetectWithData:(NSData *)data;
+
+@end

+ 74 - 0
iOSClient/Library/NCUchardet/NCUchardet.m

@@ -0,0 +1,74 @@
+//
+//  NCUchardet.m
+//  Crypto Cloud Technology Nextcloud
+//
+//  Created by Marino Faggiana on 16/08/17.
+//  Copyright (c) 2017 TWS. All rights reserved.
+//
+//  Author Marino Faggiana <m.faggiana@twsweb.it>
+//
+//  This program is free software: you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation, either version 3 of the License, or
+//  (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+//
+
+#import "NCUchardet.h"
+#import "uchardet.h"
+
+@interface NCUchardet ()
+{
+   uchardet_t _detector;
+}
+@end
+
+@implementation NCUchardet
+
++ (NCUchardet *)sharedNUCharDet {
+    static NCUchardet *nuCharDet;
+    @synchronized(self) {
+        if (!nuCharDet) {
+            nuCharDet = [NCUchardet new];
+        }
+        return nuCharDet;
+    }
+}
+
+- (id)init
+{
+    self = [super init];
+    
+    if (self) {
+        _detector = uchardet_new();
+    }
+    
+    return self;
+}
+
+- (void)dealloc
+{
+    uchardet_delete(_detector);
+}
+
+- (NSString *)encodingDetectWithData:(NSData *)data
+{
+    uchardet_handle_data(_detector, [data bytes], [data length]);
+    uchardet_data_end(_detector);
+    
+    const char *charset = uchardet_get_charset(_detector);
+    NSString *encoding = [NSString stringWithCString:charset encoding:NSASCIIStringEncoding];
+    
+    uchardet_reset(_detector);
+    
+    return encoding;
+}
+
+@end

二进制
iOSClient/Library/NCUchardet/libuchardet-ios.a


+ 100 - 0
iOSClient/Library/NCUchardet/uchardet.h

@@ -0,0 +1,100 @@
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is Mozilla Universal charset detector code.
+ *
+ * The Initial Developer of the Original Code is
+ * Netscape Communications Corporation.
+ * Portions created by the Initial Developer are Copyright (C) 2001
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *          BYVoid <byvoid.kcp@gmail.com>
+ *          Jehan <jehan at girinstud.io>
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+#ifndef UCHARDET_H___
+#define UCHARDET_H___
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <stddef.h>
+
+/**
+ * A handle for a uchardet encoding detector.
+ */
+typedef struct uchardet * uchardet_t;
+
+/**
+ * Create an encoding detector.
+ * @return an instance of uchardet_t.
+ */
+uchardet_t uchardet_new(void);
+
+/**
+ * Delete an encoding detector.
+ * @param ud [in] the uchardet_t handle to delete.
+ */
+void uchardet_delete(uchardet_t ud);
+
+/**
+ * Feed data to an encoding detector.
+ * The detector is able to shortcut processing when it reaches certainty
+ * for an encoding, so you should not worry about limiting input data.
+ * As far as you should be concerned: the more the better.
+ *
+ * @param ud [in] handle of a instance of uchardet
+ * @param data [in] data
+ * @param len [in] number of byte of data
+ * @return non-zero number on failure.
+ */
+int uchardet_handle_data(uchardet_t ud, const char * data, size_t len);
+
+/**
+ * Notify an end of data to an encoding detctor.
+ * @param ud [in] handle of a instance of uchardet
+ */
+void uchardet_data_end(uchardet_t ud);
+
+/**
+ * Reset an encoding detector.
+ * @param ud [in] handle of a instance of uchardet
+ */
+void uchardet_reset(uchardet_t ud);
+
+/**
+ * Get an iconv-compatible name of the encoding that was detected.
+ * @param ud [in] handle of a instance of uchardet
+ * @return name of charset on success and "" on failure.
+ */
+const char * uchardet_get_charset(uchardet_t ud);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif

+ 3 - 2
iOSClient/Main/CCDetail.m

@@ -24,9 +24,9 @@
 #import "CCDetail.h"
 #import "AppDelegate.h"
 #import "CCMain.h"
+#import "NCUchardet.h"
 #import "NCBridgeSwift.h"
 
-
 #define TOOLBAR_HEIGHT 49.0f
 
 #define alertRequestPasswordPDF 1
@@ -389,7 +389,8 @@
         [headRequest setHTTPMethod:@"HEAD"];
         
         NSURLSessionDataTask *task = [session dataTaskWithRequest:headRequest completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
-            [self.webView loadData:[NSData dataWithContentsOfURL: url] MIMEType:response.MIMEType characterEncodingName:@"utf-8" baseURL:url];
+            NSString *encodingName = [[NCUchardet sharedNUCharDet] encodingDetectWithData:data];
+            [self.webView loadData:[NSData dataWithContentsOfURL: url] MIMEType:response.MIMEType characterEncodingName:encodingName baseURL:url];
         }];
         
         [task resume];