Example #1
0
int main(int argc, char** argv) {

	char szPath[MAX_PATH];

	for (int i = 1; i < argc; i++) {

		PathRemoveFileSpec(lstrcpy(szPath, argv[i]));

		WIN32_FIND_DATA findData;
		HANDLE hFind = FindFirstFile(argv[i], &findData);
		if (hFind != INVALID_HANDLE_VALUE) {
			do {
				char szFile[MAX_PATH];

				PathAppend(lstrcpy(szFile, szPath), findData.cFileName);

				printf("%s\n", szFile);

				wc_info wci;

				FILE* fp = fopen(szFile, "r");
				if (fp) {
					ZeroMemory(&wci, sizeof(wci));

					wci.m_size = _filelength(fileno(fp));
					wci.m_p = malloc(wci.m_size);
					fread(wci.m_p, sizeof(char), wci.m_size, fp);
					fclose(fp);

					wc(wci);

					printf("バイト数: %u\n", wci.m_count_byte);
					printf("  文字数: %u\n", wci.m_count_char);

					free(wci.m_p);
				}
			} while (FindNextFile(hFind, &findData));

			FindClose(hFind);
		}
	}

	_getch();

	return 0;
}
bool ConfigurationHolder::buildConfigFilePath(const WCHAR* fileName)
{
	ZeroMemory(configPath, sizeof(configPath));

	if (!GetModuleFileName(0, configPath, _countof(configPath)))
	{
#ifdef DEBUG_COMMENTS
		Scylla::debugLog.log(L"buildConfigFilePath :: GetModuleFileName failed %d", GetLastError());
#endif
		return false;
	}

	PathRemoveFileSpec(configPath);
	PathAppend(configPath, fileName);

	return true;
}
int wmain( int argc, const wchar_t *argv[] )
{
#ifndef BUILD_SETUP
	if(argc==2)
	{
		if(wcscmp(L"-install",argv[1])==0)
			InstallService();
		else if (wcscmp(L"-uninstall",argv[1])==0)
			UninstallService();
		return 0;
	}
#endif
	SERVICE_TABLE_ENTRY DispatchTable[]={
		{(wchar_t*)g_ServiceName, ServiceMain},
		{NULL, NULL}
	};
	HKEY hKey;
	if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,L"SOFTWARE\\IvoSoft\\ClassicShell",0,KEY_READ|KEY_WOW64_64KEY,&hKey)==ERROR_SUCCESS)
	{
		DWORD log;
		DWORD size=sizeof(log);
		if (RegQueryValueEx(hKey,L"LogService",0,NULL,(BYTE*)&log,&size)==ERROR_SUCCESS && log)
		{
			GetModuleFileName(NULL,g_LogName,_countof(g_LogName));
			PathRemoveFileSpec(g_LogName);
			PathAppend(g_LogName,L"service.log");
			LogText("Starting service\n");
		}

		DWORD dump;
		size=sizeof(dump);

		if (RegQueryValueEx(hKey,L"CrashDump",0,NULL,(BYTE*)&dump,&size)==ERROR_SUCCESS && dump>0)
		{
			if (dump==1) MiniDumpType=MiniDumpNormal;
			if (dump==2) MiniDumpType=MiniDumpWithDataSegs;
			if (dump==3) MiniDumpType=MiniDumpWithFullMemory;
			SetUnhandledExceptionFilter(TopLevelFilter);
		}
		RegCloseKey(hKey);
	}

	StartServiceCtrlDispatcher(DispatchTable);
	return 0;
}
Example #4
0
// determine the directory for a given pathname
// (wstring only for now; feel free to make this a template if needed)
/*static*/ wstring File::DirectoryPathOf(wstring path)
{
#ifdef _WIN32
    // Win32 accepts forward slashes, but it seems that PathRemoveFileSpec() does not
    // TODO:
    // "PathCchCanonicalize does the / to \ conversion as a part of the canonicalization, it's
    // probably a good idea to do that anyway since I suspect that the '..' characters might
    // confuse the other PathCch functions" [Larry Osterman]
    // "Consider GetFullPathName both for canonicalization and last element finding." [Jay Krell]
    path = msra::strfun::ReplaceAll<wstring>(path, L"/", L"\\");

    HRESULT hr;
    if (IsWindows8OrGreater()) // PathCchRemoveFileSpec() only available on Windows 8+
    {
        typedef HRESULT(*PathCchRemoveFileSpecProc)(_Inout_updates_(_Inexpressible_(cchPath)) PWSTR, _In_ size_t);
        HINSTANCE hinstLib = LoadLibrary(TEXT("api-ms-win-core-path-l1-1-0.dll"));
        if (hinstLib == nullptr)
            RuntimeError("DirectoryPathOf: LoadLibrary() unexpectedly failed.");
        PathCchRemoveFileSpecProc PathCchRemoveFileSpec = reinterpret_cast<PathCchRemoveFileSpecProc>(GetProcAddress(hinstLib, "PathCchRemoveFileSpec"));
        if (!PathCchRemoveFileSpec)
            RuntimeError("DirectoryPathOf: GetProcAddress() unexpectedly failed.");

        // this is the actual function call we care about
        hr = PathCchRemoveFileSpec(&path[0], path.size());

        FreeLibrary(hinstLib);
    }
    else // on Windows 7-, use older PathRemoveFileSpec() instead
        hr = PathRemoveFileSpec(&path[0]) ? S_OK : S_FALSE;

    if (hr == S_OK) // done
        path.resize(wcslen(&path[0]));
    else if (hr == S_FALSE) // nothing to remove: use .
        path = L".";
    else
        RuntimeError("DirectoryPathOf: Path(Cch)RemoveFileSpec() unexpectedly failed with 0x%08x.", (unsigned int)hr);
#else
    auto pos = path.find_last_of(L"/");
    if (pos != path.npos)
        path.erase(pos);
    else // if no directory path at all, use current directory
        return L".";
#endif
    return path;
}
static BOOL find_portable_dir(LPCWSTR base, LPWSTR *result, BOOL *existing) {
    WCHAR buf[4*MAX_PATH] = {0};

    _snwprintf_s(buf, 4*MAX_PATH, _TRUNCATE, L"%s\\calibre-portable.exe", base);
    *existing = true;

    if (file_exists(buf)) {
        *result = _wcsdup(base);
        if (*result == NULL) { show_error(L"Out of memory"); return false; }
        return true;
    }

    WIN32_FIND_DATA fdFile; 
    HANDLE hFind = NULL;
    _snwprintf_s(buf, 4*MAX_PATH, _TRUNCATE, L"%s\\*", base);

    if((hFind = FindFirstFileEx(buf, FindExInfoStandard, &fdFile, FindExSearchLimitToDirectories, NULL, 0)) != INVALID_HANDLE_VALUE) {
        do {
            if(is_dots(fdFile.cFileName)) continue;

            if(fdFile.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
                _snwprintf_s(buf, 4*MAX_PATH, _TRUNCATE, L"%s\\%s\\calibre-portable.exe", base, fdFile.cFileName);
                if (file_exists(buf)) {
                    *result = _wcsdup(buf);
                    if (*result == NULL) { show_error(L"Out of memory"); return false; }
                    PathRemoveFileSpec(*result);
                    FindClose(hFind);
                    return true;
                }
            } 
        } while(FindNextFile(hFind, &fdFile));
        FindClose(hFind);
    }

    *existing = false;
    _snwprintf_s(buf, 4*MAX_PATH, _TRUNCATE, L"%s\\Calibre Portable", base);
    if (!CreateDirectory(buf, NULL) && GetLastError() != ERROR_ALREADY_EXISTS) {
        show_last_error(L"Failed to create Calibre Portable folder");
        return false;
    }
    *result = _wcsdup(buf);
    if (*result == NULL) { show_error(L"Out of memory"); return false; }

    return true;
}
Example #6
0
void CMainFrame::OnCmdRun()
{
	CDocument *pDoc = GetActiveFrame()->GetActiveDocument();
	pDoc->DoFileSave();

	CString strApp = theApp.CombinePath( theApp.GetPath(), theApp.m_strCompilerApp );
	SetEnvironmentVariable( _T("NEWPAS"), '"' + strApp + '"' );

	CString strArgs;
	// using an environ. var. because cmd /C doesn't support more than 1 quoted path
	strArgs.Format( _T("/C %%NEWPAS%% \"%s\" execvm & pause"), (LPCTSTR)pDoc->GetPathName() );

	TCHAR szFolder[MAX_PATH];
	_tcscpy_s( szFolder, MAX_PATH, pDoc->GetPathName() );
	PathRemoveFileSpec( szFolder );

	::ShellExecute( 0, _T("open"), _T("cmd"), strArgs, szFolder, SW_SHOW );
}
Example #7
0
bool GetDirectory(String& path)
{
	DWORD dwFileAttrs = GetFileAttributes(path.c_str());
	if (dwFileAttrs == INVALID_FILE_ATTRIBUTES)
		return false;

	// if path is not a directory, take its parent directory
	if ((dwFileAttrs & FILE_ATTRIBUTE_DIRECTORY) == 0)
	{
		TCHAR* pszPath = new TCHAR[path.length() + 1];
		_tcscpy(pszPath, path.c_str());
		PathRemoveFileSpec(pszPath);
		path = String(pszPath);
		delete pszPath;
	}

	return true;
}
Example #8
0
bool TexCubeWnd::OnEnvCreate()
{
	if(!m_xCube.Create(this))
	{
		return false;
	}

	D3DLIGHT9 lgt;
	ZeroMemory(&lgt, sizeof(lgt));
	lgt.Type = D3DLIGHT_DIRECTIONAL;
	lgt.Ambient   = D3DXCOLOR(0.8f, 0.8f, 0.8f, 1.0f);
	lgt.Diffuse   = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
	lgt.Specular  = D3DXCOLOR(0.2f, 0.2f, 0.2f, 1.0f);
	lgt.Direction = D3DXVECTOR3(1.0f, -1.0f, 0.0f);
	m_pD3Dev9->SetLight(0, &lgt);
	m_pD3Dev9->LightEnable(0, TRUE);

	m_pD3Dev9->SetRenderState(D3DRS_NORMALIZENORMALS, TRUE);
	m_pD3Dev9->SetRenderState(D3DRS_SPECULARENABLE, TRUE);

	char szTexturePath[MAX_PATH] = {0};
	GetModuleFileName(NULL, szTexturePath, sizeof(szTexturePath));
	PathRemoveFileSpec(szTexturePath);
	strcat(szTexturePath, "\\res\\p2c6_tex01.jpg");

	if(!PathFileExists(szTexturePath))
	{
		MessageBox(NULL, "Cannot load texture...", "Error", MB_ICONERROR | MB_OK);
		return false;
	}

	HRESULT hr = D3DXCreateTextureFromFile(m_pD3Dev9, szTexturePath, &m_pTex);
	if(D3D_OK != hr ||
		NULL == m_pTex)
	{
		return false;
	}

	D3DXVECTOR3 pos(0.0f, 0.0f, -4.0f);
	Gfx_SetViewTransform(&pos);
	Gfx_SetProjectionTransform();

	return true;
}
Example #9
0
co_rc_t co_winnt_load_driver_lowlevel_by_name(char *name, char *path) 
{ 
	SC_HANDLE   schSCManager; 
	char fullpath[0x100] = {0,};
	char driverfullpath[0x100] = {0,};
	co_rc_t rc;

	GetModuleFileName(co_current_win32_instance, fullpath, sizeof(fullpath));
	PathRemoveFileSpec(fullpath);
	PathCombine(driverfullpath, fullpath, path);

	co_terminal_print("loading %s\n", driverfullpath);

	schSCManager = OpenSCManager(NULL,                 // machine (NULL == local) 
				     NULL,                 // database (NULL == default) 
				     SC_MANAGER_ALL_ACCESS /* access required */ );

	rc = co_winnt_install_driver_lowlevel(schSCManager, name, driverfullpath);
	if (!CO_OK(rc)) {
		CloseServiceHandle(schSCManager);    
		return rc;
	}

	rc = co_winnt_start_driver_lowlevel(schSCManager, name); 
	if (!CO_OK(rc)) {
		co_winnt_remove_driver_lowlevel(schSCManager, name); 
		CloseServiceHandle(schSCManager);    
		return rc;
	}

#if (0)
	rc = co_os_check_device(name); 
	if (!CO_OK(rc)) {
		co_winnt_stop_driver_lowlevel(schSCManager, name);  
		co_winnt_remove_driver_lowlevel(schSCManager, name); 
		CloseServiceHandle(schSCManager);    
		return rc;
	}
#endif

	CloseServiceHandle(schSCManager);    

	return CO_RC(OK);
} 
ModelPtr XFileLoader::OpenFromResource( int resourceID,float scale )
{
	HRESULT hr = S_OK;

	m_fileName = _T("");

	TCHAR path[MAX_PATH];
	_tcscpy_s( path,MAX_PATH,m_fileName.c_str() );
	PathRemoveFileSpec( path );
	PathAddBackslash( path );
	m_path = path;

	m_scale = scale;

	Graphics* graphics = Graphics::GetInstance();
	IDirect3DDevice9Ptr pD3DDevice = graphics->GetDirect3DDevice();

	m_pAdjacencyBuf = NULL;
	m_pMaterialBuf = NULL;
	m_pEffectInstancesBuf = NULL;
	m_Materials = 0;
	m_pD3DMesh = NULL;

	ModelPtr pModel;

	hr = D3DXLoadMeshFromXResource(
		NULL,
		(LPSTR)MAKEINTRESOURCE( resourceID ),
		(LPSTR)RT_RCDATA,
		D3DXMESH_SYSTEMMEM,
		pD3DDevice,
		&m_pAdjacencyBuf,
		&m_pMaterialBuf,
		&m_pEffectInstancesBuf,
		&m_Materials,
		&m_pD3DMesh );

	if( FAILED(hr) )
	{
		return ModelPtr();
	}

	return ModelPtr( new Model( CreateMeshContainer() ) );
}
Example #11
0
void CExtractData::DeleteTmpFile()
{
	// Add the last remaining temporary files
	LoadTmpFileList();

	for (std::set<YCString>::iterator itr = m_ssTmpFile.begin(); itr != m_ssTmpFile.end(); )
	{
		TCHAR szTmp[MAX_PATH];
		lstrcpy(szTmp, *itr);

		// Delete temporary files

		if (PathFileExists(szTmp))
		{
			// File exists

			if (!DeleteFile(szTmp))
			{
				// Fails to remove it

				itr++;
				continue;
			}
		}

		while (lstrcmp(szTmp, m_pOption->TmpDir) != 0)
		{
			// Delete folder

			if (!PathRemoveFileSpec(szTmp))
			{
				break;
			}

			RemoveDirectory(szTmp);
		}

		itr = m_ssTmpFile.erase(itr);
	}

	// Save the list of remaining temp files
	SaveTmpFileList();
}
Example #12
0
void CMd5ItemCached::SetMd5Item(CMd5Item *pMd5Item)
{
    if ((pMd5Item != m_pMd5Item) || (pMd5Item->GetVersion() != m_nVersion))
    {
        m_pMd5Item = pMd5Item;
        m_nVersion = pMd5Item->GetVersion();

        if (pMd5Item->GetFileName() == pMd5Item->GetFullPath())
            *m_szFolderPath = 0;
        else
        {
            _tcsncpy_s(m_szFolderPath, MAX_PATH, pMd5Item->GetFullPath(), _TRUNCATE);
            PathRemoveFileSpec(m_szFolderPath);
        }

        if (!pMd5Item->IsNA())
        {
            TCHAR szSize[MAX_NUM_STR];
            NUMBERFMT nf;
            nf.NumDigits = 0;
            nf.LeadingZero = 0;
            nf.Grouping = 3;
            nf.lpDecimalSep = _T(".");
            nf.lpThousandSep = _T(",");
            nf.NegativeOrder = 1;
            _stprintf_s(szSize, MAX_NUM_STR, _T("%lld"), pMd5Item->GetSize());
            GetNumberFormat(LOCALE_USER_DEFAULT, 0, szSize, &nf, m_szSize, MAX_NUM_STR);

            TCHAR szDate[MAX_DATE_STR];
            TCHAR szTime[MAX_DATE_STR];
            SYSTEMTIME st;
            FileTimeToSystemTime(&pMd5Item->GetModified(), &st);
            GetDateFormat(LOCALE_USER_DEFAULT, DATE_SHORTDATE, &st, NULL, szDate, MAX_DATE_STR);
            GetTimeFormat(LOCALE_USER_DEFAULT, 0, &st, NULL, szTime, MAX_DATE_STR);
            _stprintf_s(m_szModified, MAX_DATE_STR, _T("%s %s"), szDate, szTime);
        }
        else
        {
            *m_szSize = 0;
            *m_szModified = 0;
        }
    }
}
Example #13
0
UINT CSAStatusLog::Init(const TCHAR *pLogFilename)
{
	UINT ErrorCode;

	// get application path
	TCHAR szAppPath[MAX_PATH]={0};
	if (! GetModuleFileName(NULL,szAppPath,MAX_PATH))
	{
		return GetLastError();
	}

	// Call to "PathRemoveFileSpec". get app path.
	if (!PathRemoveFileSpec(szAppPath))
	{
		return GetLastError();
	}

	// Create Log Dir
	TCHAR szLogDir[MAX_PATH]={0};
	_stprintf_s(szLogDir,_T("%s\\Log"),szAppPath);

	BOOL rt = CreateDirectory(szLogDir,NULL);
	if (!rt && GetLastError() != 183)
	{
		int err = GetLastError();
		_tprintf(_T("Create directory %s error(%d).\r\n"),szLogDir,err);
		return err;
	}

	SYSTEMTIME sys; 
	GetLocalTime( &sys ); 
	_stprintf_s(m_szLogfile,_T("%s\\%s_%02d%02d%02d_%02d%02d.Log"),szLogDir,pLogFilename,sys.wYear,sys.wMonth,sys.wDay,sys.wHour,sys.wMinute);

	// create log file
	ErrorCode = CreateLogfile(m_hFile);
	if (ErrorCode)
	{
		return ErrorCode;
	}

	m_bEnable = TRUE;
	return 0;
}
Example #14
0
bool get_executable_directory(std::string &buffer) {
#ifdef WIN32
    char name[MAX_PATH];
    if (!GetModuleFileName(NULL, name, MAX_PATH))
        return false;
    PathRemoveFileSpec(name);
    buffer = name;
    return true;
#else
    char path[512];
    int ch = readlink("/proc/self/exe", path, 512);
    if (ch != -1) {
        path[ch] = 0;
        buffer = path;
        buffer = buffer.substr(0, buffer.find_last_of("/"));
    }
    return ch != -1;
#endif
}
BOOL CBatchRunBtn::OnSetLCID(DWORD dwLCID, HMODULE hInstance)
{
	TCHAR szLCID[20];
	wsprintf(szLCID, TEXT("%d"), dwLCID);
	BOOL ret = CTlbButton::OnSetLCID(dwLCID, hInstance);

	TCHAR langPath[MAX_PATH];
	LONG cbData = sizeof(langPath);
	RegQueryValue(HKEY_CLASSES_ROOT, TEXT("CLSID\\{FC712CA0-A945-11D4-A594-956F6349FC18}\\InprocServer32"), langPath, &cbData);
	PathRemoveFileSpec(langPath);
	PathAddBackslash(langPath);
	lstrcat(langPath, TEXT("langs\\"));
	lstrcat(langPath, szLCID);
	lstrcat(langPath, TEXT("\\batchrun.xml"));
	m_xui.clearStrings();
	m_xui.loadStrings(langPath);

	return ret;
}
bool CConfigIni::LoadConfig(LPCTSTR strIni)
{
	if(strIni == NULL)
	{
		TCHAR l_szIniPath[MAX_PATH] = {0};
		GetModuleFileName(AfxGetInstanceHandle(), l_szIniPath, MAX_PATH);
		PathRemoveFileSpec(l_szIniPath);
		PathAddBackslash(l_szIniPath);
		m_szPath = l_szIniPath;
		StrCat(l_szIniPath, l_szIniFilename);
		m_szIni = l_szIniPath;
	}
	else m_szIni = strIni;

	//节点名
	LoadString(l_szIniKey_Sys, l_szIniItem_Sys, m_szName);

	return LoadCurrentSystem();
}
Example #17
0
bool InitializeEasyLogging()
{
    char dll_path[MAX_PATH] = { '\0' };
    if (GetModuleFileName(dll_handle, dll_path, MAX_PATH) == 0)
        return false;
    PathRemoveFileSpec(dll_path);

    std::string mhud2_dir = std::string(dll_path);
    std::string conf_file = mhud2_dir + "/MHUD2.log.conf";
    std::string log_file = mhud2_dir + "/MHUD2.log";

    el::Configurations logger_conf(conf_file);
    logger_conf.setGlobally(el::ConfigurationType::Format, "[%datetime{%Y-%M-%d %h:%m:%s %F}] "
            "[TID: %thread] [%level] [HookDLL] %msg");
    logger_conf.setGlobally(el::ConfigurationType::Filename, log_file);
    logger_conf.setGlobally(el::ConfigurationType::ToFile, "true");

    el::Loggers::setDefaultConfigurations(logger_conf, true);
}
Example #18
0
bool FileSystem::CreateRecursiveDirectory(const stringRef& filepath)
{
    bool result = false;
    wchar_t path_copy[MAX_PATH] = {0};
	wcscat_s(path_copy, MAX_PATH, filepath.str());
    std::vector<std::wstring> path_collection;

    for(int level=0; PathRemoveFileSpec(path_copy); level++)
    {
        path_collection.push_back(path_copy);
    }
    for(int i=path_collection.size()-1; i >= 0; i--)
    {
        if(!PathIsDirectory(path_collection[i].c_str()))
            if(CreateDirectory(path_collection[i].c_str(), NULL))
                result = true;
    }
    return result;
};
Example #19
0
void RegisterShellMenu(std::wstring opt, wchar_t* keyBaseName)
{
	// First, get the paths we will use

	wchar_t exePath[MAX_PATH] = { 0 };
	wchar_t icoPath[MAX_PATH] = { 0 };

	GetModuleFileName(NULL, exePath, sizeof(exePath));

	wchar_t commandStr[MAX_PATH + 20] = { 0 };
	swprintf_s(commandStr, L"\"%s\" \"%%V\"", exePath);

	// Now that we have `commandStr`, it's OK to change `exePath`...
	PathRemoveFileSpec(exePath);

	PathCombine(icoPath, exePath, L"icons\\cmder.ico");

	// Now set the registry keys

	HKEY root = GetRootKey(opt);

	HKEY cmderKey;
	FAIL_ON_ERROR(
		RegCreateKeyEx(root, keyBaseName, 0, NULL,
		REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &cmderKey, NULL));

	FAIL_ON_ERROR(RegSetValue(cmderKey, L"", REG_SZ, L"Cmder Here", NULL));
	FAIL_ON_ERROR(RegSetValueEx(cmderKey, L"NoWorkingDirectory", 0, REG_SZ, (BYTE *)L"", 2));

	FAIL_ON_ERROR(RegSetValueEx(cmderKey, L"Icon", 0, REG_SZ, (BYTE *)icoPath, wcslen(icoPath) * sizeof(wchar_t)));

	HKEY command;
	FAIL_ON_ERROR(
		RegCreateKeyEx(cmderKey, L"command", 0, NULL,
		REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &command, NULL));

	FAIL_ON_ERROR(RegSetValue(command, L"", REG_SZ, commandStr, NULL));

	RegCloseKey(command);
	RegCloseKey(cmderKey);
	RegCloseKey(root);
}
Example #20
0
static BOOL
get_release_notes(wchar_t rpath[MAX_PATH])
{
    BOOL rv  = FALSE;
    HKEY hk_client = NULL;
    wchar_t cpath[MAX_PATH];
    DWORD cb_data;

    if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
                     L"Software\\TransarcCorporation\\AFS Client\\CurrentVersion",
                     0, KEY_READ, &hk_client) != ERROR_SUCCESS)
        return FALSE;

    cb_data = sizeof(cpath);
    if (RegQueryValueEx(hk_client, L"PathName", NULL, NULL, (LPBYTE) cpath, &cb_data) != ERROR_SUCCESS)
        goto done;

    cpath[min(cb_data, MAX_PATH - 1)] = L'\0';

    if (!PathRemoveFileSpec(cpath))
        goto done;

    if (!PathAppend(cpath, L"Documentation"))
        goto done;

    if (!PathAppend(cpath, L"ReleaseNotes.chm"))
        goto done;

    if (!PathCanonicalize(rpath, cpath))
        goto done;

    if (!PathFileExists(rpath))
        goto done;

    rv = TRUE;

 done:
    if (hk_client)
        RegCloseKey(hk_client);

    return rv;
}
ModelPtr XFileLoader::Open( const tstring& filePath,float scale )
{
	HRESULT hr = S_OK;

	m_fileName = filePath;

	TCHAR path[MAX_PATH];
	_tcscpy_s( path,MAX_PATH,filePath.c_str() );
	PathRemoveFileSpec( path );
	PathAddBackslash( path );
	m_path = path;

	m_scale = scale;

	Graphics* graphics = Graphics::GetInstance();
	IDirect3DDevice9Ptr pD3DDevice = graphics->GetDirect3DDevice();

	m_pAdjacencyBuf = NULL;
	m_pMaterialBuf = NULL;
	m_pEffectInstancesBuf = NULL;
	m_Materials = 0;
	m_pD3DMesh = NULL;

	ModelPtr pModel;

	hr = D3DXLoadMeshFromX(
		m_fileName.c_str(),
		D3DXMESH_SYSTEMMEM,
		pD3DDevice,
		&m_pAdjacencyBuf,
		&m_pMaterialBuf,
		&m_pEffectInstancesBuf,
		&m_Materials,
		&m_pD3DMesh );

	if( FAILED(hr) )
	{
		return ModelPtr();
	}

	return ModelPtr( new Model( CreateMeshContainer() ) );
}
Example #22
0
static void NewVersionCallback( DWORD newVersion, CString downloadUrl, CString news )
{
	if (newVersion>GetVersionEx(g_Instance))
	{
		wchar_t path[_MAX_PATH];
		GetModuleFileName(g_Instance,path,_countof(path));
		PathRemoveFileSpec(path);
		PathAppend(path,L"ClassicShellUpdate.exe");
		wchar_t cmdLine[1024];
		Sprintf(cmdLine,_countof(cmdLine),L"\"%s\" -popup",path);
		STARTUPINFO startupInfo={sizeof(startupInfo)};
		PROCESS_INFORMATION processInfo;
		memset(&processInfo,0,sizeof(processInfo));
		if (CreateProcess(path,cmdLine,NULL,NULL,TRUE,0,NULL,NULL,&startupInfo,&processInfo))
		{
			CloseHandle(processInfo.hThread);
			CloseHandle(processInfo.hProcess);
		}
	}
}
Example #23
0
int thcrap_inject_into_running(HANDLE hProcess, const char *run_cfg_fn)
{
	int ret = -1;
	HMODULE inj_mod = NULL;

	if(GetModuleHandleEx(
		GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT | GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS,
		(LPTSTR)thcrap_inject_into_running,
		&inj_mod
	)) {
		size_t cur_dir_len = GetCurrentDirectory(0, NULL) + 1;
		size_t inj_dir_len = GetModuleFileNameU(inj_mod, NULL, 0) + 1;
		VLA(char, inj_dll, inj_dir_len);
		VLA(char, inj_dir, inj_dir_len);

		STRLEN_DEC(run_cfg_fn);
		size_t param_len = cur_dir_len + run_cfg_fn_len;
		VLA(char, abs_run_cfg_fn, param_len);
		const char *param;

		GetModuleFileNameU(inj_mod, inj_dir, inj_dir_len);
		strncpy(inj_dll, inj_dir, inj_dir_len);
		PathRemoveFileSpec(inj_dir);
		PathAddBackslashA(inj_dir);

		// Allow for relative directory names
		if(PathIsRelativeA(run_cfg_fn)) {
			GetCurrentDirectory(cur_dir_len, abs_run_cfg_fn);
			PathAppendA(abs_run_cfg_fn, run_cfg_fn);
			param = abs_run_cfg_fn;
		} else {
			param = run_cfg_fn;
			param_len = run_cfg_fn_len;
		}
		ret = Inject(hProcess, inj_dir, inj_dll, "thcrap_init", param, param_len);
		VLA_FREE(abs_run_cfg_fn);
		VLA_FREE(inj_dir);
		VLA_FREE(inj_dll);
	}
	return ret;
}
Example #24
0
BOOL HookController::init()
{
	WM_CBTHOOK = RegisterWindowMessage(WM_CBTHOOK_MSG);

	char exePath[MAX_PATH];
	GetModuleFileName(NULL,exePath,MAX_PATH);
	PathRemoveFileSpec(exePath);

	char dllPath[MAX_PATH];
	sprintf(dllPath, "%s\\%s", exePath, DLL_NAME);

	// Load library in which we'll be hooking our functions.
	hookDllHandle = LoadLibrary(dllPath);

	if(hookDllHandle == NULL)
	{
		return false;
	}
 
	// Get the address of the function inside the DLL.
	installHookFunction = (installHook)GetProcAddress(hookDllHandle, INSTALL_FUNCTION);

	if(installHookFunction == NULL)
	{
		installHookFunction = (installHook)GetProcAddress(hookDllHandle, INSTALL_FUNCTION_ALT);

		if(installHookFunction == NULL)
		{
			return false;
		}
	}

	uninstallHookFunction = (uninstallHook)GetProcAddress(hookDllHandle, UNINSTALL_FUNCTION);

	if(uninstallHookFunction == NULL)
	{
		return false;
	}

	return true;
}
HRESULT CPluginManagerDLL::LoadConvertersFromFolder(CONST TCHAR* pchPluginFolder)
{
    TCHAR m_acEvalFilePath[MAX_PATH];
    CString strPluginPath;
    if(pchPluginFolder == NULL)
    {
        GetModuleFileName( NULL, m_acEvalFilePath, MAX_PATH );
        PathRemoveFileSpec(m_acEvalFilePath);
        strPluginPath = m_acEvalFilePath;
        strPluginPath += defDEFAULTPLUGINFOLDER;
    }
    else
    {
        strPluginPath = pchPluginFolder;
    }

    if(PathFileExists(strPluginPath) == TRUE)
    {
        SetCurrentDirectory(strPluginPath);

        CFileFind omFileFinder;
        CString strWildCard = defDLLFILEEXTENSION; //look for the plugin files

        BOOL bWorking = omFileFinder.FindFile(strWildCard);
        while (bWorking)
        {
            bWorking = omFileFinder.FindNextFile();
            if (omFileFinder.IsDots() || omFileFinder.IsDirectory())
            {
                continue;
            }
            LoadConverter(omFileFinder.GetFilePath());

        }
        return S_OK;
    }
    else
    {
        return S_FALSE;
    }
}
Example #26
0
// 检查文件MD5值
DWORD WINAPI CUpdaterApp::_CheckFileMD5(LPVOID lpParameter)
{
	LPUPDATEITEM pItem = (LPUPDATEITEM)lpParameter;
	TCHAR szFileName[MAX_PATH] = {0};
	GetModuleFileName(NULL, szFileName, MAX_PATH - 1);
	PathRemoveFileSpec(szFileName);
	PathAppend(szFileName, pItem->szFileName);
	
	HANDLE hFile = CreateFile(szFileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
	if (INVALID_HANDLE_VALUE != hFile)
	{
		HANDLE hMap = CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, 0, NULL);
		if (hMap)
		{
			DWORD dwSize = GetFileSize(hFile, NULL);
			LPVOID lpBuff = MapViewOfFile(hMap, FILE_MAP_READ, 0, 0, 0);
			MD5 md5(lpBuff, dwSize);
#if defined(_UNICODE) || defined(UNICODE)
			mbstowcs(pItem->szLocalMD5, md5.toString().c_str(), 32);
#else
			lstrcpyn(pItem->szLocalMD5, md5.toString().c_str(), 33);
#endif // defined(_UNICODE) || defined(UNICODE)
			if (lstrcmpi(pItem->szLocalMD5, pItem->szServerMD5))
			{
				pItem->bNeedUpdate = TRUE;
			}
			UnmapViewOfFile(lpBuff);
			CloseHandle(hMap);
		}
		CloseHandle(hFile);
	}
	else
	{
		if (!PathFileExists(szFileName))
		{
			// 文件不存在,标记更新!
			pItem->bNeedUpdate = TRUE;
		}
	}
	return 0;
}
Example #27
0
File: config.c Project: VCCE/VCC
int SelectFile(char *FileName)
{
	OPENFILENAME ofn ;	
	char Dummy[MAX_PATH]="";
	char TempFileName[MAX_PATH]="";

	memset(&ofn,0,sizeof(ofn));
	ofn.lStructSize       = sizeof (OPENFILENAME);
	ofn.hwndOwner         = EmuState.WindowHandle;
	ofn.Flags             = OFN_HIDEREADONLY;
	ofn.hInstance         = GetModuleHandle(0);
	ofn.lpstrDefExt       = "txt";
	ofn.lpstrFilter       =	"Text File\0*.txt\0\0";	
	ofn.nFilterIndex      = 0 ;					// current filter index
	ofn.lpstrFile         = TempFileName;		// contains full path and filename on return
	ofn.nMaxFile          = MAX_PATH;			// sizeof lpstrFile
	ofn.lpstrFileTitle    = NULL;				// filename and extension only
	ofn.nMaxFileTitle     = MAX_PATH;			// sizeof lpstrFileTitle
	ofn.lpstrInitialDir   = Dummy;				// initial directory
	ofn.lpstrTitle        = "Open print capture file";		// title bar string
	if (strlen(LastPrnPath) > 0)
	{
		ofn.lpstrInitialDir = LastPrnPath;
	}

	if (GetOpenFileName(&ofn))
	{
		// save last path
		strcpy(LastPrnPath, TempFileName);
		PathRemoveFileSpec(LastPrnPath);

		strcpy(FileName, TempFileName);

		if ( ! OpenPrintFile(TempFileName) )
		{
			MessageBox(0, "Can't Open File", "Can't open the file specified.", 0);
		}
	}
	
	return(1);
}
void CMyTreeView::AddItem(const TCHAR *szFullFileName)
{
	TCHAR			szDirectory[MAX_PATH];
	HTREEITEM		hParent;
	HTREEITEM		hDeskParent;

	/* If the specified item is a drive, it
	will need to be handled differently,
	as it is a child of my computer (and
	as such is not a regular file). */
	if(PathIsRoot(szFullFileName))
	{
		AddDrive(szFullFileName);
	}
	else
	{
		StringCchCopy(szDirectory, SIZEOF_ARRAY(szDirectory), szFullFileName);
		PathRemoveFileSpec(szDirectory);

		// Check if it is a desktop (sub)child
		hDeskParent = LocateItemOnDesktopTree(szDirectory);

		hParent = LocateExistingItem(szDirectory);

		/* If this items' parent isn't currently shown on the
		treeview and the item is not on the desktop, exit without
		doing anything further. */
		if(hParent == NULL && hDeskParent == NULL)
			return;

		AddItemInternal(hParent,szFullFileName);

		if(hDeskParent != NULL)
		{
			/* If the item is on the desktop, it is a special
			case. We need to update the treeview also starting
			from the root item. */
			AddItemInternal(hDeskParent,szFullFileName);
		}
	}
}
Example #29
0
void SlimItem::_FindPath(const CString& strPath)
{
    TCHAR szScanPath[MAX_PATH] = {0};
    HANDLE hFind = INVALID_HANDLE_VALUE;
    WIN32_FIND_DATA findData;

    wcscpy(szScanPath, strPath);

    PathRemoveFileSpec(szScanPath);

    hFind = ::FindFirstFile(strPath, &findData);

    if (hFind == INVALID_HANDLE_VALUE)
        goto Clear0;

    do 
    {
        if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)  
        {
            CString strFileName = findData.cFileName;
            if (strFileName.GetLength() >= 2 &&
                strFileName[0] == L'$' && 
                strFileName[strFileName.GetLength() - 1] == L'$')
            {
                CString strRealPath;
                strRealPath += szScanPath;
                strRealPath += L"\\";
                strRealPath += findData.cFileName;
                m_itemPaths.Add(strRealPath);
            }
        }
    } while (::FindNextFile(hFind, &findData));

Clear0:
    if (hFind != INVALID_HANDLE_VALUE)
    {
        FindClose(hFind);
        hFind = INVALID_HANDLE_VALUE;
    }
    return;
}
Example #30
0
//----------------------------------------------------------------------------
//
HRESULT CAnchoAddonService::FinalConstruct()
{
  // Get and store the path, this will be used in some places (e.g. to load
  // additional DLLs).
  LPTSTR psc = m_sThisPath.GetBuffer(_MAX_PATH);
  GetModuleFileName(_AtlModule.m_hInstance, psc, _MAX_PATH);
  PathRemoveFileSpec(psc);
  PathAddBackslash(psc);
  m_sThisPath.ReleaseBuffer();

  CComObject<CIECookieManager> * pCookiesManager = NULL;
  IF_FAILED_RET(CComObject<CIECookieManager>::CreateInstance(&pCookiesManager));
  pCookiesManager->setNotificationCallback(ACookieCallbackFunctor::APtr(new CookieNotificationCallback(*this)));
  pCookiesManager->startWatching();

  m_Cookies = pCookiesManager;

  IF_FAILED_RET(SimpleJSArray::createInstance(m_BrowserActionInfos));

  return S_OK;
}