Esempio n. 1
0
BOOL TUninstDlg::UnInstall(void)
{
// 現在、起動中の ipmsg を終了
	int		st = TerminateIPMsg();

	if (st == 1) return FALSE;
	if (st == 2) {
		if (!IsWinVista() || TIsUserAnAdmin() || !TIsEnableUAC()) {
			MessageBox(GetLoadStr(IDS_CANTTERMINATE), UNINSTALL_STR);
			return FALSE;
		}
		if (MessageBox(GetLoadStr(IDS_REQUIREADMIN_TERM), "",
						MB_OKCANCEL|MB_ICONINFORMATION) != IDOK) return FALSE;
		return	RunAsAdmin(hWnd);
	}

	if (!runasWnd && MessageBox(GetLoadStr(IDS_START), UNINSTALL_STR,
						MB_OKCANCEL|MB_ICONINFORMATION) != IDOK) return	FALSE;

// 公開鍵削除
	if (IsDlgButtonChecked(DELPUBKEY_CHECK)) {
		BOOL	need_admin = FALSE;
		char	contName[MAX_PATH_U8], userName[MAX_PATH_U8];
		DWORD	size = sizeof(userName);
		::GetUserName(userName, &size);

		::wsprintf(contName, "ipmsg.rsa2048.%s", userName);
		if (!DeleteKeySet(MS_ENHANCED_PROV, contName, CRYPT_MACHINE_KEYSET) ||
			!DeleteKeySet(MS_ENHANCED_PROV, contName, 0)) need_admin = TRUE;

		::wsprintf(contName, "ipmsg.rsa1024.%s", userName);
		if (!DeleteKeySet(MS_ENHANCED_PROV, contName, CRYPT_MACHINE_KEYSET) ||
			!DeleteKeySet(MS_ENHANCED_PROV, contName, 0)) need_admin = TRUE;

		::wsprintf(contName, "ipmsg.rsa512.%s", userName);
		if (!DeleteKeySet(MS_DEF_PROV, contName, CRYPT_MACHINE_KEYSET) ||
			!DeleteKeySet(MS_DEF_PROV, contName, 0)) need_admin = TRUE;

		if (need_admin) {
			if (IsWinVista() && !TIsUserAnAdmin() && TIsEnableUAC()) {
				if (MessageBox(GetLoadStr(IDS_REQUIREADMIN_PUBKEY), "",
					MB_OKCANCEL|MB_ICONINFORMATION) != IDOK) return FALSE;
				return	RunAsAdmin(hWnd);
			}
		}
	}

// スタートアップ&デスクトップから削除
	TRegistry	reg(HKEY_CURRENT_USER);
	if (reg.OpenKey(REGSTR_SHELLFOLDERS)) {
		char	buf[MAX_PATH_U8];
		char	*regStr[]	= { REGSTR_STARTUP, REGSTR_PROGRAMS, REGSTR_DESKTOP, NULL };

		for (int i=0; regStr[i]; i++) {
			if (reg.GetStr(regStr[i], buf, sizeof(buf))) {
				if (i == 0) RemoveSameLink(buf);
				::wsprintf(buf + strlen(buf), "\\%s", IPMSG_SHORTCUT_NAME);
				DeleteLink(buf);
			}
		}
		reg.CloseKey();
	}

// レジストリからユーザー設定情報を削除
	if (reg.ChangeApp(HSTOOLS_STR))
		reg.DeleteChildTree(GetLoadStr(IDS_REGIPMSG));

// レジストリからアプリケーション情報を削除
	char	setupDir[MAX_PATH_U8];		// セットアップディレクトリ情報を保存
	GetDlgItemTextU8(RESETUP_EDIT, setupDir, sizeof(setupDir));

	reg.ChangeTopKey(HKEY_LOCAL_MACHINE);
	if (reg.OpenKey(REGSTR_PATH_APPPATHS)) {
		if (reg.OpenKey(IPMSG_EXENAME)) {
			reg.GetStr(REGSTR_PATH, setupDir, sizeof(setupDir));
			reg.CloseKey();
		}
		reg.DeleteKey(IPMSG_EXENAME);
		reg.CloseKey();
	}

// レジストリからアンインストール情報を削除
	if (reg.OpenKey(REGSTR_PATH_UNINSTALL)) {
		reg.DeleteKey(IPMSG_NAME);
		reg.CloseKey();
	}

// 終了メッセージ
	MessageBox(GetLoadStr(IDS_UNINSTCOMPLETE));

// インストールディレクトリを開く
	if (GetDriveTypeEx(setupDir) != DRIVE_REMOTE)
		ShellExecuteU8(NULL, NULL, setupDir, 0, 0, SW_SHOW);

	::PostQuitMessage(0);
	return	TRUE;
}
Esempio n. 2
0
BOOL TInstDlg::Install(void)
{
	char	buf[MAX_PATH], setupDir[MAX_PATH], setupPath[MAX_PATH];
	BOOL	is_delay_copy = FALSE;
	int		len;

// インストールパス設定
	len = GetDlgItemText(FILE_EDIT, setupDir, sizeof(setupDir));
	if (GetChar(setupDir, len-1) == '\\') SetChar(setupDir, len-1, 0);
	Wstr	w_setup(setupDir);

	if (IsWinVista() && TIsVirtualizedDirV(w_setup.Buf())) {
		if (!TIsUserAnAdmin()) {
			return	RunAsAdmin(TRUE);
		}
		else if (cfg.runImme && cfg.setupDir && lstrcmpiV(w_setup.Buf(), cfg.setupDir)) {
			return	MessageBox(GetLoadStr(IDS_ADMINCHANGE)), FALSE;
		}
	}

	CreateDirectory(setupDir, NULL);
	DWORD	attr = GetFileAttributes(setupDir);

	if (attr == 0xffffffff || (attr & FILE_ATTRIBUTE_DIRECTORY) == 0)
		return	MessageBox(GetLoadStr(IDS_NOTCREATEDIR)), FALSE;
	MakePath(setupPath, setupDir, FASTCOPY_EXE);

	if (MessageBox(GetLoadStr(IDS_START), INSTALL_STR, MB_OKCANCEL|MB_ICONINFORMATION) != IDOK)
		return	FALSE;

// ファイルコピー
	if (cfg.mode == SETUP_MODE) {
		char	installPath[MAX_PATH], orgDir[MAX_PATH];

		::GetModuleFileName(NULL, orgDir, sizeof(orgDir));
		GetParentDir(orgDir, orgDir);

		for (int cnt=0; SetupFiles[cnt] != NULL; cnt++) {
			MakePath(buf, orgDir, SetupFiles[cnt]);
			MakePath(installPath, setupDir, SetupFiles[cnt]);

			if (MiniCopy(buf, installPath) || IsSameFile(buf, installPath))
				continue;

			if ((strcmp(SetupFiles[cnt], CURRENT_SHEXTDLL_EX) == 0 ||
				 strcmp(SetupFiles[cnt], CURRENT_SHEXTDLL) == 0) && DelayCopy(buf, installPath)) {
				is_delay_copy = TRUE;
				continue;
			}
			return	MessageBox(installPath, GetLoadStr(IDS_NOTCREATEFILE)), FALSE;
		}
	}

// スタートメニュー&デスクトップに登録
	char	*linkPath[]	= { toA(cfg.startMenu, TRUE), toA(cfg.deskTop, TRUE), NULL };
	BOOL	execFlg[]	= { cfg.programLink,          cfg.desktopLink,        NULL };

	for (int cnt=0; linkPath[cnt]; cnt++) {
		strcpy(buf, linkPath[cnt]);
		if (cnt != 0 || RemoveSameLink(linkPath[cnt], buf) == FALSE) {
			::wsprintf(buf + strlen(buf), "\\%s", FASTCOPY_SHORTCUT);
		}
		if (execFlg[cnt]) {
			if (IS_WINNT_V) {
				Wstr	w_setup(setupPath, BY_MBCS);
				Wstr	w_buf(buf, BY_MBCS);
				SymLinkV(w_setup.Buf(), w_buf.Buf());
			}
			else {
				SymLinkV(setupPath, buf);
			}
		}
		else {
			if (IS_WINNT_V) {
				Wstr	w_buf(buf, BY_MBCS);
				DeleteLinkV(w_buf.Buf());
			}
			else {
				DeleteLinkV(buf);
			}
		}
	}

#if 0
// レジストリにアンインストール情報を登録
	if (reg.OpenKey(REGSTR_PATH_UNINSTALL)) {
		if (reg.CreateKey(FASTCOPY)) {
			MakePath(buf, setupDir, INSTALL_EXE);
			strcat(buf, " /r");
			reg.SetStr(REGSTR_VAL_UNINSTALLER_DISPLAYNAME, FASTCOPY);
			reg.SetStr(REGSTR_VAL_UNINSTALLER_COMMANDLINE, buf);
			reg.CloseKey();
		}
		reg.CloseKey();
	}
#endif

	if (IsWinVista() && TIsVirtualizedDirV(w_setup.Buf())) {
		WCHAR	wbuf[MAX_PATH] = L"", old_path[MAX_PATH] = L"", usr_path[MAX_PATH] = L"";
		WCHAR	fastcopy_dir[MAX_PATH], *fastcopy_dirname = NULL;

		GetFullPathNameW(w_setup.Buf(), MAX_PATH, fastcopy_dir, &fastcopy_dirname);

		if (cfg.appData) {
			strcpyV(usr_path, cfg.appData);
		}
		else {
			TSHGetSpecialFolderPathV(NULL, wbuf, CSIDL_APPDATA, FALSE);
			MakePathV(usr_path, wbuf, fastcopy_dirname);
		}

		ConvertVirtualStoreConf(w_setup.Buf(), usr_path, cfg.virtualDir);
	}

// コピーしたアプリケーションを起動
	const char *msg = GetLoadStr(is_delay_copy ? IDS_DELAYSETUPCOMPLETE : IDS_SETUPCOMPLETE);
	int			flg = MB_OKCANCEL|MB_ICONINFORMATION;

	if (IsWin7()) {
		msg = Fmt("%s%s", msg, GetLoadStr(IDS_COMPLETE_WIN7));
	}

	TLaunchDlg	dlg(msg, this);
	UINT		id;

	if ((id = dlg.Exec()) == IDOK || id == LAUNCH_BUTTON) {
		char	*arg = (id == LAUNCH_BUTTON) ? "/install" : "";
		ShellExecute(NULL, "open", setupPath, arg, setupDir, SW_SHOW);
	}

	::PostQuitMessage(0);
	return	TRUE;
}
Esempio n. 3
0
BOOL TInstDlg::UnInstall(void)
{
	char	buf[MAX_PATH];
	char	setupDir[MAX_PATH] = "";

	::GetModuleFileName(NULL, setupDir, sizeof(setupDir));
	GetParentDir(setupDir, setupDir);
	BOOL	is_shext = FALSE;

	is_shext = ShellExtFunc(setupDir, CHECK_SHELLEXT);

	if (is_shext && IsWinVista() && !TIsUserAnAdmin()) {
		RunAsAdmin(TRUE);
		return	TRUE;
	}

	if (MessageBox(GetLoadStr(IDS_START), UNINSTALL_STR, MB_OKCANCEL|MB_ICONINFORMATION) != IDOK)
		return	FALSE;

// スタートメニュー&デスクトップから削除
	TRegistry	reg(HKEY_CURRENT_USER, BY_MBCS);
	if (reg.OpenKey(REGSTR_SHELLFOLDERS)) {
		char	*regStr[]	= { REGSTR_PROGRAMS, REGSTR_DESKTOP, NULL };

		for (int cnt=0; regStr[cnt] != NULL; cnt++) {
			if (reg.GetStr(regStr[cnt], buf, sizeof(buf))) {
				if (cnt == 0)
					RemoveSameLink(buf);
				::wsprintf(buf + strlen(buf), "\\%s", FASTCOPY_SHORTCUT);
				if (IS_WINNT_V) {
					Wstr	w_buf(buf, BY_MBCS);
					DeleteLinkV(w_buf.Buf());
				}
				else {
					DeleteLinkV(buf);
				}
			}
		}
		reg.CloseKey();
	}

	ShellExtFunc(setupDir, UNREGISTER_SHELLEXT);

#ifdef _WIN64
	if (IS_WINNT_V) {
#else
	if (IS_WINNT_V && TIsWow64()) {
#endif
		SHELLEXECUTEINFO	sei = { sizeof(sei) };
		char	arg[1024];

		sprintf(arg, "\"%s\\%s\",%s", setupDir, CURRENT_SHEXTDLL_EX, "DllUnregisterServer");
		sei.lpFile = "rundll32.exe";
		sei.lpParameters = arg;
		ShellExecuteEx(&sei);
	}

// レジストリからアンインストール情報を削除
	if (reg.OpenKey(REGSTR_PATH_UNINSTALL)) {
		if (reg.OpenKey(FASTCOPY)) {
			if (reg.GetStr(REGSTR_VAL_UNINSTALLER_COMMANDLINE, setupDir, sizeof(setupDir)))
				GetParentDir(setupDir, setupDir);
			reg.CloseKey();
		}
		reg.DeleteKey(FASTCOPY);
		reg.CloseKey();
	}

// 終了メッセージ
	MessageBox(is_shext ? GetLoadStr(IDS_UNINSTSHEXTFIN) : GetLoadStr(IDS_UNINSTFIN));

// インストールディレクトリを開く
	if (GetFileAttributes(setupDir) != 0xffffffff) {
		::ShellExecute(NULL, NULL, setupDir, 0, 0, SW_SHOW);
	}

// AppDataディレクトリを開く
	if (IsWinVista()) {
		WCHAR	wbuf[MAX_PATH] = L"", upath[MAX_PATH] = L"";
		WCHAR	fastcopy_dir[MAX_PATH] = L"", *fastcopy_dirname = NULL;
		Wstr	w_setup(setupDir);

		if (TIsVirtualizedDirV(w_setup.Buf())) {
			if (TSHGetSpecialFolderPathV(NULL, wbuf, CSIDL_APPDATA, FALSE)) {
				GetFullPathNameW(w_setup.Buf(), MAX_PATH, fastcopy_dir, &fastcopy_dirname);
				MakePathV(upath, wbuf, fastcopy_dirname);

				if (GetFileAttributesV(upath) != 0xffffffff) {
					::ShellExecuteW(NULL, NULL, upath, 0, 0, SW_SHOW);
				}
			}
		}
	}

	::PostQuitMessage(0);
	return	TRUE;
}


BOOL ReadLink(char *src, char *dest, char *arg=NULL)
{
	IShellLink		*shellLink;		// 実際は IShellLinkA or IShellLinkW
	IPersistFile	*persistFile;
	WCHAR			wbuf[MAX_PATH];
	BOOL			ret = FALSE;

	if (SUCCEEDED(CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink,
			(void **)&shellLink))) {
		if (SUCCEEDED(shellLink->QueryInterface(IID_IPersistFile, (void **)&persistFile))) {
			AtoW(src, wbuf, MAX_PATH);
			if (SUCCEEDED(persistFile->Load(wbuf, STGM_READ))) {
				if (SUCCEEDED(shellLink->GetPath(dest, MAX_PATH, NULL, 0))) {
					if (arg) {
						shellLink->GetArguments(arg, MAX_PATH);
					}
					ret = TRUE;
				}
			}
			persistFile->Release();
		}
		shellLink->Release();
	}
	return	ret;
}
Esempio n. 4
0
BOOL TInstDlg::Install(void)
{
	char	buf[MAX_PATH_U8], setupDir[MAX_PATH_U8], setupPath[MAX_PATH_U8];
	char	installPath[MAX_PATH_U8];
	BOOL	extract_only = IsDlgButtonChecked(EXTRACT_CHECK);

// 現在、起動中の ipmsg を終了
	int		st = extract_only ? 0 : TerminateIPMsg();
	if (st == 1) return	FALSE;

// インストールパス設定
	GetDlgItemTextU8(FILE_EDIT, setupDir, sizeof(setupDir));

	if (IsWinVista() && !::IsUserAnAdmin() && TIsEnableUAC()
			&& TIsVirtualizedDirW(U8toWs(setupDir))) {
		if (MessageBox(GetLoadStr(IDS_REQUIREADMIN), INSTALL_STR,
				MB_OKCANCEL|MB_ICONINFORMATION) != IDOK) return	FALSE;
		return	RunAsAdmin(hWnd, TRUE);
	}

	CreateDirectoryU8(setupDir, NULL);
	DWORD	attr = GetFileAttributesU8(setupDir);
	if (attr == 0xffffffff || (attr & FILE_ATTRIBUTE_DIRECTORY) == 0)
		return	MessageBox(GetLoadStr(IDS_NOTCREATEDIR), INSTALL_STR), FALSE;
	MakePath(setupPath, setupDir, IPMSG_EXENAME);

	if (st == 2) {
		MessageBox(GetLoadStr(IDS_CANTTERMINATE), INSTALL_STR);
		return	FALSE;
	}
	if (!runasImm &&
		MessageBox(GetLoadStr(IDS_START), INSTALL_STR, MB_OKCANCEL|MB_ICONINFORMATION) != IDOK) {
		return	FALSE;
	}
	runasImm = FALSE;

// ファイル生成
	for (int i=0; SetupFiles[i]; i++) {
		MakePath(installPath, setupDir, SetupFiles[i]);
		CreateStatus cs = CreateFileBySelf(installPath, SetupFiles[i]);
		if (cs == CS_BROKEN) {
			MessageBox(GetLoadStr(IDS_BROKENARCHIVE), INSTALL_STR);
			return	FALSE;
		}
		else if (cs == CS_ACCESS) {
			const char *msg = Fmt("%s\r\n%s", GetLoadStrU8(IDS_NOTCREATEFILE), installPath);
			MessageBoxU8(msg, INSTALL_STR);
			return	FALSE;
		}
	}

// 展開のみ
	if (extract_only) {
		ShellExecuteW(NULL, NULL, U8toWs(setupDir), 0, 0, SW_SHOW);
		return TRUE;
	}

// スタートアップ&デスクトップに登録
	TRegistry	reg(HKEY_CURRENT_USER);
	if (reg.OpenKey(REGSTR_SHELLFOLDERS)) {
		char	*regStr[] = { REGSTR_STARTUP, REGSTR_PROGRAMS, REGSTR_DESKTOP, NULL };
		BOOL	resId[]   = { STARTUP_CHECK,  PROGRAM_CHECK,   DESKTOP_CHECK,  NULL };

		for (int i=0; regStr[i]; i++) {
			if (reg.GetStr(regStr[i], buf, sizeof(buf))) {
				if (i != 0 || !RemoveSameLink(buf, buf))
					::wsprintf(buf + strlen(buf), "\\%s", IPMSG_SHORTCUT_NAME);
				if (IsDlgButtonChecked(resId[i]))
					SymLink(setupPath, buf);
				else
					DeleteLink(buf);
			}
		}
		reg.CloseKey();
	}

// レジストリにアプリケーション情報を登録
	reg.ChangeTopKey(HKEY_LOCAL_MACHINE);
	if (reg.OpenKey(REGSTR_PATH_APPPATHS)) {
		if (reg.CreateKey(IPMSG_EXENAME)) {
			reg.SetStr(NULL, setupPath);
			reg.SetStr(REGSTR_PATH, setupDir);
			reg.CloseKey();
		}
		reg.CloseKey();
	}

// レジストリにアンインストール情報を登録
	if (reg.OpenKey(REGSTR_PATH_UNINSTALL)) {
		if (reg.CreateKey(IPMSG_NAME)) {
			MakePath(buf, setupDir, SETUP_EXENAME);
			strcat(buf, " /r");
			reg.SetStr(REGSTR_VAL_UNINSTALLER_DISPLAYNAME, IPMSG_FULLNAME);
			reg.SetStr(REGSTR_VAL_UNINSTALLER_COMMANDLINE, buf);
			reg.CloseKey();
		}
		reg.CloseKey();
	}

// コピーしたアプリケーションを起動
	const char *msg = GetLoadStr(IDS_SETUPCOMPLETE);
	int			flg = MB_OKCANCEL|MB_ICONINFORMATION;

//	if (IsWinVista() && ::IsUserAnAdmin() && TIsEnableUAC()) {
//		msg = Fmt("%s%s", msg, GetLoadStr(IDS_COMPLETE_UACADD));
//		flg |= MB_DEFBUTTON2;
//	}
	TLaunchDlg	dlg(msg, this);
	if (dlg.Exec() == IDOK) {
		if (runasWnd) {
			Wstr	wbuf(setupDir);
			if (::SendDlgItemMessageW(runasWnd, FILE_EDIT, WM_SETTEXT, 0, (LPARAM)wbuf.Buf())) {
				::PostMessage(runasWnd, WM_IPMSG_QUIT, 1, 0);
				runasWnd = NULL;
			}
		}
		else {
			AppKick();
		}
	}
	else {
		HWND	hHelp = ShowHelpU8(0, setupDir, GetLoadStrU8(IDS_IPMSGHELP), "#history");
		if (hHelp) {
			Show(SW_HIDE);
			while (::IsWindow(hHelp)) {
				this->Sleep(100);
			}
		}
	}

	if (runasWnd) {
		::PostMessage(runasWnd, WM_IPMSG_QUIT, 0, 0);
		runasWnd = NULL;
	}

//	ShellExecuteU8(NULL, NULL, setupDir, 0, 0, SW_SHOW);
	::PostQuitMessage(0);
	return	TRUE;
}