示例#1
0
/*
	BrowseDlg用 WM_COMMAND 処理
*/
BOOL TBrowseDirDlg::EvCommand(WORD wNotifyCode, WORD wID, LPARAM hwndCtl)
{
	switch (wID) {
	case MKDIR_BUTTON:
		{
			char		dirBuf[MAX_PATH], path[MAX_PATH];
			TInputDlg	dlg(dirBuf, this);
			if (dlg.Exec() != IDOK)
				return	TRUE;

			MakePath(path, fileBuf, dirBuf);
			if (::CreateDirectory(path, NULL)) {
				strcpy(fileBuf, path);
				dirtyFlg = TRUE;
				PostMessage(WM_CLOSE, 0, 0);
			}
		}
		return	TRUE;

	case RMDIR_BUTTON:
		if (::RemoveDirectory(fileBuf)) {
			GetParentDir(fileBuf, fileBuf);
			dirtyFlg = TRUE;
			PostMessage(WM_CLOSE, 0, 0);
		}
		return	TRUE;
	}
	return	FALSE;
}
//----------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------
Effect* Effect::Create(Manager* manager, const EFK_CHAR* path, float magnification, const EFK_CHAR* materialPath)
{
	Setting* setting = manager->GetSetting();

	EffectLoader* eLoader = setting->GetEffectLoader();

	if (setting == NULL) return NULL;

	void* data = NULL;
	int32_t size = 0;

	if (!eLoader->Load(path, data, size)) return NULL;

	EFK_CHAR parentDir[512];
	if (materialPath == NULL)
	{
		GetParentDir(parentDir, path);
		materialPath = parentDir;
	}

	Effect* effect = EffectImplemented::Create(manager, data, size, magnification, materialPath);

	eLoader->Unload(data, size);

	return effect;
}
示例#3
0
/*
	BrowseDlg用サブクラス生成
*/
BOOL TBrowseDirDlg::AttachWnd(HWND _hWnd)
{
	BOOL	ret = TSubClass::AttachWnd(_hWnd);
	dirtyFlg = FALSE;

// ディレクトリ設定
	DWORD	attr = GetFileAttributes(fileBuf);
	if (attr == 0xffffffff || (attr & FILE_ATTRIBUTE_DIRECTORY) == 0)
		GetParentDir(fileBuf, fileBuf);
	SendMessage(BFFM_SETSELECTION, TRUE, (LPARAM)fileBuf);
	SetWindowText(FASTCOPY);

// ボタン作成
	RECT	tmp_rect;
	::GetWindowRect(GetDlgItem(IDOK), &tmp_rect);
	POINT	pt = { tmp_rect.left, tmp_rect.top };
	::ScreenToClient(hWnd, &pt);
	int		cx = (pt.x - 30) / 2, cy = tmp_rect.bottom - tmp_rect.top;

	::CreateWindow(BUTTON_CLASS, GetLoadStr(IDS_MKDIR), WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON, 10,
		pt.y, cx, cy, hWnd, (HMENU)MKDIR_BUTTON, TApp::GetInstance(), NULL);
	::CreateWindow(BUTTON_CLASS, GetLoadStr(IDS_RMDIR), WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,
		18 + cx, pt.y, cx, cy, hWnd, (HMENU)RMDIR_BUTTON, TApp::GetInstance(), NULL);

	HFONT	hDlgFont = (HFONT)SendDlgItemMessage(IDOK, WM_GETFONT, 0, 0L);
	if (hDlgFont) {
		SendDlgItemMessage(MKDIR_BUTTON, WM_SETFONT, (UINT)hDlgFont, 0L);
		SendDlgItemMessage(RMDIR_BUTTON, WM_SETFONT, (UINT)hDlgFont, 0L);
	}

	return	ret;
}
示例#4
0
/*
	メインダイアログ用 WM_INITDIALOG 処理ルーチン
*/
BOOL TInstDlg::EvCreate(LPARAM lParam)
{
	GetWindowRect(&rect);
	int		cx = ::GetSystemMetrics(SM_CXFULLSCREEN), cy = ::GetSystemMetrics(SM_CYFULLSCREEN);
	int		xsize = rect.right - rect.left, ysize = rect.bottom - rect.top;

	::SetClassLong(hWnd, GCL_HICON,
					(LONG_PTR)::LoadIcon(TApp::GetInstance(), (LPCSTR)SETUP_ICON));
	MoveWindow((cx - xsize)/2, (cy - ysize)/2, xsize, ysize, TRUE);
	Show();

// プロパティシートの生成
	staticText.AttachWnd(GetDlgItem(INSTALL_STATIC));
	propertySheet = new TInstSheet(this, &cfg);

// 現在ディレクトリ設定
	char		buf[MAX_PATH], setupDir[MAX_PATH];
	TRegistry	reg(HKEY_LOCAL_MACHINE, BY_MBCS);

// タイトル設定
	if (IsWinVista() && TIsUserAnAdmin()) {
		GetWindowText(buf, sizeof(buf));
		strcat(buf, " (Admin)");
		SetWindowText(buf);
	}

// Program Filesのパス取り出し
	if (reg.OpenKey(REGSTR_PATH_SETUP)) {
		if (reg.GetStr(REGSTR_PROGRAMFILES, buf, sizeof(buf)))
			MakePath(setupDir, buf, FASTCOPY);
		reg.CloseKey();
	}

// 既にセットアップされている場合は、セットアップディレクトリを読み出す
	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.CloseKey();
	}

	if (!cfg.startMenu || !cfg.deskTop) {
		GetShortcutPath(&cfg);
	}

	SetDlgItemText(FILE_EDIT, cfg.setupDir ? toA(cfg.setupDir) : setupDir);

	CheckDlgButton(cfg.mode == SETUP_MODE ? SETUP_RADIO : UNINSTALL_RADIO, 1);
	ChangeMode();

	if (cfg.runImme) PostMessage(WM_COMMAND, MAKEWORD(IDOK, 0), 0);

	return	TRUE;
}
示例#5
0
SetDirectory::SetDirectory(const char* filename)
{
    directory = GetParentDir(filename);
    if (!directory.empty())
    {
        previousDir = GetCurrentDir();
        if (chdir(directory.c_str()) != 0)
            msg_error("SetDirectory") << "can't change directory.";
    }
}
示例#6
0
bool DirIsChildOf(const wxString &path, const wxString &child)
{
    wxString parent=path;
    while(!parent.IsEmpty())
    {
        if(wxFileName(path).SameAs(parent))
            return true;
        parent=GetParentDir(parent);
    }
    return false;
}
示例#7
0
SetDirectory::SetDirectory(const std::string& filename)
{
    directory = GetParentDir(filename.c_str());
    if (!directory.empty()){
        std::cout << ">chdir("<<directory<<")"<<std::endl;
		previousDir = GetCurrentDir();
#ifndef WIN32
        chdir(directory.c_str());
#else
        _chdir(directory.c_str());
#endif
    }
}
示例#8
0
//----------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------
Effect* Graphics_Imp::CreateEffect_(const achar* path)
{
	auto ret = EffectContainer->TryLoad(path, [this,path](uint8_t* data, int32_t size) -> Effect_Imp*
	{
		EFK_CHAR parentDir[512];	
		GetParentDir(parentDir, (const EFK_CHAR*) path);
	
		auto effect = Effekseer::Effect::Create(m_effectSetting, data, size, 1.0, parentDir);
		if (effect == nullptr) return nullptr;
		return Effect_Imp::CreateEffect(this, effect);
	});

	return ret;
}
示例#9
0
  bool PlexHierarchicalCache::CacheData (const void* data, size_t size,
				  	 const char* path)
  {
    size_t writeCacheIndex = (size_t)~0;
    for (size_t i = 0; i < caches.GetSize(); i++)
    {
      if (caches[i].cache->IsCacheWriteable())
      {
	writeCacheIndex = i;
	break;
      }
    }
    if (writeCacheIndex == (size_t)~0) return false;

    bool doWrite = true;
    
    if (redundantRemove)
    {
      csRef<iDataBuffer> nextData;
      for (size_t i = writeCacheIndex+1; i < caches.GetSize(); i++)
      {
	nextData = caches[i].cache->ReadCache (path);
	if (nextData.IsValid()) break;
      }
      if (nextData.IsValid()
	&& (nextData->GetSize() == size)
	&& (memcmp (data, nextData->GetData(), size) == 0))
      {
	/* The item to cache matches what's cached in some lower cache,
	 * so we don't have to cache it in the higher cache. Instead,
	 * remove it */
	doWrite = false;
	caches[writeCacheIndex].cache->ClearCache (path);
	
	// The containing directory may be empty, so try to tidy up later
	csString parentPath (GetParentDir (path));
	if (!parentPath.IsEmpty())
	  caches[writeCacheIndex].delayedClearDirs.Add (parentPath);
      }
    }
    
    if (doWrite)
      return caches[writeCacheIndex].cache->CacheData (data, size, path);
    else
      return true;
  }
