Skip to content

Commit

Permalink
处理 WeaselSetup 报毒问题 (rime#936)
Browse files Browse the repository at this point in the history
* fix WeaselSetup false positive in anti-virus programs
  • Loading branch information
determ1ne authored Jun 15, 2023
1 parent 31ab780 commit e4ea2ea
Show file tree
Hide file tree
Showing 39 changed files with 50,870 additions and 364 deletions.
Original file line number Diff line number Diff line change
@@ -1,76 +1,77 @@
#include "stdafx.h"
#include "InstallOptionsDialog.h"

int uninstall(bool silent);

InstallOptionsDialog::InstallOptionsDialog()
: installed(false), hant(false), user_dir()
{
}

InstallOptionsDialog::~InstallOptionsDialog()
{
}

LRESULT InstallOptionsDialog::OnInitDialog(UINT, WPARAM, LPARAM, BOOL&) {
cn_.Attach(GetDlgItem(IDC_RADIO_CN));
tw_.Attach(GetDlgItem(IDC_RADIO_TW));
remove_.Attach(GetDlgItem(IDC_REMOVE));
default_dir_.Attach(GetDlgItem(IDC_RADIO_DEFAULT_DIR));
custom_dir_.Attach(GetDlgItem(IDC_RADIO_CUSTOM_DIR));
dir_.Attach(GetDlgItem(IDC_EDIT_DIR));

CheckRadioButton(IDC_RADIO_CN, IDC_RADIO_TW,
(hant? IDC_RADIO_TW : IDC_RADIO_CN));
CheckRadioButton(IDC_RADIO_DEFAULT_DIR, IDC_RADIO_CUSTOM_DIR,
(user_dir.empty() ? IDC_RADIO_DEFAULT_DIR : IDC_RADIO_CUSTOM_DIR));
dir_.SetWindowTextW(user_dir.c_str());

cn_.EnableWindow(!installed);
tw_.EnableWindow(!installed);
remove_.EnableWindow(installed);
dir_.EnableWindow(user_dir.empty() ? FALSE : TRUE);

CenterWindow();
return 0;
}

LRESULT InstallOptionsDialog::OnClose(UINT, WPARAM, LPARAM, BOOL&) {
EndDialog(IDCANCEL);
return 0;
}

LRESULT InstallOptionsDialog::OnOK(WORD, WORD code, HWND, BOOL&) {
hant = (IsDlgButtonChecked(IDC_RADIO_TW) == BST_CHECKED);
if (IsDlgButtonChecked(IDC_RADIO_CUSTOM_DIR) == BST_CHECKED) {
CStringW text;
dir_.GetWindowTextW(text);
user_dir = text;
}
else {
user_dir.clear();
}
EndDialog(IDOK);
return 0;
}

LRESULT InstallOptionsDialog::OnRemove(WORD, WORD code, HWND, BOOL&) {
const bool non_silent = false;
uninstall(non_silent);
installed = false;
cn_.EnableWindow(!installed);
tw_.EnableWindow(!installed);
remove_.EnableWindow(installed);
return 0;
}

LRESULT InstallOptionsDialog::OnUseDefaultDir(WORD, WORD code, HWND, BOOL&) {
dir_.EnableWindow(FALSE);
return 0;
}

LRESULT InstallOptionsDialog::OnUseCustomDir(WORD, WORD code, HWND, BOOL&) {
dir_.EnableWindow(TRUE);
dir_.SetFocus();
return 0;
}
#include "stdafx.h"
#include "InstallOptionsDlg.h"
#include <atlstr.h>

int uninstall(bool silent);

InstallOptionsDialog::InstallOptionsDialog()
: installed(false), hant(false), user_dir()
{
}

InstallOptionsDialog::~InstallOptionsDialog()
{
}

LRESULT InstallOptionsDialog::OnInitDialog(UINT, WPARAM, LPARAM, BOOL&) {
cn_.Attach(GetDlgItem(IDC_RADIO_CN));
tw_.Attach(GetDlgItem(IDC_RADIO_TW));
remove_.Attach(GetDlgItem(IDC_REMOVE));
default_dir_.Attach(GetDlgItem(IDC_RADIO_DEFAULT_DIR));
custom_dir_.Attach(GetDlgItem(IDC_RADIO_CUSTOM_DIR));
dir_.Attach(GetDlgItem(IDC_EDIT_DIR));

CheckRadioButton(IDC_RADIO_CN, IDC_RADIO_TW,
(hant ? IDC_RADIO_TW : IDC_RADIO_CN));
CheckRadioButton(IDC_RADIO_DEFAULT_DIR, IDC_RADIO_CUSTOM_DIR,
(user_dir.empty() ? IDC_RADIO_DEFAULT_DIR : IDC_RADIO_CUSTOM_DIR));
dir_.SetWindowTextW(user_dir.c_str());

cn_.EnableWindow(!installed);
tw_.EnableWindow(!installed);
remove_.EnableWindow(installed);
dir_.EnableWindow(user_dir.empty() ? FALSE : TRUE);

CenterWindow();
return 0;
}

LRESULT InstallOptionsDialog::OnClose(UINT, WPARAM, LPARAM, BOOL&) {
EndDialog(IDCANCEL);
return 0;
}

LRESULT InstallOptionsDialog::OnOK(WORD, WORD code, HWND, BOOL&) {
hant = (IsDlgButtonChecked(IDC_RADIO_TW) == BST_CHECKED);
if (IsDlgButtonChecked(IDC_RADIO_CUSTOM_DIR) == BST_CHECKED) {
CStringW text;
dir_.GetWindowTextW(text);
user_dir = text;
}
else {
user_dir.clear();
}
EndDialog(IDOK);
return 0;
}

LRESULT InstallOptionsDialog::OnRemove(WORD, WORD code, HWND, BOOL&) {
const bool non_silent = false;
uninstall(non_silent);
installed = false;
cn_.EnableWindow(!installed);
tw_.EnableWindow(!installed);
remove_.EnableWindow(installed);
return 0;
}

LRESULT InstallOptionsDialog::OnUseDefaultDir(WORD, WORD code, HWND, BOOL&) {
dir_.EnableWindow(FALSE);
return 0;
}

LRESULT InstallOptionsDialog::OnUseCustomDir(WORD, WORD code, HWND, BOOL&) {
dir_.EnableWindow(TRUE);
dir_.SetFocus();
return 0;
}
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
#pragma once

#include "resource.h"

class InstallOptionsDialog : public CDialogImpl<InstallOptionsDialog>
{
public:
enum { IDD = IDD_INSTALL_OPTIONS };

InstallOptionsDialog();
~InstallOptionsDialog();

bool installed;
bool hant;
std::wstring user_dir;

protected:
BEGIN_MSG_MAP(InstallOptionsDialog)
MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
MESSAGE_HANDLER(WM_CLOSE, OnClose)
COMMAND_ID_HANDLER(IDOK, OnOK)
COMMAND_ID_HANDLER(IDC_REMOVE, OnRemove)
COMMAND_ID_HANDLER(IDC_RADIO_DEFAULT_DIR, OnUseDefaultDir)
COMMAND_ID_HANDLER(IDC_RADIO_CUSTOM_DIR, OnUseCustomDir)
END_MSG_MAP()

LRESULT OnInitDialog(UINT, WPARAM, LPARAM, BOOL&);
LRESULT OnClose(UINT, WPARAM, LPARAM, BOOL&);
LRESULT OnOK(WORD, WORD code, HWND, BOOL&);
LRESULT OnRemove(WORD, WORD code, HWND, BOOL&);
LRESULT OnUseDefaultDir(WORD, WORD code, HWND, BOOL&);
LRESULT OnUseCustomDir(WORD, WORD code, HWND, BOOL&);

void UpdateWidgets();

CButton cn_;
CButton tw_;
CButton remove_;
CButton default_dir_;
CButton custom_dir_;
CEdit dir_;
};
#pragma once

#include "resource.h"

class InstallOptionsDialog : public CDialogImpl<InstallOptionsDialog>
{
public:
enum { IDD = IDD_INSTALL_OPTIONS };

InstallOptionsDialog();
~InstallOptionsDialog();

bool installed;
bool hant;
std::wstring user_dir;

protected:
BEGIN_MSG_MAP(InstallOptionsDialog)
MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
MESSAGE_HANDLER(WM_CLOSE, OnClose)
COMMAND_ID_HANDLER(IDOK, OnOK)
COMMAND_ID_HANDLER(IDC_REMOVE, OnRemove)
COMMAND_ID_HANDLER(IDC_RADIO_DEFAULT_DIR, OnUseDefaultDir)
COMMAND_ID_HANDLER(IDC_RADIO_CUSTOM_DIR, OnUseCustomDir)
END_MSG_MAP()

LRESULT OnInitDialog(UINT, WPARAM, LPARAM, BOOL&);
LRESULT OnClose(UINT, WPARAM, LPARAM, BOOL&);
LRESULT OnOK(WORD, WORD code, HWND, BOOL&);
LRESULT OnRemove(WORD, WORD code, HWND, BOOL&);
LRESULT OnUseDefaultDir(WORD, WORD code, HWND, BOOL&);
LRESULT OnUseCustomDir(WORD, WORD code, HWND, BOOL&);

void UpdateWidgets();

CButton cn_;
CButton tw_;
CButton remove_;
CButton default_dir_;
CButton custom_dir_;
CEdit dir_;
};
62 changes: 0 additions & 62 deletions WeaselSetup/ReadMe.txt

This file was deleted.

33 changes: 12 additions & 21 deletions WeaselSetup/WeaselSetup.cpp
Original file line number Diff line number Diff line change
@@ -1,43 +1,33 @@
// WeaselSetup.cpp : Defines the entry point for the application.
// WeaselSetup.cpp : main source file for WeaselSetup.exe
//

#include "stdafx.h"
#include "WeaselSetup.h"
#include "InstallOptionsDialog.h"

#include "resource.h"

#include "InstallOptionsDlg.h"

CAppModule _Module;

static int Run(LPTSTR lpCmdLine);

int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpstrCmdLine, int /*nCmdShow*/)
{
UNREFERENCED_PARAMETER(hPrevInstance);

HRESULT hRes = ::CoInitialize(NULL);
// If you are running on NT 4.0 or higher you can use the following call instead to
// make the EXE free threaded. This means that calls come in on a random RPC thread.
//HRESULT hRes = ::CoInitializeEx(NULL, COINIT_MULTITHREADED);
ATLASSERT(SUCCEEDED(hRes));

// this resolves ATL window thunking problem when Microsoft Layer for Unicode (MSLU) is used
::DefWindowProc(NULL, 0, 0, 0L);

AtlInitCommonControls(ICC_BAR_CLASSES); // add flags to support other controls

hRes = _Module.Init(NULL, hInstance);
ATLASSERT(SUCCEEDED(hRes));

int ret = Run(lpCmdLine);
int nRet = Run(lpstrCmdLine);

_Module.Term();
::CoUninitialize();

return ret;
return nRet;
}

