Пример #1
0
BOOL TMakeVirtualStorePathV(void *org_path, void *buf)
{
	if (!IsWinVista()) return FALSE;

	if (!TIsVirtualizedDirV(org_path)
	|| !TSHGetSpecialFolderPathV(NULL, buf, CSIDL_LOCAL_APPDATA, FALSE)
	||	GetChar(org_path, 1) != ':' || GetChar(org_path, 2) != '\\') {
		strcpyV(buf, org_path);
		return	FALSE;
	}

	sprintfV(MakeAddr(buf, strlenV(buf)), L"\\VirtualStore%s", MakeAddr(org_path, 2));
	return	TRUE;
}
Пример #2
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;
}
Пример #3
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;
}