示例#10
0
std::string SetDirectory::GetRelativeFromDir(const char* filename, const char* basename)
{
    if (!filename || !filename[0]) return "";
    if (IsAbsolute(filename)) return filename; // absolute path
    std::string base = basename;
    std::string s = filename;
    // remove any ".."
    while ((s.substr(0,3)=="../" || s.substr(0,3)=="..\\") && !base.empty())
    {
        s = s.substr(3);
        base = GetParentDir(base.c_str());
    }
    if (base.empty())
        return s;
    else if (base[base.length()-1] == '/')
        return base + s;
    else
        return base + "/" + s;
}
示例#11
0
/*
	ファイルの保存されているドライブ識別
*/
UINT GetDriveTypeEx(const char *file)
{
	if (file == NULL)
		return	GetDriveType(NULL);

	if (IsUncFile(file))
		return	DRIVE_REMOTE;

	char	buf[MAX_PATH];
	int		len = (int)strlen(file), len2;

	strcpy(buf, file);
	do {
		len2 = len;
		GetParentDir(buf, buf);
		len = (int)strlen(buf);
	} while (len != len2);

	return	GetDriveType(buf);
}
//----------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------
bool EffectImplemented::Reload( Manager* managers, int32_t managersCount, const EFK_CHAR* path, const EFK_CHAR* materialPath )
{
	if(m_pManager == NULL ) return false;

	Setting* loader = GetSetting();
	
	EffectLoader* eLoader = loader->GetEffectLoader();
	if( loader == NULL ) return false;

	void* data = NULL;
	int32_t size = 0;

	if( !eLoader->Load( path, data, size ) ) return false;

	EFK_CHAR parentDir[512];
	if( materialPath == NULL )
	{
		GetParentDir(parentDir, path);
		materialPath = parentDir;
	}

	for( int32_t i = 0; i < managersCount; i++)
	{
		((ManagerImplemented*)&(managers[i]))->BeginReloadEffect( this );
	}

	Reset();
	Load( data, size, m_maginificationExternal, materialPath );

	m_pManager->EndReloadEffect( this );

	for( int32_t i = 0; i < managersCount; i++)
	{
		((ManagerImplemented*)&(managers[i]))->EndReloadEffect( this );
	}

	return false;
}
示例#13
0
  void PlexHierarchicalCache::DelayClearDirs (SubCache& cache)
  {
    while (cache.delayedClearDirs.GetSize() > 0)
    {
      csSet<csString> newClearDirs;
      csSet<csString>::GlobalIterator it (cache.delayedClearDirs.GetIterator());
      while (it.HasNext())
      {
	csString dir (it.Next());
	csRef<iStringArray> subitems = cache.cache->GetSubItems (dir);
	if (subitems->GetSize() == 0)
	{
	  cache.cache->ClearCache (dir);
	
	  // Now the parent may be empty ... check on next cycle
	  csString parentPath (GetParentDir (dir));
	  if (!parentPath.IsEmpty())
	    newClearDirs.Add (parentPath);
	}
      }
      
      cache.delayedClearDirs = newClearDirs;
    }
  }