int install(bool hant, bool silent);
int uninstall(bool silent);
bool has_installed();
Expand Down Expand Up @@ -92,16 +82,16 @@ static int CustomInstall(bool installing)
return 1;

ret = RegCreateKeyEx(HKEY_CURRENT_USER, KEY,
0, NULL, 0, KEY_ALL_ACCESS, 0, &hKey, NULL);
0, NULL, 0, KEY_ALL_ACCESS, 0, &hKey, NULL);
if (FAILED(HRESULT_FROM_WIN32(ret)))
{
MessageBox(NULL, KEY, L"安裝失敗", MB_ICONERROR | MB_OK);
return 1;
}

ret = RegSetValueEx(hKey, L"RimeUserDir", 0, REG_SZ,
(const BYTE*)user_dir.c_str(),
(user_dir.length() + 1) * sizeof(WCHAR));
(const BYTE*)user_dir.c_str(),
(user_dir.length() + 1) * sizeof(WCHAR));
if (FAILED(HRESULT_FROM_WIN32(ret)))
{
MessageBox(NULL, L"無法寫入 RimeUserDir", L"安裝失敗", MB_ICONERROR | MB_OK);
Expand Down Expand Up @@ -134,3 +124,4 @@ static int Run(LPTSTR lpCmdLine)
bool installing = !wcscmp(L"/i", lpCmdLine);
return CustomInstall(installing);
}

4 changes: 1 addition & 3 deletions WeaselSetup/WeaselSetup.h
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
#pragma once

#include "resource.h"
// WeaselSetup.h
Binary file modified WeaselSetup/WeaselSetup.ico
Binary file not shown.
Binary file modified WeaselSetup/WeaselSetup.rc
Binary file not shown.
Loading

0 comments on commit e4ea2ea

Please sign in to comment.