Skip to content

Commit

Permalink
- 多线程加锁
Browse files Browse the repository at this point in the history
- 安装程序更新
  • Loading branch information
yjmthu committed Aug 4, 2023
1 parent a81953c commit 82605ef
Show file tree
Hide file tree
Showing 13 changed files with 270 additions and 147 deletions.
7 changes: 5 additions & 2 deletions pluginmgr/include/httplib.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ class HttpLib {
void ClearHeader() {
m_Headers.clear();
}
const std::u8string& GetUrl() const {
return m_Url;
}
void SetRedirect(long redirect);
void SetPostData(void* data, size_t size);
Response* Get();
Expand Down Expand Up @@ -111,8 +114,8 @@ class HttpLib {
void SetAsyncCallback();
bool SendRequest();
bool RecvResponse();
std::u8string GetDomain();
std::u8string GetPath();
std::u8string GetDomain() const;
std::u8string GetPath() const;
private:
bool ReadStatusCode();
bool ReadHeaders();
Expand Down
1 change: 1 addition & 0 deletions pluginmgr/include/pluginmgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class PluginMgr {
static int Exec();
static void Quit();
void Restart();
static std::filesystem::path GetJunkDir();
private:
static QSharedMemory* CreateSharedMemory();
void DetachSharedMemory();
Expand Down
5 changes: 3 additions & 2 deletions pluginmgr/include/update.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,17 @@ class PluginUpdate: public QObject
void DownloadUpgrade(Callback callback);
void CopyExecutable() const;
static std::array<int, 3> ParseVersion(const std::wstring& vStr);
static std::filesystem::path GetTempFilePath();
std::filesystem::path GetTempFilePath() const;
UpgradeConfig m_Settings;
private:
class NeoTimer* m_Timer;
std::u8string m_ZipUrl;
std::unique_ptr<YJson> m_LatestData;
std::unique_ptr<class HttpLib> m_DataRequest;
std::ofstream m_File;
signals:
void AskInstall();
void QuitApp() const;
void QuitApp(QString exe, QStringList arg) const;
};

#endif // UPDATE_H
8 changes: 2 additions & 6 deletions pluginmgr/src/httplib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,12 @@ void HttpLib::RequestStatusCallback(HINTERNET hInternet, DWORD_PTR dwContext, DW
if (bResults) {
bResults = object.m_Response.status < 400;
} else {
// locker.unlock();
object.EmitFinish(L"HttpLib Error: HttpLib ReadStatusCode Error.");
break;
}
if (bResults) {
bResults = object.ReadHeaders();
} else {
// locker.unlock();
object.EmitFinish(L"HttpLib StatusCode Error.");
break;
}
Expand All @@ -87,7 +85,6 @@ void HttpLib::RequestStatusCallback(HINTERNET hInternet, DWORD_PTR dwContext, DW
locker.unlock();
WinHttpQueryDataAvailable(hInternet, NULL);
} else {
// locker.unlock();
object.EmitFinish(L"HttpLib ReadHeaders Error.");
}
break;
Expand Down Expand Up @@ -132,7 +129,6 @@ void HttpLib::RequestStatusCallback(HINTERNET hInternet, DWORD_PTR dwContext, DW
auto const* pAsyncResult = (WINHTTP_ASYNC_RESULT*)lpvStatusInformation;
DWORD dwError = pAsyncResult->dwError; // The error code
DWORD dwResult = pAsyncResult->dwResult; // The ID of the called function
// locker.unlock();
object.EmitFinish(std::format(L"Winhttp status error. Error code: {}, error id: {}.", dwError, dwResult));
break;
}
Expand Down Expand Up @@ -234,7 +230,7 @@ void HttpLib::SetAsyncCallback()
#endif
}

std::u8string HttpLib::GetDomain()
std::u8string HttpLib::GetDomain() const
{
std::u8string result;
#ifdef __linux__
Expand Down Expand Up @@ -262,7 +258,7 @@ std::u8string HttpLib::GetDomain()
return result;
}

std::u8string HttpLib::GetPath()
std::u8string HttpLib::GetPath() const
{
size_t pos;
if (m_Url.starts_with(u8"https://")) {
Expand Down
8 changes: 8 additions & 0 deletions pluginmgr/src/pluginmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,14 @@ void PluginMgr::Restart()
QApplication::quit();
}

fs::path PluginMgr::GetJunkDir() {
fs::path result = "junk";
if (!fs::exists(result)) {
fs::create_directory(result);
}
return fs::absolute(result);
}

void PluginMgr::WriteSharedFlag(QSharedMemory* sharedMemory, int flag) {
//m_SharedMemory->setKey(QStringLiteral("__Neobox__"));
sharedMemory->lock();
Expand Down
12 changes: 10 additions & 2 deletions pluginmgr/src/uninstall.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,19 @@ using namespace std::literals;


void EraseRegister() {
QSettings settings("HKEY_LOCAL_"
{
QSettings settings("HKEY_LOCAL_"
"MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Un"
"install\\Neobox",
QSettings::NativeFormat);
settings.remove("");
settings.remove("");
}
{
QSettings settings(R"(HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run)", QSettings::NativeFormat);
if (settings.contains("Neobox")) {
settings.remove("Neobox");
}
}
}

bool ExitAppInstance(fs::path appFile) {
Expand Down
Loading

0 comments on commit 82605ef

Please sign in to comment.