DtkCore
DTK Core module
载入中...
搜索中...
未找到
dcapfile.h
浏览该文件的文档.
1// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd.
2//
3// SPDX-License-Identifier: LGPL-3.0-or-later
4
5#ifndef DCAPFILE_H
6#define DCAPFILE_H
7
8#include <dtkcore_global.h>
9
10#include <DObject>
11#include <QDir>
12#include <QFile>
13
14DCORE_BEGIN_NAMESPACE
15
16class DCapFilePrivate;
17class DCapFile : public QFile, public DObject
18{
19 Q_OBJECT
20 D_DECLARE_PRIVATE(DCapFile)
21 Q_DISABLE_COPY(DCapFile)
22
23public:
24 explicit DCapFile(QObject *parent = nullptr);
25 DCapFile(const QString &name, QObject *parent = nullptr);
26
27 ~DCapFile() override;
28
29 void setFileName(const QString &name);
30
31 bool exists() const;
32 static bool exists(const QString &fileName);
33
34#if DTK_VERSION < DTK_VERSION_CHECK(6, 0, 0, 0)
35 D_DECL_DEPRECATED_X("Use QFile::symLinkTarget() instead")
36 QString readLink() const;
37#endif
38#if QT_VERSION >= QT_VERSION_CHECK(5, 13, 0)
39 QString symLinkTarget() const;
40#endif
41 bool remove();
42 static bool remove(const QString &fileName);
43
44#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
46 static bool moveToTrash(const QString &fileName, QString *pathInTrash = nullptr);
47#endif
48
49 bool rename(const QString &newName);
50 static bool rename(const QString &oldName, const QString &newName);
51
52 bool link(const QString &newName);
53 static bool link(const QString &oldname, const QString &newName);
54
55 bool copy(const QString &newName);
56 static bool copy(const QString &fileName, const QString &newName);
57
58 bool open(OpenMode flags) override;
59
60 bool resize(qint64 sz) override;
61 static bool resize(const QString &filename, qint64 sz);
62
63private:
64 bool open(FILE *f, OpenMode ioFlags, FileHandleFlags handleFlags=DontCloseHandle);
65 bool open(int fd, OpenMode ioFlags, FileHandleFlags handleFlags=DontCloseHandle);
66};
67
68class DCapDirPrivate;
69class DCapDir : public QDir
70{
71public:
72 DCapDir(const DCapDir &);
73 DCapDir(const QString &path = QString());
74 DCapDir(const QString &path, const QString &nameFilter,
75 SortFlags sort = SortFlags(Name | IgnoreCase), Filters filter = AllEntries);
76 ~DCapDir();
77
78 void setPath(const QString &path);
79
80 bool cd(const QString &dirName);
81
82 QStringList entryList(Filters filters = NoFilter, SortFlags sort = NoSort) const;
83 QStringList entryList(const QStringList &nameFilters, Filters filters = NoFilter,
84 SortFlags sort = NoSort) const;
85
86 QFileInfoList entryInfoList(Filters filters = NoFilter, SortFlags sort = NoSort) const;
87 QFileInfoList entryInfoList(const QStringList &nameFilters, Filters filters = NoFilter,
88 SortFlags sort = NoSort) const;
89
90 bool mkdir(const QString &dirName) const;
91 bool rmdir(const QString &dirName) const;
92 bool mkpath(const QString &dirPath) const;
93 bool rmpath(const QString &dirPath) const;
94 bool exists() const;
95 bool remove(const QString &fileName);
96 bool rename(const QString &oldName, const QString &newName);
97 bool exists(const QString &name) const;
98
99private:
100 QSharedDataPointer<DCapDirPrivate> dd_ptr;
101};
102
103DCORE_END_NAMESPACE
104Q_DECLARE_SHARED(DTK_CORE_NAMESPACE::DCapDir)
105#endif // DCAPFILE_H
Definition dcapfile.h:70
bool exists(const QString &name) const
指定文件夹是否存在(如果找到同名文件, 此函数将返回 false)
bool cd(const QString &dirName)
将DCapDir的目录更改为dirName。 如果新目录存在, 则返回true;否则返回false 请注意, 如果新目录不存在, 则不执行逻辑cd()操作
DCapDir(const DCapDir &)
拷贝构造函数 构造一个DCapDir对象, 该对象是目录目录的DCapDir对象的副本
DCapDir(const QString &path=QString())
构造指向给定目录路径的DCapDir。如果 path 为空, 则使用程序的工作目录.
bool mkdir(const QString &dirName) const
创建文件夹
DCapDir(const QString &path, const QString &nameFilter, SortFlags sort=SortFlags(Name|IgnoreCase), Filters filter=AllEntries)
构造具有路径路径的DCapDir对象
QStringList entryList(Filters filters=NoFilter, SortFlags sort=NoSort) const
返回目录中所有文件和目录的名称列表
void setPath(const QString &path)
将目录的路径设置为path。该路径被清除了多余的"."、"... "和多个分隔符。没有检查这个路径的 目录是否真的存在; 路径可以是绝对路径也可以是相对路径, 绝对路径以目录分隔符"/"开始(在Win...
bool rmpath(const QString &dirPath) const
移除目录
bool mkpath(const QString &dirPath) const
创建目录
bool exists() const
文件夹是否存在(如果找到同名文件, 此函数将返回 false)
bool rmdir(const QString &dirName) const
移除文件夹
bool remove(const QString &fileName)
移除文件夹
bool rename(const QString &oldName, const QString &newName)
重命名文件夹
对于文件操作的安全封装, 提供了带有安全管控的文件读取, 相关漏洞见CWE_22
Definition dcapfile.h:18
static bool copy(const QString &fileName, const QString &newName)
该函数是重载DCapFile::copy(const QString &newName)区别是需要手动传入原始文件名
static bool rename(const QString &oldName, const QString &newName)
如果文件名存在则重命名文件
bool open(OpenMode flags) override
使用OpenMode模式打开文件, 如果成功返回true;否则返回false
static bool link(const QString &oldname, const QString &newName)
该函数是重载DCapFile::link()区别是需要手动传入原始文件名
static bool moveToTrash(const QString &fileName, QString *pathInTrash=nullptr)
如果传入文件名对应文件存在则将文件移动至指定回收站(垃圾桶)
bool copy(const QString &newName)
setFileName()指定的文件或者是在构造时指定的文件复制一份, 名为newName 如果成功, 则返回ture;否则返回false
QString symLinkTarget() const
这是一个重载函数 返回符号链接, 或Windows上的快捷方式指向的文件或目录的绝对路径, 如果该对象不是符号链接, 则返回一个空字符串。
DCapFile(const QString &name, QObject *parent=nullptr)
重载的构造函数, 接受传入一个文件名, 并创建一个文件对象
bool resize(qint64 sz) override
设置文件大小sz(以字节为单位)。如果调整大小成功, 则返回true;否则为false。如果sz大于当前文件, 则新字节将设置为 0;如果sz较小, 则文件将被简单地截断
static bool exists(const QString &fileName)
文件是否存在
static bool resize(const QString &filename, qint64 sz)
该函数是重载DCapFile::resize(qint64 sz)区别是手动指定文件名
bool rename(const QString &newName)
如果文件名存在则重命名文件
bool moveToTrash()
如果文件存在则将文件移动至默认回收站(垃圾桶)
void setFileName(const QString &name)
传入需要操作的文件名
static bool remove(const QString &fileName)
如果文件存在则删除文件
bool remove()
如果文件存在则删除文件
bool link(const QString &newName)
创建一个名为newName的链接
bool exists() const
文件是否存在
Definition dobject.h:25