Skip to content

Commit

Permalink
Merge pull request #12 from Pituchey-Hotam/dev
Browse files Browse the repository at this point in the history
Fix send request with another thread
  • Loading branch information
YehudaEi authored Oct 5, 2023
2 parents afcfc79 + 1b15b83 commit 21bc38f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 18 deletions.
3 changes: 2 additions & 1 deletion TBBD/TBBD_status.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,6 @@ typedef enum tbbd_status_e {
TBBD_STATUS_COPYFILEW_FAILED,
TBBD_STATUS_ADAL_AND_LIVEID_REGEX_NOT_FOUND,
TBBD_STATUS_STRINGCCHCOPYEXW_FAILED,
TBBD_STATUS_CREATEFONTW_FAILED
TBBD_STATUS_CREATEFONTW_FAILED,
TBBD_STATUS_CREATETHREAD_FAILED
} tbbd_status_t;
10 changes: 5 additions & 5 deletions TBBD/const.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
#define LAST_UPDATE_HEBREW_DATE_PATH L"/Pituchey-Hotam/The-Big-Beiinish-Dictionary/data/last-update-hebrew-date.txt"
#define THE_DICTIONARY_URL L"https://raw.githubusercontent.com/Pituchey-Hotam/The-Big-Beiinish-Dictionary/data/TBBD.dic"

#define STATISTICS_SERVER_DOMAIN L"yehudae.net"
#define STATISTICS_SERVER_PATH_INSTALL L"/PitucheyHotam/tbbd.php?install"
#define STATISTICS_SERVER_PATH_UNINSTALL L"/PitucheyHotam/tbbd.php?uninstall"
#define STATISTICS_SERVER_PATH_MANUAL_UPDATE L"/PitucheyHotam/tbbd.php?manual-update"
#define STATISTICS_SERVER_PATH_AUTO_UPDATE L"/PitucheyHotam/tbbd.php?auto-update"
constexpr LPCWCHAR STATISTICS_SERVER_DOMAIN = L"yehudae.net";
constexpr LPCWCHAR STATISTICS_SERVER_PATH_INSTALL = L"/PitucheyHotam/tbbd.php?install";
constexpr LPCWCHAR STATISTICS_SERVER_PATH_UNINSTALL = L"/PitucheyHotam/tbbd.php?uninstall";
constexpr LPCWCHAR STATISTICS_SERVER_PATH_MANUAL_UPDATE = L"/PitucheyHotam/tbbd.php?manual-update";
constexpr LPCWCHAR STATISTICS_SERVER_PATH_AUTO_UPDATE = L"/PitucheyHotam/tbbd.php?auto-update";

#define MASTER_REGISTRY_PATH L"SOFTWARE\\Microsoft\\Shared Tools\\Proofing Tools\\1.0\\Custom Dictionaries"
#define CONFIG_DIR_PATH L"\\PitucheyHotam"
Expand Down
43 changes: 31 additions & 12 deletions TBBD/tbbd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ LRESULT CALLBACK GlobalCallbackHandler(HWND hwnd, UINT msg, WPARAM wParam, LPARA
return tbbd.CallbackHandler(hwnd, msg, wParam, lParam);
}

DWORD WINAPI GlobalNonBlokingSendStatistics(LPVOID lpParam) {
return (DWORD)http_get(STATISTICS_SERVER_DOMAIN, (LPCWCHAR)lpParam, NULL, 0);
}

