1.0 finish

This commit is contained in:
2025-03-25 02:44:59 +08:00
parent cc7c995549
commit c84b88a422
23 changed files with 1126 additions and 127 deletions

View File

@@ -1,15 +1,30 @@
#include "fileconfigdecode.h"
#include <QDebug>
QScopedPointer<FileConfigDecode> FileConfigDecode::m_instance;
FileConfigDecode::FileConfigDecode()
{
// if (m_instance.isNull()) {
// m_instance.reset(new FileConfigDecode);
// }
initFile();
qDebug() << "read:" << autoSetup << rename << timeRename << autoCopy;
}
FileConfigDecode *FileConfigDecode::getInstance()
{
if (m_instance.isNull()) {
m_instance.reset(new FileConfigDecode);
}
return m_instance.data();
}
FileConfigDecode::~FileConfigDecode()
{
updateFile();
// updateFile();
// qDebug() << "write:" << autoSetup << rename << timeRename << autoCopy;
}
@@ -43,6 +58,21 @@ bool FileConfigDecode::getAutoCopy()
return autoCopy;
}
QString FileConfigDecode::getUserName()
{
return userName;
}
QString FileConfigDecode::getPassword()
{
return password;
}
RenameType FileConfigDecode::getRenameType()
{
return renameType;
}
void FileConfigDecode::setAddress(QString value)
{
this->address = value;
@@ -58,28 +88,64 @@ void FileConfigDecode::setPort(quint16 value)
void FileConfigDecode::setAutoSetup(bool value)
{
this->autoSetup = value;
updateFile();
// updateFile();
}
void FileConfigDecode::setRename(bool value)
{
this->rename = value;
if (value == true) {
renameType = (renameType == RENAME_TYPE_TIME) ? RENAME_TYPE_TIME : RENAME_TYPE_NORMAL;
}
else {
renameType = (renameType == RENAME_TYPE_TIME) ? RENAME_TYPE_TIME : RENAME_TYPE_NORMAL;
}
qDebug() << renameType;
updateFile();
// updateFile();
}
void FileConfigDecode::setTimeRename(bool value)
void FileConfigDecode::setTimeRename(bool value, int flag)
{
this->timeRename = value;
if (value) {
renameType = RENAME_TYPE_TIME;
}
if (!value && flag == 1) {
renameType = RENAME_TYPE_NORMAL;
}
if (!value && flag == 0) {
renameType = RENAME_TYPE_NONE;
}
qDebug() << renameType;
updateFile();
// updateFile();
}
void FileConfigDecode::setAutoCopy(bool value)
{
this->autoCopy = value;
updateFile();
// updateFile();
}
void FileConfigDecode::fileWrite(QString path, QString address, quint16 port, bool autosetup, bool rename, bool timerename, bool autocopy)
void FileConfigDecode::setUserName(QString username)
{
this->userName = username;
updateFile();
}
void FileConfigDecode::setPassword(QString password)
{
this->password = password;
updateFile();
}
void FileConfigDecode::fileWrite(QString path, QString address, bool autosetup,
bool rename, bool timerename, bool autocopy, QString username, QString password)
{
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
QSettings* config = new QSettings(path, QSettings::IniFormat);
@@ -105,6 +171,8 @@ void FileConfigDecode::fileWrite(QString path, QString address, quint16 port, bo
config->setValue("rename", rename);
config->setValue("timerename", timerename);
config->setValue("autocopy", autocopy);
config->setValue("username", username);
config->setValue("password", password);
config->endGroup();
delete config;
#endif
@@ -113,7 +181,7 @@ void FileConfigDecode::fileWrite(QString path, QString address, quint16 port, bo
void FileConfigDecode::initFile()
{
QString addDataPath = QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation);
QString addFilePath = addDataPath + "config.ini";
QString addFilePath = addDataPath + "/config.ini";
qDebug() << addFilePath;
QFile file(addFilePath);
if (file.exists()) {
@@ -126,6 +194,8 @@ void FileConfigDecode::initFile()
this->rename = config->value(section + "rename").toBool();
this->timeRename = config->value(section + "timerename").toBool();
this->autoCopy = config->value(section + "autocopy").toBool();
this->userName = config->value(section+"username").toString();
this->password = config->value(section+"password").toString();
checkConfig();
@@ -134,30 +204,38 @@ void FileConfigDecode::initFile()
else {
this->firstCreate = true;
this->address = "127.0.0.1";
this->port = 0;
this->address = "127.0.0.1:8080";
this->autoSetup = false;
this->rename = false;
this->timeRename = false;
this->autoCopy = false;
this->userName = "admin";
this->password = "admin";
fileWrite(addFilePath, address, port, autoSetup, rename, timeRename, autoCopy);
fileWrite(addFilePath, address, autoSetup, rename, timeRename, autoCopy, userName, password);
}
}
void FileConfigDecode::checkConfig()
{
if (address.isEmpty()) {
address = "127.0.0.1";
address = "127.0.0.1:8080";
}
if (rename)
renameType = RENAME_TYPE_NORMAL;
if (timeRename)
renameType = RENAME_TYPE_TIME;
qDebug() << renameType;
}
void FileConfigDecode::updateFile()
{
QString addDataPath = QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation);
QString addFilePath = addDataPath + "config.ini";
QString addFilePath = addDataPath + "/config.ini";
qDebug() << "write" << autoSetup << rename << timeRename << autoCopy;
fileWrite(addFilePath, address, port, autoSetup, rename, timeRename, autoCopy);
fileWrite(addFilePath, address, autoSetup, rename, timeRename, autoCopy, userName, password);
}