Exemple #1
0
BOOL fileWalkOverPath(PSTR szPathIn,PSTR szPattern,BOOL bSubPath,PFN_WalkName WalkName,PVOID usrData)
{
  char            szWalkPath[_MAX_PATH];
  char            szWalkName[_MAX_PATH];
  BOOL            bCont;
  HANDLE          hFind;
  WIN32_FIND_DATA nData;
  
  bCont = TRUE;
  strcpy(szWalkPath,szPathIn);
  PathAddBackslash(szWalkPath);
  if (bSubPath){
    sprintf(szWalkName,"%s*.*",szWalkPath);
    if (INVALID_HANDLE_VALUE != (hFind=FindFirstFile(szWalkName,&nData))){
      do{
	    if (!FLAGON(nData.dwFileAttributes,FILE_ATTRIBUTE_DIRECTORY)) continue;
	    if (0 == strcmp(nData.cFileName,".") || 0 == strcmp(nData.cFileName,"..")) continue;
	    strcpyV(szWalkName,sizeof(szWalkName),"%s%s\\",szWalkPath,nData.cFileName);
	    bCont = WalkName(usrData,szWalkPath,&nData) && fileWalkOverPath(szWalkName,szPattern,TRUE,WalkName,usrData);
      }while(bCont && FindNextFile(hFind,&nData));
      FindClose(hFind);
    }
  }
  strcpyV(szWalkName,sizeof(szWalkName),"%s%s",szWalkPath,szPattern);
  if (INVALID_HANDLE_VALUE != (hFind=FindFirstFile(szWalkName,&nData))){
	do{
	  if (0 == strcmp(nData.cFileName,".") || 0 == strcmp(nData.cFileName,"..")) continue;
      bCont = WalkName(usrData,szWalkPath,&nData);
	}while(bCont && FindNextFile(hFind,&nData));
	FindClose(hFind);
  }
  return bCont;
}
Exemple #2
0
/*
	親ディレクトリ取得(必ずフルパスであること。UNC対応)
*/
BOOL GetParentDirV(const void *srcfile, void *dir)
{
	WCHAR	path[MAX_PATH], *fname=NULL;

	if (GetFullPathNameV(srcfile, MAX_PATH, path, (void **)&fname) == 0 || fname == NULL)
		return	strcpyV(dir, srcfile), FALSE;

	if (((char *)fname - (char *)path) > 3 * CHAR_LEN_V || GetChar(path, 1) != ':')
		SetChar(fname, -1, 0);
	else
		SetChar(fname, 0, 0);		// C:\ の場合

	strcpyV(dir, path);
	return	TRUE;
}
Exemple #3
0
BOOL fileAutoRename(PSTR szName,DWORD dwName)
{
  char   szPath[_MAX_PATH];
  char   szTemp[_MAX_PATH];
  char   szExt[_MAX_PATH];
  PSTR   pName,pExt,pOrd;
  DWORD  dwOrd;
  HANDLE hFile;
  
  //not exist ?
  if (INVALID_HANDLE_VALUE != (hFile=CreateFile(szName,GENERIC_WRITE,0,NULL,CREATE_NEW,FILE_ATTRIBUTE_NORMAL,NULL))){
    CloseHandle(hFile);
	return TRUE;
  }
  strcpyN(szPath,sizeof(szPath),szName);
  pName = PathFindFileName(szPath);
  pExt  = PathFindExtension(pName);
  strcpyN(szExt,sizeof(szExt),pExt);
  pOrd = pExt - 1;
  for(;;pOrd++){
    if (*pOrd < '0' || *pOrd > '9') break;
  }
  pOrd++;
  dwOrd = atoi(pOrd);
  pOrd[0] = 0;
  for(;dwOrd<INT_MAX-1;dwOrd++){
    strcpyV(szTemp,sizeof(szTemp),"%s%d%s",szPath,dwOrd,szExt);
	if (INVALID_HANDLE_VALUE != (hFile=CreateFile(szTemp,GENERIC_WRITE,0,NULL,CREATE_NEW,FILE_ATTRIBUTE_NORMAL,NULL))){
      CloseHandle(hFile);
	  strcpyN(szName,dwName,szTemp);
      return TRUE;
    }
  }
  return FALSE;
}
Exemple #4
0
HWND ShowHelpV(HWND hOwner, void *help_dir, void *help_file, void *section)
{
#if defined(ENABLE_HTML_HELP)
	static HWND (WINAPI *pHtmlHelpV)(HWND, void *, UINT, DWORD_PTR) = NULL;

	if (pHtmlHelpV == NULL) {
		DWORD		cookie=0;
		HMODULE		hHtmlHelp = TLoadLibrary("hhctrl.ocx");
		if (hHtmlHelp)
			pHtmlHelpV = (HWND (WINAPI *)(HWND, void *, UINT, DWORD_PTR))
						::GetProcAddress(hHtmlHelp, IS_WINNT_V ? "HtmlHelpW" : "HtmlHelpA");
		if (pHtmlHelpV)
			pHtmlHelpV(NULL, NULL, HH_INITIALIZE, (DWORD)&cookie);
	}
	if (pHtmlHelpV) {
		WCHAR	path[MAX_PATH];

		MakePathV(path, help_dir, help_file);
		if (section)
			strcpyV(MakeAddr(path, strlenV(path)), section);
		return	pHtmlHelpV(hOwner, path, HH_DISPLAY_TOC, 0);
	}
#endif
	return	NULL;
}
Exemple #5
0
BOOL fileDeleteDirectory(PSTR szPath)
{
  char            szName[_MAX_PATH];
  HANDLE          hFind;
  WIN32_FIND_DATA nData;

  fileAdjustPathSplit(szPath);
  PathAddBackslash(szPath);
  strcpyV(szName,sizeof(szName),"%s*.*",szPath);
  if (INVALID_HANDLE_VALUE == (hFind=FindFirstFile(szName,&nData))){
#ifdef _DEBUG
    logError1("!FindFirstFile(%s)",szName);
#endif //_DEBUG
    return FALSE;
  }
  for(;;){
    if (0 == strcmp(nData.cFileName,".")) goto NEXT_SEARCH;
	if (0 == strcmp(nData.cFileName,"..")) goto NEXT_SEARCH;
	strcpyV(szName,sizeof(szName),"%s%s",szPath,nData.cFileName);
	if (FLAGON(nData.dwFileAttributes,FILE_ATTRIBUTE_DIRECTORY)){
	  if (!fileDeleteDirectory(szName)) return FALSE;
	  if (!RemoveDirectory(szName)){
#ifdef _DEBUG
        logError1("!RemoveDirectory(%s)",szPath);
#endif //_DEBUG
        return FALSE;
      }
	}
	else{
	  if (!DeleteFile(szName)){
#ifdef _DEBUG
	    logError1("!DeleteFile(%s)",szName);
#endif //_DEBUG
	    return FALSE;
	  }
	}
NEXT_SEARCH:
    if (!FindNextFile(hFind,&nData)) break;
  }
  FindClose(hFind);
  return TRUE;
}
Exemple #6
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;
}
Exemple #7
0
BOOL TInstDlg::RunAsAdmin(BOOL is_imme)
{
	SHELLEXECUTEINFOW	sei = {0};
	WCHAR				buf[MAX_PATH * 2];
	WCHAR				exe_path[MAX_PATH];
	WCHAR				setup_path[MAX_PATH];
	WCHAR				app_data[MAX_PATH];
	WCHAR				virtual_store[MAX_PATH];
	WCHAR				fastcopy_dir[MAX_PATH];
	WCHAR				*fastcopy_dirname = NULL;
	int					len;

	::GetModuleFileNameW(NULL, exe_path, sizeof(exe_path));

	if (!(len = GetDlgItemTextV(FILE_EDIT, setup_path, MAX_PATH))) return FALSE;
	if (GetChar(setup_path, len-1) == '\\') SetChar(setup_path, len-1, 0);
	if (!GetFullPathNameW(setup_path, MAX_PATH, fastcopy_dir, &fastcopy_dirname)) return FALSE;

	if (!TSHGetSpecialFolderPathV(NULL, buf, CSIDL_APPDATA, FALSE)) return FALSE;
	MakePathV(app_data, buf, fastcopy_dirname);

	strcpyV(buf, fastcopy_dir);
#ifdef _WIN64
	ConvertToX86Dir(buf);
#endif
	if (!TMakeVirtualStorePathV(buf, virtual_store)) return FALSE;

	sprintfV(buf, L"/runas=%p,%d,%d,%d,%d,\"%s\",\"%s\",\"%s\",\"%s\",\"%s\"",
		hWnd, cfg.mode, is_imme, cfg.programLink, cfg.desktopLink,
		cfg.startMenu, cfg.deskTop,
		setup_path, app_data, virtual_store);

	sei.cbSize = sizeof(SHELLEXECUTEINFO);
	sei.lpVerb = L"runas";
	sei.lpFile = exe_path;
	sei.lpDirectory = NULL;
	sei.nShow = SW_NORMAL;
	sei.lpParameters = buf;

	EnableWindow(FALSE);
	BOOL ret = ::ShellExecuteExW(&sei);
	EnableWindow(TRUE);

	return	ret;
}
Exemple #8
0
BOOL ConvertToX86Dir(void *target)
{
	WCHAR	buf[MAX_PATH];
	WCHAR	buf86[MAX_PATH];
	int		len;

	if (!TSHGetSpecialFolderPathV(NULL, buf, CSIDL_PROGRAM_FILES, FALSE)) return FALSE;
	len = strlenV(buf);
	SetChar(buf, len++, '\\');
	SetChar(buf, len, 0);

	if (strnicmpV(buf, target, len)) return FALSE;

	if (!TSHGetSpecialFolderPathV(NULL, buf86, CSIDL_PROGRAM_FILESX86, FALSE)) return FALSE;
	MakePathV(buf, buf86, MakeAddr(target, len));
	strcpyV(target, buf);

	return	 TRUE;
}
Exemple #9
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;
}