TBBD::TBBD() :
ChangeStatusBotton(NULL), RefrashBotton(NULL), versionLabel(NULL), lastUpdateDateLabel(NULL), statusLabel(NULL),
ServerVersion(L""), CurrentVersion(L""), ServerLastUpdateDate(L""), CurrentLastUpdateDate(L""),
Expand Down Expand Up @@ -448,6 +452,8 @@ tbbd_status_t TBBD::GetServerLastUpdateHebDate(LPWSTR LastUpdateHebDate, DWORD s
tbbd_status_t TBBD::Install() {
tbbd_status_t status = TBBD_STATUS_UNINITIALIZED;
BOOL adalRegexNotFound = FALSE;
HANDLE hThread = NULL;
DWORD threadId = 0;

if (!SUCCEEDED(URLDownloadToFileW(nullptr, THE_DICTIONARY_URL, this->TBBDFilePath, 0, nullptr))) {
status = TBBD_STATUS_URLDOWNLOADTOFILEW_FAILED;
Expand Down Expand Up @@ -501,11 +507,15 @@ tbbd_status_t TBBD::Install() {
goto l_cleanup;
}

status = http_get(STATISTICS_SERVER_DOMAIN, STATISTICS_SERVER_PATH_INSTALL, NULL, 0);
if (TBBD_STATUS_SUCCESS != status) {
hThread = CreateThread(NULL, 0, GlobalNonBlokingSendStatistics, (LPVOID)STATISTICS_SERVER_PATH_INSTALL, 0, &threadId);

if (NULL == hThread) {
status = TBBD_STATUS_CREATETHREAD_FAILED;
goto l_cleanup;
}

CloseHandle(hThread);

status = TBBD_STATUS_SUCCESS;
l_cleanup:
return status;
Expand Down Expand Up @@ -749,6 +759,8 @@ tbbd_status_t TBBD::InstallExeToAppdata() {

tbbd_status_t TBBD::UnInstall() {
tbbd_status_t status = TBBD_STATUS_UNINITIALIZED;
HANDLE hThread = NULL;
DWORD threadId = 0;

status = TryToDeleteRegistrys(L"PitucheyHotem_TBBD_ADAL_Prefix");
if (TBBD_STATUS_SUCCESS != status) {
Expand Down Expand Up @@ -799,11 +811,15 @@ tbbd_status_t TBBD::UnInstall() {
goto l_cleanup;
}

status = http_get(STATISTICS_SERVER_DOMAIN, STATISTICS_SERVER_PATH_UNINSTALL, NULL, 0);
if (TBBD_STATUS_SUCCESS != status) {
hThread = CreateThread(NULL, 0, GlobalNonBlokingSendStatistics, (LPVOID)STATISTICS_SERVER_PATH_UNINSTALL, 0, &threadId);

if (NULL == hThread) {
status = TBBD_STATUS_CREATETHREAD_FAILED;
goto l_cleanup;
}

CloseHandle(hThread);

status = TBBD_STATUS_SUCCESS;
l_cleanup:
return status;
Expand Down Expand Up @@ -920,6 +936,8 @@ tbbd_status_t TBBD::UnInstallExeFromAppdata() {

tbbd_status_t TBBD::Update() {
tbbd_status_t status = TBBD_STATUS_UNINITIALIZED;
HANDLE hThread = NULL;
DWORD threadId = 0;

if (!DeleteFileW(this->TBBDFilePath)) {
if (ERROR_FILE_NOT_FOUND != GetLastError()) {
Expand All @@ -934,18 +952,19 @@ tbbd_status_t TBBD::Update() {
}

if (NULL == this->RefrashBotton) {
status = http_get(STATISTICS_SERVER_DOMAIN, STATISTICS_SERVER_PATH_AUTO_UPDATE, NULL, 0);
if (TBBD_STATUS_SUCCESS != status) {
goto l_cleanup;
}
hThread = CreateThread(NULL, 0, GlobalNonBlokingSendStatistics, (LPVOID)STATISTICS_SERVER_PATH_AUTO_UPDATE, 0, &threadId);
}
else {
status = http_get(STATISTICS_SERVER_DOMAIN, STATISTICS_SERVER_PATH_MANUAL_UPDATE, NULL, 0);
if (TBBD_STATUS_SUCCESS != status) {
goto l_cleanup;
}
hThread = CreateThread(NULL, 0, GlobalNonBlokingSendStatistics, (LPVOID)STATISTICS_SERVER_PATH_MANUAL_UPDATE, 0, &threadId);
}

if (NULL == hThread) {
status = TBBD_STATUS_CREATETHREAD_FAILED;
goto l_cleanup;
}

CloseHandle(hThread);

if (!SUCCEEDED(StringCchCopyExW(this->CurrentVersion, (VERSION_STRING_LENGTH / sizeof(this->CurrentVersion[0])), this->ServerVersion, NULL, NULL, 0))) {
status = TBBD_STATUS_STRINGCCHCOPYEXW_FAILED;
goto l_cleanup;
Expand Down

0 comments on commit 21bc38f

Please sign in to comment.