diff --git a/README.md b/README.md index b7b50492e673ae376a2f30f969765337629762a7..a0731e9238237c7f765313d4fa1ee242d3b1d612 100644 --- a/README.md +++ b/README.md @@ -34,3 +34,5 @@ Software architecture description 4. The most valuable open source project [GVP](https://gitee.com/gvp) 5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help) 6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) + +add diff --git a/interfaces/innerkits/native/file_remote_share/BUILD.gn b/interfaces/innerkits/native/file_remote_share/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..6f9b24ff6beb41defa7de82bbcfb6e4b3b885932 --- /dev/null +++ b/interfaces/innerkits/native/file_remote_share/BUILD.gn @@ -0,0 +1,40 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos.gni") + +config("file_share_config") { + visibility = [ ":*" ] + include_dirs = [ + "include", + "../common", + ] +} + +ohos_shared_library("fileshare_native") { + sources = [ "src/file_share.cpp" ] + + public_configs = [ ":file_share_config" ] + + external_deps = [ + "ability_base:base", + "ability_base:want", + "ability_base:zuri", + "access_token:libaccesstoken_sdk", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + ] + + part_name = "app_file_service" + subsystem_name = "filemanagement" +} diff --git a/interfaces/innerkits/native/file_remote_share/include/file_remote_share.h b/interfaces/innerkits/native/file_remote_share/include/file_remote_share.h new file mode 100644 index 0000000000000000000000000000000000000000..7ad4b0acf695a884a524719822381cfc0f7661db --- /dev/null +++ b/interfaces/innerkits/native/file_remote_share/include/file_remote_share.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef APP_FILE_SERVICE_FILE_REMOTE_SHARE +#define APP_FILE_SERVICE_FILE_REMOTE_SHARE + +#include +#include + +namespace OHOS { +namespace AppFileService { +using namespace std; + +#define HMDFS_IOC 0xf2 +#define HMDFS_IOC_GET_DRAG_PATH _IOR(HMDFS_IOC, 3, __u32) + +static string ChangeUriFromLocalToCloud (const string &uriStr, const int &userId); + +} // namespace AppFileService +} // namespace OHOS + +#endif \ No newline at end of file diff --git a/interfaces/innerkits/native/file_remote_share/src/file_remote_share.cpp b/interfaces/innerkits/native/file_remote_share/src/file_remote_share.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b39000d32019a985c1953d9c1d0b0437810f689f --- /dev/null +++ b/interfaces/innerkits/native/file_remote_share/src/file_remote_share.cpp @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "file_drag.h" + +#include +#include +#include +#include +#include +#include + +namespace OHOS { +namespace AppFileService { + +struct hmdfs_drag_info{ + unsigned long localLen; + unsigned long localPath; + unsigned long cloudLen; + unsigned long cloudPath; +}; + +static string GetBundleName (const string &uriStr) +{ + int bundlenameEnd = uriStr.find('/', URI_BUNDLENAME_BEGIN); + return uriStr.substr(URI_BUNDLENAME_BEGIN, + bundlenameEnd - URI_BUNDLENAME_BEGIN); + +} + +static string GetFilesName (const string &uriStr) +{ + int filesEnd = BUNDLENAME_BEGIN - 1; + for(int i = 0; i < LOOP_TIMES; i++){ + filesEnd = uriStr.find('/', filesEnd + 1); + } + return uriStr.substr(filesEnd + 1, + int(uri.size()) - filesEnd); +} + +static string CreateSrcStr(const string &bundleName, const int &userId, const string &filesName) +{ + string srcStr = SRC_DIR_MASK; + + srcStr.substr(SRC_BUNDLENAME_INSERT, bundleName); + srcStr.substr(SRC_USERID_INSERT, to_string(userId)); + srcStr += filesName; + + return srcStr; +} + +static string CreateDstStr(const string &bundleName, const string &filesName) +{ + string dstStr = DST_DIR_MASK; + + dstStr.substr(DST_BUNDLENAME_INSERT, bundleName); + dstStr += filesName; + + return dstStr; +} + +static GetSharePath(const int &userId) +{ + return SHAER_PATH_HEAD + to_string(userId) + SHAER_PATH_MID; +} + +static string ChangeUriFromLocalToCloud (const string &uriStr, const int &userId) +{ + const char *srcCh; + const char *dstCh; + string bundleName = GetBundleName(uriStr); + string filesName = GetFilesName(uriStr); + + string srcStr = CreateSrcStr(bundleName, userId, filesName); + string dstStr = CreateDstStr(bundleName, filesName); + + string dstUriStr = FILE_SCHEME + bundleName + dstStr; + + file hmdfsDevFd = open(GetSharePath(userId), O_RDONLY); + + hmdfs_drag_info hdi; + + srcCh = srcStr.c_str(); + dstCh = dstStr.c_str(); + + hdi.localLen = MAX_PATH_LENGTH; + hdi.localPath = static_cast (srcCh);; + hdi.cloudLen = MAX_PATH_LENGTH; + hdi.cloudPath = static_cast (dstCh); + + ioctl(hmdfsDevFd, HMDFS_IOC_GET_DRAG_PATH, hdi); + + return dstUriStr; +} + +} +} \ No newline at end of file