diff --git a/Pack/Default.SFX b/Pack/Default.SFX deleted file mode 100644 index 15c0e99..0000000 Binary files a/Pack/Default.SFX and /dev/null differ diff --git a/Pack/Rar.exe b/Pack/Rar.exe deleted file mode 100644 index c539aae..0000000 Binary files a/Pack/Rar.exe and /dev/null differ diff --git a/Pack/WinRAR.exe b/Pack/WinRAR.exe deleted file mode 100644 index 57f151a..0000000 Binary files a/Pack/WinRAR.exe and /dev/null differ diff --git a/Pack/note.txt b/Pack/note.txt deleted file mode 100644 index 85eded8..0000000 --- a/Pack/note.txt +++ /dev/null @@ -1,7 +0,0 @@ -TempMode - -Silent=1 - -Overwrite=1 - -Setup=./example.exe \ No newline at end of file diff --git a/Pack/run.bat b/Pack/run.bat deleted file mode 100644 index 39ffc5d..0000000 --- a/Pack/run.bat +++ /dev/null @@ -1,3 +0,0 @@ -@echo off -WinRAR.exe a FluentUI.exe ../* -rar.exe c -znote.txt FluentUI.exe \ No newline at end of file diff --git a/example/App.qml b/example/App.qml index 15a236d..b19ca2f 100644 --- a/example/App.qml +++ b/example/App.qml @@ -10,7 +10,6 @@ Window { color: "#00000000" Component.onCompleted: { FluApp.init(app,properties) - console.debug(properties.installHelper.applicationFilePath()) FluApp.isDark = false FluApp.routes = { "/":"qrc:/MainPage.qml", @@ -19,15 +18,7 @@ Window { "/Installer":"qrc:/Installer.qml", "/Uninstall":"qrc:/Uninstall.qml" } - if(installHelper.isNavigateUninstall()){ - FluApp.initialRoute = "/Uninstall" - }else{ - if(installHelper.isNavigateInstall()){ - FluApp.initialRoute = "/Installer" - }else{ - FluApp.initialRoute = "/" - } - } + FluApp.initialRoute = "/" FluApp.run() } diff --git a/example/InstallHelper.cpp b/example/InstallHelper.cpp deleted file mode 100644 index 7710b03..0000000 --- a/example/InstallHelper.cpp +++ /dev/null @@ -1,238 +0,0 @@ -#include "InstallHelper.h" - -#include -#include -#include - -#include -#include -#include - -#pragma comment(lib, "User32.lib") -#pragma comment(lib, "Ole32.lib") - -extern Q_CORE_EXPORT int qt_ntfs_permission_lookup; - -using CopyProgressCallback = std::function; - - -QString linkName = "FluentUI.lnk"; -QString uninstallLinkName = "Uninstall FluentUI.lnk"; -QString fileName = "FluentUI"; - -InstallHelper* InstallHelper::m_instance = nullptr; - -static QString getInstallConfigPath(){ - return QStandardPaths::writableLocation(QStandardPaths::ConfigLocation)+"/install"; -} - - -static void copyDir(const QString& srcPath, const QString& dstPath, CopyProgressCallback callback) -{ - QDir srcDir(srcPath); - QDir dstDir(dstPath); - if (!dstDir.exists()) { - dstDir.mkdir(dstPath); - } - QFileInfoList fileInfos = srcDir.entryInfoList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot); - int totalFiles = fileInfos.count(); - int currentFile = 0; - foreach (QFileInfo fileInfo, fileInfos) { - currentFile++; - QString srcFilePath = fileInfo.filePath(); - QString dstFilePath = dstPath + QDir::separator() + fileInfo.fileName(); - if (fileInfo.isDir()) { - copyDir(srcFilePath, dstFilePath, callback); - } else { - QFile dstFile(dstFilePath); - if(dstFile.exists()){ - dstFile.remove(); - } - QFile::copy(srcFilePath, dstFilePath); - } - if (callback != nullptr) { - callback(currentFile, totalFiles); - } - } -} - -static QString generateBatFile() -{ - QDir pathDir(getInstallConfigPath()); - if(!pathDir.exists()){ - pathDir.mkdir(getInstallConfigPath()); - } - QString filePath = getInstallConfigPath()+"/uninstall.bat"; - QFile batFile(filePath); - if (!batFile.open(QIODevice::WriteOnly | QIODevice::Text)) { - qWarning() << "Failed to create bat file: " << batFile.errorString(); - return ""; - } - QTextStream out(&batFile); - out << "@echo off\n"; - out << "set PID=%1" << "\n"; - out << "tasklist /FI \"PID eq %PID%\" | find /i \"%PID%\"\n"; - out << "if \"%ERRORLEVEL%\"==\"0\" (\n"; - out << " taskkill /pid %PID%\n"; - out << " timeout /t 2 /nobreak >nul\n"; - out << " echo The process with PID %PID% has been terminated.\n"; - out << ") else (\n"; - out << " echo The process with PID %PID% does not exist.\n"; - out << ")\n"; - out << "rd /s /q %2" <<"\n"; - batFile.close(); - return filePath; -} - -static bool registerUninstallProgram(const QString& displayName, const QString& installPath, const QString& version) -{ - const QString instalIniPath = getInstallConfigPath()+"/install.ini"; - QSettings settings(instalIniPath,QSettings::IniFormat); - settings.setValue("DisplayName", displayName); - settings.setValue("InstallLocation", installPath); - settings.setValue("DisplayVersion", version); - QString uninstallCommand = QString("\"%1\" --uninstall").arg(QCoreApplication::applicationFilePath()); - settings.setValue("UninstallString", uninstallCommand); - settings.sync(); - return true; -} - -static bool unRegisterUninstallProgram(){ - const QString instalIniPath = getInstallConfigPath()+"/install.ini"; - QFile instalIniFile(instalIniPath); - if(instalIniFile.exists()){ - instalIniFile.remove(); - } - return true; -} - -static void createHome(const QString& exePath){ - //创建桌面快捷方式 - QFile::link(exePath,QStandardPaths::writableLocation(QStandardPaths::DesktopLocation).append("/").append(linkName)); -} - -static void removeLink(){ - QString linkPath = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation).append("/").append(linkName); - QFile linkHome(linkPath); - if(linkHome.exists()){ - linkHome.remove(); - } - linkPath = QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation).append("/").append(fileName); - QFile linkStartMenu(linkPath); - if(linkStartMenu.exists()){ - linkStartMenu.remove(); - } -} - -static void createStartMenu(const QString& exePath){ - QString startMenuPath = QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation).append("/").append(fileName); - QDir dir(startMenuPath); - if(!dir.exists()) - { - dir.mkdir(startMenuPath); - } - if(dir.exists()) - { - QFile::link(exePath, startMenuPath.append("/").append(linkName)); - } -} - - - -static void createUninstallLink(QString exePath, QString path){ -#ifdef Q_OS_WIN - QString dst = path.append("\\").append(uninstallLinkName); - IShellLink *pShellLink; - QString args = "--uninstall"; - HRESULT hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,IID_IShellLink, (LPVOID *)&pShellLink); - if (SUCCEEDED(hres)) - { - pShellLink->SetPath(exePath.toStdWString().c_str()); - pShellLink->SetArguments(args.toStdWString().c_str()); - pShellLink->SetDescription(L"Fluent Uninstall"); - IPersistFile *pPersistFile; - hres = pShellLink->QueryInterface(IID_IPersistFile, (LPVOID *)&pPersistFile); - if (SUCCEEDED(hres)) - { - hres = pPersistFile->Save(dst.toStdWString().c_str(), TRUE); - pPersistFile->Release(); - } - pShellLink->Release(); - } - CoUninitialize(); -#endif -} - -InstallHelper *InstallHelper::getInstance() -{ - if(InstallHelper::m_instance == nullptr){ - InstallHelper::m_instance = new InstallHelper; - } - return InstallHelper::m_instance; -} - -InstallHelper::InstallHelper(QObject *parent) - : QObject{parent} -{ - installing(false); - uninstallSuccess(false); - errorInfo(""); -} - -bool InstallHelper::isNavigateInstall(){ - const QString instalIniPath = getInstallConfigPath()+"/install.ini"; - QFile installIniFle(instalIniPath); - if(installIniFle.exists()){ - return false; - } - return true; -} - -void InstallHelper::install(const QString& path,bool isHome,bool isStartMenu){ - qt_ntfs_permission_lookup ++; - QFileInfo folder(path.chopped(8)); - bool isWritable = folder.isWritable(); - qt_ntfs_permission_lookup --; - qDebug()< future = QtConcurrent::run(copyDir,QCoreApplication::applicationDirPath(),path,[=](int currentFile, int totalFiles){ - if(currentFile==totalFiles){ - if(isHome){ - createHome(exePath); - } - if(isStartMenu){ - createStartMenu(exePath); - } - createUninstallLink(exePath,path); - registerUninstallProgram("FluentUI",path,"1.0.0.0"); - } - }); - future.waitForFinished(); - QStringList args; - args<<"/c"; - args< -#include -#include - -#include "stdafx.h" - - -class InstallHelper : public QObject -{ - - Q_OBJECT - Q_PROPERTY_AUTO(bool,installing) - Q_PROPERTY_AUTO(bool,uninstallSuccess) - Q_PROPERTY_AUTO(QString,errorInfo) -public: - explicit InstallHelper(QObject *parent = nullptr); - - Q_INVOKABLE void install(const QString& path,bool isHome,bool isStartMenu); - - Q_INVOKABLE QString applicationFilePath(){ - return QGuiApplication::arguments().join(" "); - } - - Q_INVOKABLE bool isNavigateUninstall(){ - return QGuiApplication::arguments().contains("--uninstall"); -// return true; - } - - Q_INVOKABLE bool isNavigateInstall(); - - Q_INVOKABLE QString pid(){ - return QString::number(QCoreApplication::applicationPid()); - } - - Q_INVOKABLE void uninstall(); - static InstallHelper *getInstance(); -private: - static InstallHelper* m_instance; -}; - -#endif // INSTALLHELPER_H diff --git a/example/Installer.qml b/example/Installer.qml deleted file mode 100644 index 55ad1ef..0000000 --- a/example/Installer.qml +++ /dev/null @@ -1,172 +0,0 @@ -import QtQuick 2.15 -import QtQuick.Layouts 1.15 -import QtQuick.Dialogs 1.3 as Dialogs -import Qt.labs.platform 1.1 -import FluentUI 1.0 - -FluWindow { - - id:window - width: 800 - height: 400 - minimumWidth:800 - maximumWidth:800 - minimumHeight:400 - maximumHeight:400 - title:"安装向导" - - property string installPath: "C:\\Program Files" - property string installName: "FluentUI" - - FluAppBar{ - id:appbar - title: "安装向导" - } - - - Item{ - id:data - Dialogs.FileDialog { - id: fileDialog - selectFolder: true - folder: "file:///"+installPath - onAccepted: { - installPath = String(fileDialog.fileUrls[0]).replace("file:///","").replace(RegExp("/",'g'),"\\") - } - } - - - Connections{ - target: installHelper - function onErrorInfoChanged(){ - showError(installHelper.errorInfo) - } - } - } - - - ColumnLayout{ - - width: parent.width - - anchors{ - top: appbar.bottom - bottom: parent.bottom - topMargin: 20 - } - - RowLayout{ - - width: parent.width - - FluText{ - text:"安装路径:" - Layout.leftMargin: 30 - } - - FluTextBox{ - id:textbox_path - Layout.preferredHeight: 40 - Layout.fillWidth: true - text:installPath+ "\\" +installName - readOnly:true - } - - FluButton{ - text:"更改路径" - Layout.rightMargin: 30 - onClicked: { - fileDialog.open() - } - } - } - - FluCheckBox{ - id:checkbox_startmenu - Layout.topMargin: 20 - Layout.leftMargin: 30 - checked: true - text:"创建启动菜单快捷方式" - } - FluCheckBox{ - id:checkbox_home - Layout.leftMargin: 30 - Layout.topMargin: 5 - checked: true - text:"创建桌面图标" - } - - Item{ - width: 1 - Layout.fillHeight: true - } - - - Rectangle{ - - Layout.fillWidth: true - border.width: 1 - border.color: FluApp.isDark ? Qt.rgba(45/255,45/255,45/255,1) : Qt.rgba(238/255,238/255,238/255,1) - - height: 60 - color: FluApp.isDark ? "#323232" : "#FFFFFF" - RowLayout{ - anchors{ - right: parent.right - rightMargin: 30 - verticalCenter: parent.verticalCenter - } - spacing: 14 - FluButton{ - text:"取消" - onClicked: { - window.close() - } - } - FluFilledButton{ - text:"同意并安装" - onClicked: { - installHelper.install(textbox_path.text,checkbox_home.checked,checkbox_startmenu.checked) - } - } - FluButton{ - text:"不安装直接运行" - onClicked: { - FluApp.navigate("/") - window.close() - } - } - } - } - } - - Rectangle{ - - anchors.fill: parent - visible: installHelper.installing - color: "#80000000" - - MouseArea{ - anchors.fill: parent - hoverEnabled: true - } - - FluProgressBar{ - id:progress - anchors.centerIn: parent - } - - FluText{ - text:"正在安装..." - color:"#FFFFFF" - font.pixelSize: 20 - anchors{ - horizontalCenter: progress.horizontalCenter - bottom: progress.top - bottomMargin: 10 - } - } - - } - -} diff --git a/example/Uninstall.qml b/example/Uninstall.qml deleted file mode 100644 index 4ef7100..0000000 --- a/example/Uninstall.qml +++ /dev/null @@ -1,75 +0,0 @@ -import QtQuick 2.15 -import QtQuick.Layouts 1.15 -import QtQuick.Dialogs 1.3 as Dialogs -import Qt.labs.platform 1.1 -import FluentUI 1.0 - -FluWindow { - - id:window - width: 800 - height: 400 - minimumWidth:800 - maximumWidth:800 - minimumHeight:400 - maximumHeight:400 - title:"卸载向导" - - FluAppBar{ - id:appbar - title: "卸载向导" - } - - ColumnLayout{ - - width: parent.width - - anchors{ - top: appbar.bottom - bottom: parent.bottom - topMargin: 20 - } - - - - Item{ - Layout.preferredWidth : parent.width - Layout.fillHeight: true - FluText{ - text:"青山不改,绿水长流,有缘再见" - anchors.centerIn: parent - fontStyle:FluText.TitleLarge - } - } - - Rectangle{ - - Layout.fillWidth: true - border.width: 1 - border.color: FluApp.isDark ? Qt.rgba(45/255,45/255,45/255,1) : Qt.rgba(238/255,238/255,238/255,1) - - height: 60 - color: FluApp.isDark ? "#323232" : "#FFFFFF" - RowLayout{ - anchors{ - right: parent.right - rightMargin: 30 - verticalCenter: parent.verticalCenter - } - spacing: 14 - FluButton{ - text:"取消" - onClicked: { - window.close() - } - } - FluButton{ - text:"确定要卸载" - onClicked: { - installHelper.uninstall() - } - } - } - } - } -} diff --git a/example/example.pro b/example/example.pro index df40de6..f14783c 100644 --- a/example/example.pro +++ b/example/example.pro @@ -4,7 +4,6 @@ CONFIG += c++11 qtquickcompiler utf8_source DEFINES += QT_DEPRECATED_WARNINGS QT_NO_WARNING_OUTPUT SOURCES += \ - InstallHelper.cpp \ main.cpp RESOURCES += qml.qrc @@ -14,5 +13,4 @@ else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target HEADERS += \ - InstallHelper.h \ stdafx.h diff --git a/example/main.cpp b/example/main.cpp index 77bd19c..19b541a 100644 --- a/example/main.cpp +++ b/example/main.cpp @@ -3,11 +3,10 @@ #include #include #include -#include "InstallHelper.h" QMap properties(){ QMap map; - map["installHelper"] = QVariant::fromValue(QVariant::fromValue(InstallHelper::getInstance())); +// map["installHelper"] = QVariant::fromValue(QVariant::fromValue(InstallHelper::getInstance())); return map; } diff --git a/example/qml.qrc b/example/qml.qrc index fb457d3..387ebde 100644 --- a/example/qml.qrc +++ b/example/qml.qrc @@ -24,9 +24,7 @@ res/svg/avatar_10.svg res/svg/avatar_11.svg res/svg/avatar_12.svg - Installer.qml T_Awesome.qml T_TextBox.qml - Uninstall.qml