示例#14
0
int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{

	//detect if Notecase was started in portable mode 
	//(with no GTK installed on computer, but copied to the same directory as the Notecase.exe)
	std::string strDir = GetAppPath();
	strDir = GetParentDir(strDir.c_str());

	std::string strGtk = strDir;
	strGtk += "gtk\\";

	if(0 == _access(strGtk.c_str(), 0))	// GTK directory exists
	{
		//set variable so Notecase can detect portable mode in an easy way
		_putenv("NOTECASE_PORTABLE=1");

		//set directory for INI file
		char szBuffer[10024];
		_snprintf(szBuffer, sizeof(szBuffer)-1, "NOTECASE_HOME=%s", strDir.c_str());
		szBuffer[sizeof(szBuffer)-1] = '\0';
		_putenv(szBuffer);

		//set directory for help file
		std::string strHelp = strDir + "config\\help.ncd";
		_snprintf(szBuffer, sizeof(szBuffer)-1, "NOTECASE_HELP=%s", strHelp.c_str());
		szBuffer[sizeof(szBuffer)-1] = '\0';
		_putenv(szBuffer);

		//set directory for ini file, unless already set
		const char *szEnv = getenv("NOTECASE_INI");
		if(NULL == szEnv){
			std::string strIni = strDir + "config\\notecase.ini";
			_snprintf(szBuffer, sizeof(szBuffer)-1, "NOTECASE_INI=%s", strIni.c_str());
			szBuffer[sizeof(szBuffer)-1] = '\0';
			_putenv(szBuffer);
		}
		
		//TOFIX do we need to preserve existing path
		const char *szPath = getenv("PATH");
		int nLen = strlen(szPath);
		std::string strGtkBin = strGtk + "bin\\";
		_snprintf(szBuffer, sizeof(szBuffer)-1, "PATH=%s;%s;%s", strGtk.c_str(), strGtkBin.c_str(), szPath);
		szBuffer[sizeof(szBuffer)-1] = '\0';
		_putenv(szBuffer);

		std::string strURL = strDir;
		strURL += "app\\Notecase.exe";

		HINSTANCE hInstance = ShellExecute(NULL, "open", strURL.c_str(), (NULL != lpCmdLine) ? lpCmdLine : "", "", SW_SHOW);
		DWORD result = reinterpret_cast<DWORD>(hInstance);
		if (result <= HINSTANCE_ERROR)
		{
			ShowSystemErrorMessage(result); // format and show system error message
			return 1;
		}
	}
	else
		MessageBox(NULL, "Failed to find GTK directory!", "ERROR", MB_OK);

	return 0;
}
int WINAPI wWinMain(HINSTANCE hInstance,
	HINSTANCE hPrevInstance,
	LPWSTR lpOriginalCmdLine,
	int nCmdShow)
{
	int i;
	LOADED_IMAGE oImg;
	LPWSTR lpCmdLine;
	wchar_t parentDir[MAX_PATH+1] = L"", exePath[MAX_PATH+1] = L"";
	size_t szParentDir, szExeStr, szCmdLine, szPlatExe;
	PROCESS_INFORMATION pi;
	STARTUPINFO si;
	LPWSTR *argv = __wargv;
	int argc = __argc;

	// Zero out our loaded image struct.
	ZeroMemory(&oImg, sizeof(oImg));

	/* Make sure we have args. */
	if(argc == 1) {
		Fatal(1L, L"No images specified.");
	}
	

	/* Get our exe's parent folder. */
	if(!GetParentDir(parentDir, &szParentDir)) {
		Fatal(1L, L"Could not get parent folder of image, \"%s\". This should not happen ever.", argv[0]);
	}

	/* Iterate through our arguments */
	for(i = 1; i < argc; i++) {
		/* Verify file exists. */
		if(_waccess(argv[i], 00) == -1) {
			Fatal(1L, L"File does not exist.\nFile: %s", argv[i]);
		}

		/* Get the binary type. */
		if(!MapAndLoadW(argv[i], &oImg)) {
			Fatal(1L, L"Unable to get binary type for image.\nImage: %s", argv[i]);
		}

		lstrcpyW(exePath, parentDir);
		switch(oImg.FileHeader->FileHeader.Machine)
		{
			case IMAGE_FILE_MACHINE_I386:
				lstrcatW(exePath, x86exe);
				szPlatExe = SZ_86_EXE;
				break;
			// TODO: Differentiate between x64 platforms.
			case IMAGE_FILE_MACHINE_AMD64:
				lstrcatW(exePath, amd64exe);
				szPlatExe = SZ_AMD_EXE;
				break;
			case IMAGE_FILE_MACHINE_IA64:
				lstrcatW(exePath, ia64exe);
				szPlatExe = SZ_IA_EXE;
				break;
			default:
				Fatal(1L, L"Unknown binary type returned for image.\nImage: %s\n\nBinary Type: %d", argv[i], oImg.FileHeader->FileHeader.Machine);
		}

		if(!UnMapAndLoad(&oImg)) {
			Fatal(1L, L"Failed to unload/unmap image.\nImage: %s", argv[i]);
		}

		/* Calculate the length of the eventual exe path with surrounding quotes. */
		lstrcatW(exePath, depsexe);
		szExeStr = szParentDir + szPlatExe + 2; // +2 for the two "s surrounding the image path.

		/* Allocate our command line string. */
		// szExeStr+         1 +1+wcslen(argv)+1
		// "(path)depends.exe" "argv"
		szCmdLine = szExeStr + lstrlenW(argv[i]) + 3;
		lpCmdLine = (LPWSTR)LocalAlloc(LPTR, sizeof(wchar_t) * (szCmdLine + 1));
		if(lpCmdLine == NULL) {
			Fatal(1L, L"Could not allocate memory.\nMemory required (bytes): %d", sizeof(wchar_t) * (szCmdLine + 1));
		}
		if(swprintf(lpCmdLine, szCmdLine+1, L"\"%s\" \"%s\"", exePath, argv[i]) == -1) {
			LocalFree(lpCmdLine);
			FatalCall(L"swprintf");
		}

		ZeroMemory(&si, sizeof(si));
		si.cb = sizeof(si);
		ZeroMemory(&pi, sizeof(pi));

		/* Depends launching. */
		if (!CreateProcessW(
			NULL,		/* No module name (use command line) */
			lpCmdLine,	/* Command line */
			NULL,		/* Process handle not inheritable */
			NULL,		/* Thread handle not inheritable */
			FALSE,		/* Set handle inheritance to FALSE */
			0,			/* No creation flags */
			NULL,		/* Use parent's environment block */
			NULL,		/* Use parent's starting directory */
			&si,		/* Pointer to STARTUPINFO structure */
			&pi			/* Pointer to PROCESS_INFORMATION structure */
		)) {
			// len("CreateProcessW") + len(" - ") + len(cmdline)
			szCmdLine += 17;
			LocalFree(lpCmdLine);
			lpCmdLine = (LPWSTR)LocalAlloc(LPTR, sizeof(wchar_t) * (szCmdLine + 1));
			swprintf(lpCmdLine, szCmdLine+1, L"CreateProcessW - \"%s\" \"%s\"", exePath, argv[i]);
			FatalCall(lpCmdLine);
		}
		LocalFree(lpCmdLine);
	}
	return 0;
}
示例#16
0
std::string SetDirectory::GetRelativeFromFile(const char* filename, const char* basename)
{
    std::string base = GetParentDir(basename);
    return GetRelativeFromDir(filename, base.c_str());
}
示例#17
0
int TSaveCommonDlg::Exec(void)
{
	modalFlg = TRUE;

	char	fname[MAX_BUF], last_dir[MAX_BUF], buf[MAX_BUF], *ext;

	// 最終保存ディレクトリが無くなっている場合、少しさかのぼる
	for (int i=0; i < 5; i++) {
		if (*cfg->lastSaveDir && GetFileAttributesU8(cfg->lastSaveDir) == 0xffffffff)
			if (!PathToDir(cfg->lastSaveDir, cfg->lastSaveDir))
				break;
	}

	strcpy(last_dir, *cfg->lastSaveDir ? cfg->lastSaveDir : ".");

	while (1) {
		FileInfo	*fileInfo = shareInfo->fileInfo[offset];

		MakePath(fname, last_dir, fileInfo->Fname());

	// ファイルダイアログ
		TApp::GetApp()->AddWin(this);
		BOOL	ret = OpenFileDlg(parentWin, OpenFileDlg::NODEREF_SAVE, (LPOFNHOOKPROC)TApp::WinProc).Exec(fname, GetLoadStrU8(IDS_SAVEFILE), GetLoadStrAsFilterU8(IDS_OPENFILEALLFLTR), last_dir);
		TApp::GetApp()->DelWin(this);
		hWnd = NULL;

		if (!ret)
			return	FALSE;

	// shortcut の場合は、リンク先に飛ぶ
		if (!isLinkFile && (ext = strrchr(fname, '.')) && stricmp(ext, ".lnk") == 0) {
			char	arg[MAX_BUF];
			if (ReadLinkU8(fname, last_dir, arg)) {
				if ((GetFileAttributesU8(last_dir) & FILE_ATTRIBUTE_DIRECTORY) == 0)
					GetParentDir(last_dir, last_dir);
			}
			continue;
		}

		fileInfo = shareInfo->fileInfo[offset];

		PathToDir(fname, last_dir);
		ForcePathToFname(fname, fname);
		fileInfo->SetSelected(TRUE);

	// 上書き確認
		for (int i=0; i < shareInfo->fileCnt; i++)
		{
			if (!shareInfo->fileInfo[i]->IsSelected())
				continue;
			MakePath(buf, last_dir, offset == i ? fname : shareInfo->fileInfo[i]->Fname());
			if (GetFileAttributesU8(buf) != 0xffffffff)
			{
				ret = parentWin->MessageBoxU8(GetLoadStrU8(IDS_OVERWRITE), GetLoadStrU8(IDS_ATTENTION), MB_OKCANCEL|MB_ICONEXCLAMATION);
				if (ret != IDOK) {
					for (int j=0; j < shareInfo->fileCnt; j++)
						shareInfo->fileInfo[j]->SetSelected(FALSE);
				}
				break;
			}
		}
		if (ret) {
			fileInfo->SetFname(fname);
			strcpy(cfg->lastSaveDir, last_dir);
			cfg->WriteRegistry(CFG_GENERAL);
			return	TRUE;
		}
	}
	// not reach
}
示例#18
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;
}
示例#19
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;
}