generated from zhangwei/Matrixai
76 lines
2.7 KiB
C++
76 lines
2.7 KiB
C++
/*
|
|
* Copyright (c) 2020.Huawei Technologies Co., Ltd. All rights reserved.
|
|
* 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 FILEMANAGER_H
|
|
#define FILEMANAGER_H
|
|
|
|
#ifdef _WIN32
|
|
#include <io.h>
|
|
#include <direct.h>
|
|
#include <windows.h>
|
|
#include <shlwapi.h>
|
|
#else
|
|
#include <unistd.h>
|
|
#include <sys/stat.h>
|
|
#include <sys/types.h>
|
|
#include <dirent.h>
|
|
#include <libgen.h>
|
|
#endif
|
|
#include <cstring>
|
|
#include <fstream>
|
|
#include <algorithm>
|
|
#include <vector>
|
|
#include <memory>
|
|
#include <cstdio>
|
|
#include <iostream>
|
|
#include <set>
|
|
|
|
#include "CommonDataType.h"
|
|
#include "Log.h"
|
|
#include "ErrorCode.h"
|
|
|
|
#ifdef _WIN32
|
|
#define access _access
|
|
#endif
|
|
|
|
#define BUF_SIZE 32U // Max buffer size
|
|
const int TWO = 2;
|
|
static const std::string SLASH = "/"; // delimiter used to split path
|
|
|
|
#ifndef _WIN32
|
|
mode_t SetFileDefaultUmask();
|
|
mode_t SetFileUmask(mode_t newUmask);
|
|
#endif
|
|
APP_ERROR GetRealPath(const std::string &srcPath, std::string &resolvedPath);
|
|
APP_ERROR ExistFile(const std::string &filePath);
|
|
std::vector<std::string> SplitPath(const std::string &str, const std::set<char> delimiters);
|
|
APP_ERROR CreateDir(const std::string &dirPath);
|
|
void CreateDirRecursively(const std::string &file);
|
|
void CreateDirRecursivelyByFile(const std::string &file);
|
|
APP_ERROR ReadFile(const std::string &filePath, RawData &fileData);
|
|
APP_ERROR ReadFileWithOffset(const std::string &fileName, RawData &fileData, const uint32_t offset);
|
|
APP_ERROR ReadBinaryFile(const std::string &fileName, std::shared_ptr<uint8_t> &buffShared, int &buffLength);
|
|
std::string GetExtension(const std::string &filePath);
|
|
std::string GetName(const std::string &filePath);
|
|
std::string GetParent(const std::string &filePath);
|
|
APP_ERROR ChangeDir(const std::string &dir);
|
|
void SaveFileAppend(const std::string &fileName, const std::string &stream, const int streamLength);
|
|
void SaveFileOverwrite(const std::string &fileName, const std::string &stream, const int streamLength);
|
|
void CopyFile(const std::string &srcFile, const std::string &destFile);
|
|
APP_ERROR SaveFileWithTimeStamp(std::shared_ptr<void> imageBuffer, uint32_t bufferSize, std::string folderName,
|
|
std::string fileName, std::string fileSuffix);
|
|
void GetCurTimeString(std::string &timeString);
|
|
#endif
|