Exemplo n.º 1
0
void Platform::FindFileInDir(tWStringList &alstStrings,tWString asDir, tWString asMask)
{
    //Log("Find Files in '%ls' with mask '%ls'\n",asDir.c_str(), asMask.c_str());
    //Get the search string
    wchar_t sSpec[256];
    wchar_t end = asDir[asDir.size()-1];
    //The needed structs
    DIR *dirhandle;
    dirent *_entry;
    struct stat statbuff;
    tWString fileentry;

    if ((dirhandle = opendir(cString::To8Char(asDir).c_str()))==NULL) return;

    while ((_entry = readdir(dirhandle)) != NULL)
        {
            if (end==_W('/'))
                swprintf(sSpec,256,_W("%ls%s"),asDir.c_str(),_entry->d_name);
            else
                swprintf(sSpec,256,_W("%ls/%s"),asDir.c_str(),_entry->d_name);

            // skip unreadable
            if (stat(cString::To8Char(sSpec).c_str(),&statbuff) ==-1) continue;
            // skip directories
            if (S_ISDIR(statbuff.st_mode)) continue;

            fileentry.assign(cString::To16Char(_entry->d_name));

            if (!patiMatch(asMask.c_str(),fileentry.c_str())) continue;
            alstStrings.push_back(fileentry);
        }
    closedir(dirhandle);
}
Exemplo n.º 2
0
	bool CloneFile(const tWString& asSrcFileName,const tWString& asDestFileName,
		bool abFailIfExists)
	{
	#ifdef WIN32
		return CopyFile(asSrcFileName.c_str(),asDestFileName.c_str(),abFailIfExists)==TRUE;
	#else
		if (abFailIfExists && FileExists(asDestFileName)) {
			return true;
		} 
		std::ifstream IN (cString::To8Char(asSrcFileName).c_str(), std::ios::binary);
		std::ofstream OUT (cString::To8Char(asDestFileName).c_str(), std::ios::binary);
		OUT << IN.rdbuf();
		OUT.flush();
		return true;
	#endif
	}
Exemplo n.º 3
0
	bool HasWindowFocus(const tWString &asWindowCaption)
	{
		#ifdef WIN32
			HWND pWindowHandle = FindWindow(NULL, asWindowCaption.c_str());
			return (pWindowHandle == GetFocus());
		#endif
		return true;
	}
Exemplo n.º 4
0
	bool CreateFolder(const tWString& asPath)
	{
	#ifdef WIN32
		return CreateDirectory(asPath.c_str(),NULL)==TRUE;
	#else 
		return mkdir(cString::To8Char(asPath).c_str(),0755)==0;
	#endif
	}
Exemplo n.º 5
0
	void RemoveFile(const tWString& asFilePath)
	{
	#ifdef WIN32
		_wremove(asFilePath.c_str());
	#else
		remove(cString::To8Char(asFilePath).c_str());
	#endif
	}
Exemplo n.º 6
0
	bool FolderExists(const tWString& asPath)
	{
	#ifdef WIN32
		return GetFileAttributes(asPath.c_str())==FILE_ATTRIBUTE_DIRECTORY;
	#else
		struct stat statbuf;
		return (stat(cString::To8Char(asPath).c_str(), &statbuf) != -1);
	#endif
	}
Exemplo n.º 7
0
    void OpenBrowserWindow ( const tWString& asURL )
	{
		#ifdef WIN32
		ShellExecute ( NULL, _W("open"), asURL.c_str(), NULL, NULL, SW_SHOWNORMAL );
		#elif defined(__linux__)
		tString asTemp = "./openurl.sh "+cString::To8Char(asURL);
		system(asTemp.c_str());
		#elif defined(__APPLE__)
		tString asTemp = "open "+cString::To8Char(asURL);
		system(asTemp.c_str());
		#endif
	}
Exemplo n.º 8
0
	void CopyTextToClipboard(const tWString &asText)
	{
#ifdef WIN32
		OpenClipboard(NULL);
		EmptyClipboard();

		HGLOBAL clipbuffer;
		wchar_t * pBuffer;
		EmptyClipboard();
		clipbuffer = GlobalAlloc(GMEM_DDESHARE, (asText.size()+1) *sizeof(wchar_t));
		pBuffer = (wchar_t*)GlobalLock(clipbuffer);
		wcscpy(pBuffer, asText.c_str());
		//GlobalUnlock(clipbuffer);

		SetClipboardData(CF_UNICODETEXT, clipbuffer);

		GlobalUnlock(clipbuffer); 
		
		CloseClipboard();
#endif
	}
Exemplo n.º 9
0
	bool FileExists(const tWString& asFileName)
	{
	#ifdef WIN32
		FILE *f = _wfopen(asFileName.c_str(),_W("r"));
	#else
		FILE *f = fopen(cString::To8Char(asFileName).c_str(),"r");
	#endif
		if(f==NULL)
		{
			return false;
		}

		fclose(f);
		return true;
	}
Exemplo n.º 10
0
	cDate FileCreationDate(const tWString& asFilePath)
	{
		struct tm* pClock;
	#ifdef WIN32
		struct _stat attrib;
		_wstat(asFilePath.c_str(), &attrib);
	#else
		struct stat attrib;
		stat(cString::To8Char(asFilePath).c_str(), &attrib);
	#endif

		pClock = gmtime(&(attrib.st_ctime));	// Get the last modified time and put it into the time structure

		cDate date = DateFromGMTIme(pClock);

		return date;
	}