コード例 #1
0
bool TrimFilePathW(wstring& strPath)
{
    int pos = strPath.find_last_of(L'\\');
    if (wstring::npos == pos)
    {
        return false;
    }
    int count = strPath.size() - pos;
    strPath = strPath.substr(strPath.find_last_of(L'\\') + 1, count);
    return true;
}
コード例 #2
0
ファイル: system.cpp プロジェクト: AlloyTeam/webtop
//可同时处理目录和文件:path可以是路径,也可以是文件名,或者文件通配符
wstring find(wstring path,bool cursive)
{ 
     //取路径名最后一个"//"之前的部分,包括"//"
	replace_allW(path,L"\\",L"/");
	UINT index=path.find_last_of('/');
	if(index+1==path.length()){
		path.append(L"*.*");
	}
    wstring prefix=path.substr(0,path.find_last_of('/')+1);

    WIN32_FIND_DATA FindFileData;
    HANDLE hFind=::FindFirstFile(path.data(),&FindFileData);
	std::wstringstream ss;
    if(INVALID_HANDLE_VALUE == hFind)
    {
       ss<<L"[]";
	   FindClose(hFind);
	   return ss.str();
    }
	else{
		ss<<L"[";
	}
    while(TRUE)
    {
		bool flag=false;;
      //目录
        if(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
        {
            //不是当前目录,也不是父目录
            if(cursive&&FindFileData.cFileName[0]!='.')
            {
				wstring temp=prefix+FindFileData.cFileName;
				ss<<L"{\"name\":\""<<FindFileData.cFileName<<L"\",\"list\":"<<find(temp+L"/*.*",cursive).data()<<L"}";
				flag=true;
            }
        }
        //文件
        else
        {   
             ss<<L"\""<<FindFileData.cFileName<<L"\"";
			flag=true;
        }
        if(!FindNextFile(hFind,&FindFileData))
              break;
		else if(flag){
			ss<<L",";
		}
    }
	ss<<L"]";
    FindClose(hFind);
	return ss.str();
}
コード例 #3
0
bool CaffeineClientHandler::RenameOldFile(wstring filename)
{
    //  Determine if the file already exists.  We do this because of the fugly extension
    //  API we're using.
#ifdef __APPLE__
    return renameOldFile(filename);
#else
    bool retval = false;
    struct _stat buf = {0,};
    if(_wstat(filename.c_str(), &buf) == 0)
    {
        wstring fileExt = L"";

        unsigned index = filename.find_last_of('.');
        if (index != wstring::npos)
        {
            fileExt = filename.substr(index);
        }

        wstringstream newFileName;
        newFileName << filename.substr(0, index) << ".old" << fileExt;

        RenameOldFile(newFileName.str());
        _wrename(filename.c_str(), newFileName.str().c_str());
        retval = true;
    }

    return retval;
#endif

}
コード例 #4
0
DWORD
FileDownloader::Download(wstring what, wstring *toFile)
{
	DWORD dwStatus;
	BOOL folderCreated = FALSE;

	// Setup temp file paths etc 
	wstring tempFilePath = L"temp\\";
	//tempFilePath = *toFile;
	wchar_t* szTempPath = new wchar_t[1024];
	wchar_t* szTempFilePath = new wchar_t[1024];
	GetFullPathName(tempFilePath.c_str(), 1024, szTempFilePath, NULL);
	GetFullPathName(L"temp", 1024, szTempPath, NULL);
	tempFilePath = szTempFilePath;
	folderCreated = CreateDirectory(szTempPath, NULL);
	delete [] szTempPath;
	delete [] szTempFilePath;

	if(folderCreated == FALSE)
	{
		//printf("FileDownloader - ERROR - Could not create temp directory: %ls\n", tempPath.c_str());
		//return false;
	}
	tempFilePath += L"tempFile";
	
	wstring extension = what.substr(what.find_last_of(L"."));
	tempFilePath += extension;

	DeleteFile(tempFilePath.c_str());

	printf("Downloading to: %ls\n", tempFilePath.c_str());
	*toFile = tempFilePath;
	HRESULT result = URLDownloadToFile(NULL,
			what.c_str(),
			tempFilePath.c_str(),
			0,
			this
		);

	// Wait for connection signal
	dwStatus = WaitForSingleObject(hConnected, 30000);

	if(dwStatus == WAIT_TIMEOUT)
	{
		printf("FileDownloader - ERROR - Connection timeout\n");
		return CAPTURE_NE_CONNECT_ERROR_DL_TEMP_FILE;
	}
	printf("FileDownloader - Downloading file: %ls\n", what.c_str());

	// Wait for download to finish signal
	dwStatus = WaitForSingleObject(hDownloaded, 60000);
	if(dwStatus == WAIT_TIMEOUT)
	{
		printf("FileDownloader - ERROR - Download timeout\n");
		return CAPTURE_NE_CANT_DOWNLOAD_TEMP_FILE;
	}
	printf("FileDownloader - File Downloaded: %ls\n", what.c_str());
	return 0;
}
コード例 #5
0
ファイル: string.cpp プロジェクト: vjcagay/taiga
wstring GetFileWithoutExtension(wstring str) {
  size_t pos = str.find_last_of(L".");

  if (pos != wstring::npos)
    str.resize(pos);

  return str;
}
コード例 #6
0
bool GetAppNameW(wstring& strPath)
{
    TCHAR modulePath[MAX_PATH];
    if (0 == GetModuleFileNameW(NULL, modulePath, MAX_PATH))
    {
        DOLOG("Get Current Module Name Failed!");
        return false;
    }
    strPath = modulePath;
    int pos = strPath.find_last_of(L'\\');
    if (wstring::npos == pos)
    {
        return false;
    }
    int count = strPath.size() - pos;
    strPath = strPath.substr(strPath.find_last_of(L'\\')+1, count);
    return true;
}
コード例 #7
0
ファイル: system.cpp プロジェクト: AlloyTeam/webtop
wstring GetExtW(wstring path){
	int index=path.find_last_of('.');
	if(index==-1){
		return L"";
	}
	else{
		wstring type=path.substr(index+1);
		return replace_allW(type,L"jpg",L"jpeg");
	}
}
コード例 #8
0
wstring FileName(const wstring& sBinaryPath)
{
	size_t i = sBinaryPath.find_last_of(L"/\\");
	if(i != sBinaryPath.npos)
	{
		return sBinaryPath.substr(i + 1);
	}
	else
	{
		return sBinaryPath;
	}
}
コード例 #9
0
// 得到当前程序的路径
bool GetAppPathW(wstring& strPath)
{
    TCHAR modulePath[MAX_PATH];
    if (0 == GetModuleFileNameW(NULL, modulePath, MAX_PATH))
    {
        DOLOG("Get Current Module Name Failed!");
        return false;
    }
    strPath = modulePath;
    strPath  = strPath.substr(0, strPath.find_last_of(L'\\'));
    return true;
}
コード例 #10
0
ファイル: File.cpp プロジェクト: BorisJineman/CNTK
// determine the file name for a given pathname
// (wstring only for now; feel free to make this a template if needed)
/*static*/ wstring File::FileNameOf(wstring path)
{
#ifdef WIN32
    static const wstring delim = L"\\:/";
#else
    static const wstring delim = L"/";
#endif
    auto pos = path.find_last_of(delim);
    if (pos != path.npos)
        return path.substr(pos + 1);
    else // no directory path
        return path;
}
コード例 #11
0
PixelShader::PixelShader(wstring path)
{
    HRESULT result;

    auto shaderBuffer = Tools::ReadFileToVector(path);
    result = GetD3D11Device()->CreatePixelShader(&shaderBuffer[0], shaderBuffer.size(), nullptr, &m_Shader);
    Assert(result == S_OK);

    auto extensionIndex = path.find_last_of('.');
    auto metadataBuffer = Tools::ReadFileToVector(path.substr(0, extensionIndex + 1) + L"shadermetadata");

    Reflect(shaderBuffer, metadataBuffer);
}
コード例 #12
0
		Void Mesh::loadMesh(const wstring &sNewPath)
		{
			if(sNewPath.length() < 2u || sNewPath[1] != L':')
				return;

			BinaryReader sReader{sNewPath};

			if(!sReader.readerOpened())
				return;

			Char vSignature[8]
			{
				//Empty.
			};

			sReader.readCHAR(vSignature, 8u);
			
			if(vSignature[0] != 'P' ||
				vSignature[1] != 'H' ||
				vSignature[2] != 'S' ||
				vSignature[3] != '_' ||
				vSignature[4] != 'M' ||
				vSignature[5] != 'E' ||
				vSignature[6] != 'S' ||
				vSignature[7] != 'H')
				return;

			uInt nCount = sReader.readUINT();
			this->sMeshMaterialVector.reserve(nCount);

			const wstring sPath = sNewPath.substr(0u, sNewPath.find_last_of(L"\\/") + 1u);

			for(uInt nIndex = 0u ; nIndex < nCount ; ++nIndex)
			{
				this->sMeshMaterialVector.emplace_back(sReader, sPath);
				this->sMeshMaterialNameMap[this->sMeshMaterialVector.back().sMaterialName] = &this->sMeshMaterialVector.back();
			}

			nCount = sReader.readUINT();
			this->sMeshSubMeshVector.reserve(nCount);

			for(uInt nIndex = 0u ; nIndex < nCount ; ++nIndex)
			{
				this->sMeshSubMeshVector.emplace_back(sReader);
				auto iIndex = this->sMeshMaterialNameMap.find(this->sMeshSubMeshVector.back().sSubMeshMaterialName);
				
				if(iIndex != this->sMeshMaterialNameMap.end())
					this->sMeshSubMeshVector.back().pSubMeshMaterialPointer = iIndex->second;
			}
		}
コード例 #13
0
ファイル: tracing.cpp プロジェクト: YY583456235/vscsc
// Tracing routine
// Can throw HRESULT on invalid formats
void FunctionTracer::Trace(wstring file, int line, wstring functionName, wstring format, ...)
{
    if (m_traceEnabled)
    {
        wstring buffer;
        VPRINTF_VAR_PARAMS(buffer, format);
    
        size_t pos = file.find_last_of(L"\\");
        wstring fileName = (pos == file.npos)? file: file.substr(pos+1);

        // TODO - put here your own implementation of a tracing routine, if needed
        wprintf(L"[[%40s @ %10s:%4d]] %s\n", functionName.c_str(), fileName.c_str(), line, buffer.c_str());
    }
}
コード例 #14
0
VLDDexporter::CommandProcessor::CommandProcessor(const wstring &file){
	// open read //
	Reader.open(file, ios::in);

	// get path from the input file //
	wstring tmpstr = file.substr(0, 1+file.find_last_of('\\'));
	OutputFilePath = "";
	OutputFilePath.assign(tmpstr.begin(), tmpstr.end());


	// set default settings //
	OutputFile = DEFAULT_OUTPUTFILE;

}
コード例 #15
0
ファイル: File.cpp プロジェクト: BorisJineman/CNTK
// 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;
}
コード例 #16
0
wstring BasePath(const wstring& sBinaryPath)
{
	if(sBinaryPath.size() <= 3)
	{
		return sBinaryPath;
	}

	//_ASSERT(sBinaryPath[sBinaryPath.size() - 1] != L'\\');

	size_t i = sBinaryPath.find_last_of(L"/\\");
	if(i != sBinaryPath.npos)
	{
		return sBinaryPath.substr(0, i);
	}
	else
	{
		return L"";
	}
}
コード例 #17
0
ファイル: ConfigHelper.cpp プロジェクト: 1132520084/CNTK
void ConfigHelper::ExpandDotDotDot(wstring& featPath, const wstring& scpPath, wstring& scpDirCached)
{
    wstring delim = L"/\\";

    if (scpDirCached.empty())
    {
        scpDirCached = scpPath;
        wstring tail;
        auto pos = scpDirCached.find_last_of(delim);
        if (pos != wstring::npos)
        {
            tail = scpDirCached.substr(pos + 1);
            scpDirCached.resize(pos);
        }
        if (tail.empty()) // nothing was split off: no dir given, 'dir' contains the filename
            scpDirCached.swap(tail);
    }
    size_t pos = featPath.find(L"...");
    if (pos != featPath.npos)
        featPath = featPath.substr(0, pos) + scpDirCached + featPath.substr(pos + 3);
}
コード例 #18
0
ファイル: string.cpp プロジェクト: vjcagay/taiga
int InStrCharsRev(const wstring& str1, const wstring& str2, int pos) {
  size_t i = str1.find_last_of(str2, pos);
  return (i != wstring::npos) ? i : -1;
}
コード例 #19
0
void CFileInfo::DirtoryInfoExtraction(const wstring& wstrPath, list<MESHPATH*>& rPathInfolist)
{
	CFileFind		Find;
	Find.FindFile(wstrPath.c_str());

	int		iContinue = 1;
	while(iContinue)
	{
		iContinue = Find.FindNextFile();

		if(Find.IsDots())
			continue;

		if(Find.IsDirectory())
			DirtoryInfoExtraction(wstring(Find.GetFilePath() + L"\\*.*"), rPathInfolist);
		else
		{
			if(Find.IsSystem())
				continue;

			MESHPATH*   pFilePath = new MESHPATH;
			ZeroMemory(pFilePath, sizeof(MESHPATH));

			TCHAR   szPathBuf[MAX_PATH] = L"";
			lstrcpy(szPathBuf, wstrPath.c_str());														//szPathBuf = 0x0013dd98 "C:\Users\Administrator.JUSIN-20150429V\Desktop\Export\Bush\Bush1\*.*"
			PathRemoveFileSpec(szPathBuf);		    													// szPathBuf = 0x0013dd98 "C:\Users\Administrator.JUSIN-20150429V\Desktop\Export\Bush\Bush1\*.*"
		

			wstring      wstrFileName = szPathBuf;														//szPathBuf = 0x0013dd98 "C:\Users\Administrator.JUSIN-20150429V\Desktop\Export\Bush\Bush1"
			wstrFileName = PathFindFileName(wstrFileName.c_str());										//wstrFileName = "Bush1"
			pFilePath->wstrObjTag = wstrFileName.c_str();         									// pFilePath = 0x11c5ff50 {wstrFileName="Bush1" wstrFilePath="" wstrFullPath="" ...}

			// 파일 이름 다시 정한다.
			while(true)
			{
				wstrFileName = Find.GetFilePath().operator LPCWSTR();									//wstrFileName = "C:\Users\Administrator.JUSIN-20150429V\Desktop\Export\Bush\Bush1\Bush1.X"

				wstring      wstrFileTag = wstrFileName.substr( wstrPath.find_last_of(L"\\") + 1 );		//wstrFileTag = "Bush1.X"
				wstrFileTag = wstrFileTag.substr(wstrFileTag.length() - 2, wstrFileTag.length());		//wstrFileTag = ".X"
				if(wstrFileTag == L".X" ||
					wstrFileTag == L".x")      // 대 소문자 구분하니까, 구분해서 찾아주기
				{
					wstrFileName = wstrFileName.substr( wstrPath.find_last_of(L"\\") + 1 );				//wstrFileName = "Bush1.X"
					pFilePath->wstrFileTag = wstrFileName.c_str();      // 파일이름						//pFilePath->wstrType = "Bush1.X"
					break;
				}
				Find.FindNextFile();
			}
			//          wstrFileName = wstrFileName + L".X";
			//          lstrcpy(pFilePath->szFileTag, wstrFileName.c_str());      // 파일이름

			TCHAR   szBuf[MAX_PATH] = L"";
			lstrcpy(szBuf, (LPWSTR)Find.GetFilePath().operator LPCWSTR());								//szBuf = 0x0013db38 "C:\Users\Administrator.JUSIN-20150429V\Desktop\Export\Bush\Bush1\Bush1.X"
			PathRemoveFileSpec(szBuf);																	//szBuf = 0x0013db38 "C:\Users\Administrator.JUSIN-20150429V\Desktop\Export\Bush\Bush1"

			PathCombine(szBuf, szBuf, (LPWSTR)wstrFileName.c_str());									//szBuf = 0x0013db38 "C:\Users\Administrator.JUSIN-20150429V\Desktop\Export\Bush\Bush1\Bush1.X"
			PathRemoveFileSpec(szBuf);																	//szBuf = 0x0013db38 "C:\Users\Administrator.JUSIN-20150429V\Desktop\Export\Bush\Bush1"
			//PathRemoveFileSpec(szBuf);
			pFilePath->wstrFullPath = ConvertRelativePath(szBuf).c_str();								//pFilePath->wstrFullPath = "..\..\..\..\Export\Bush\Bush1"
			// 마지막 파일 이름 없애야 함

			PathRemoveFileSpec(szBuf);																	//szBuf = 0x0013db38 "C:\Users\Administrator.JUSIN-20150429V\Desktop\Export\Bush"
			pFilePath->wstrGroupTag = PathFindFileName(szBuf);											//pFilePath->wstrFilePath = "Bush"


			pFilePath->wstrFullPath += L"\\";      // 마지막에 하나 붙여주자							//pFilePath->wstrFullPath = "..\..\..\..\Export\Bush\Bush1\"
			rPathInfolist.push_back(pFilePath);															//pFilePath = 0x11c5ff50 {wstrFileName="Bush1" wstrFilePath="Bush" wstrFullPath="..\..\..\..\Export\Bush\Bush1\" ...}

			Find.FindFile(Find.GetFilePath());
			Find.FindNextFile();
		}
	}
}
コード例 #20
0
std::wstring RuleName::withoutChoiceIndex(const wchar_t * pszName) {
	const wstring name = std::wstring(pszName);
	return name.substr(0, name.find_last_of('_'));
}
コード例 #21
0
ファイル: Helpers.cpp プロジェクト: SunnyMeng/console
HICON Helpers::LoadTabIcon(bool bBigIcon, bool bUseDefaultIcon, const wstring& strIcon, const wstring& strShell)
{
  if (bUseDefaultIcon)
  {
    if ( !strShell.empty() )
    {
      wstring strCommandLine = Helpers::ExpandEnvironmentStrings(strShell);
      int argc = 0;
      std::unique_ptr<LPWSTR[], LocalFreeHelper> argv(::CommandLineToArgvW(strCommandLine.c_str(), &argc));

      if ( argv && argc > 0 )
      {
        SHFILEINFO info;
        memset(&info, 0, sizeof(info));
        if( ::SHGetFileInfo(
          argv[0],
          0,
          &info,
          sizeof(info),
          SHGFI_ICON | (( bBigIcon )? SHGFI_LARGEICON : SHGFI_SMALLICON)) != 0 )
        {
          return info.hIcon;
        }
      }
    }
  }
  else
  {
    if (!strIcon.empty())
    {
      int index = 0;

      // check strIcon ends with ,<integer>
      bool ok = false;

      size_t pos = strIcon.find_last_of(L',');
      if( pos != wstring::npos )
      {
        bool negative = false;
        size_t i = pos + 1;
        if( strIcon.at(i) == L'-' )
        {
          i ++;
          negative = true;
        }
        for(; i < strIcon.length(); ++i)
        {
          if( strIcon.at(i) >= L'0' && strIcon.at(i) <= L'9' )
          {
            ok = true;
            index = index * 10 + (strIcon.at(i) - L'0');
          }
          else
          {
            ok = false;
            break;
          }
        }
        if( negative )
          index = -index;
      }

      wstring strIconPath = ok ? strIcon.substr(0, pos) : strIcon;

      HICON hIcon = nullptr;

      if ( bBigIcon )
      {
        ::ExtractIconEx(
          Helpers::ExpandEnvironmentStrings(strIconPath).c_str(),
          index,
          &hIcon,
          nullptr,
          1);
      }
      else
      {
        ::ExtractIconEx(
          Helpers::ExpandEnvironmentStrings(strIconPath).c_str(),
          index,
          nullptr,
          &hIcon,
          1);
      }

      if( hIcon )
        return hIcon;
    }
  }

  if ( bBigIcon )
  {
    return static_cast<HICON>(
      ::LoadImage(
        ::GetModuleHandle(NULL),
        MAKEINTRESOURCE(IDR_MAINFRAME),
        IMAGE_ICON,
        0,
        0,
        LR_DEFAULTCOLOR | LR_DEFAULTSIZE));
  }
  else
  {
    return static_cast<HICON>(
      ::LoadImage(
        ::GetModuleHandle(NULL),
        MAKEINTRESOURCE(IDR_MAINFRAME),
        IMAGE_ICON,
        16,
        16,
        LR_DEFAULTCOLOR));
  }
}
コード例 #22
0
ファイル: string.cpp プロジェクト: vjcagay/taiga
wstring GetFileName(const wstring& str) {
  return str.substr(str.find_last_of(L"/\\") + 1);
}
コード例 #23
0
ファイル: string.cpp プロジェクト: vjcagay/taiga
wstring GetFileExtension(const wstring& str) {
  return str.substr(str.find_last_of(L".") + 1);
}
コード例 #24
0
void OIFReader::ReadTifSequence(wstring file_name, int t)
{
   size_t line_size = file_name.size();
   if (file_name.substr(line_size-3, 3) == L"tif")
   {
      //interpret file_name
      int64_t pos;
      int64_t pos_ = file_name.find_last_of(L'_');
      if (pos_!=-1)
      {
         size_t j;
         wstring wstr;
         int num_c = -1;
         int num_z = -1;
         int num_t = -1;
         int num_l = -1;

         //read channel number 'C'
         pos = file_name.find(L'C', pos_+1);
         if (pos!=-1)
         {
            for (j=pos+1; j<file_name.size(); j++)
            {
               if (iswdigit(file_name[j]))
                  wstr.push_back(file_name[j]);
               else
                  break;
            }
            num_c = WSTOI(wstr);
            wstr.clear();
         }
         //read z number 'Z'
         pos = file_name.find(L'Z', pos_+1);
         if (pos!=-1)
         {
            for (j=pos+1; j<file_name.size(); j++)
            {
               if (iswdigit(file_name[j]))
                  wstr.push_back(file_name[j]);
               else
                  break;
            }
            num_z = WSTOI(wstr);
            wstr.clear();
         }
         //read time number 'T'
         pos = file_name.find(L'T', pos_+1);
         if (pos!=-1)
         {
            for (j=pos+1; j<file_name.size(); j++)
            {
               if (iswdigit(file_name[j]))
                  wstr.push_back(file_name[j]);
               else
                  break;
            }
            num_t = WSTOI(wstr);
            wstr.clear();
         }
         //read lambda number 'L'
         pos = file_name.find(L'L', pos_+1);
         if (pos!=-1)
         {
            for (j=pos+1; j<file_name.size(); j++)
            {
               if (iswdigit(file_name[j]))
                  wstr.push_back(file_name[j]);
               else
                  break;
            }
            num_l = WSTOI(wstr);
            wstr.clear();
         }

         //add info to the list
         num_c = num_c==-1?0:num_c-1;
         num_t = num_t==-1?t:num_t-1;
         num_z = num_z==-1?1:num_z;
         if (num_z > 0)
         {
            num_z--;
            //allocate
            if (m_type == 0)
            {
               if (int(m_oif_info.size()) < num_t+1)
                  m_oif_info.resize(num_t+1);
               if (int(m_oif_info[num_t].dataset.size()) < num_c+1)
                  m_oif_info[num_t].dataset.resize(num_c+1);
               if (int(m_oif_info[num_t].dataset[num_c].size()) < num_z+1)
                  m_oif_info[num_t].dataset[num_c].resize(num_z+1);
               //add
               m_oif_info[num_t].dataset[num_c][num_z] = file_name;
            }
            else
            {
               //if (num_t == 0)
               {
                  if (int(m_oif_info[num_t].dataset.size()) < num_c+1)
                     m_oif_info[num_t].dataset.resize(num_c+1);
                  if (int(m_oif_info[num_t].dataset[num_c].size()) < num_z+1)
                     m_oif_info[num_t].dataset[num_c].resize(num_z+1);
                  //add
                  m_oif_info[num_t].dataset[num_c][num_z] = file_name;
               }
            }
         }
      }
   }
}
コード例 #25
0
bool
FileUploader::sendFile(wstring file)
{
	if(!server->isConnected())
	{
		printf("FileUploader: ERROR - Not connected to server so not sending file\n");
		return false;
	}

	busy = true;

	Attribute fileNameAttribute;
	Attribute fileSizeAttribute;
	Attribute fileTypeAttribute;
	fileName = file;
	errno_t error;
	

	/* Get the file size */
	if(!getFileSize(file, &fileSize))
	{
		busy = false;
		return false;
	}

	error = _wfopen_s( &pFileStream, file.c_str(), L"rb");
	if(error != 0)
	{
		printf("FileUploader: ERROR - Could not open file: %08x\n", error);
		busy = false;
		return false;
	} else {
		fileOpened = true;
	}
	
	queue<Attribute> atts;
	fileNameAttribute.name = L"name";
	fileNameAttribute.value = file;
	fileSizeAttribute.name = L"size";
	fileSizeAttribute.value = boost::lexical_cast<wstring>(fileSize.QuadPart);
	fileTypeAttribute.name = L"type";
	fileTypeAttribute.value = file.substr(file.find_last_of(L".")+1);
	atts.push(fileNameAttribute);
	atts.push(fileSizeAttribute);
	atts.push(fileTypeAttribute);
	
	/* Send request to server to accept a file */
	server->sendXML(L"file", &atts);

	/* Wait for the server to accept the file or timeout if it fails 
	   to respond or rejects it */
	
	DWORD timeout = WaitForSingleObject(hFileAcknowledged, 5000);

	if((timeout == WAIT_TIMEOUT) || !fileAccepted)
	{
		printf("FileUploader: ERROR - Server did not acknowledge the request to receive a file\n");
		busy = false;
		if(fileOpened)
		{
			fclose(pFileStream);
			fileOpened = false;
		}
		return false;	
	}	
 
	printf("FileUplodaer: Sending file: %ls\n", fileName.c_str());

	/* Loop sending the file inside <file-part /> xml messages */
	size_t offset = 0;	
	size_t bytesRead;
	do
	{
		bytesRead = sendFilePart((UINT)offset, 8192);
		offset += bytesRead;
	} while(bytesRead > 0);

	atts.push(fileNameAttribute);
	atts.push(fileSizeAttribute);

	server->sendXML(L"file-finished", &atts);

	fclose(pFileStream);
	fileOpened = false;
	busy = false;
	return true;
}
コード例 #26
0
ファイル: M2Packer.cpp プロジェクト: xmoeproject/X-moe
wstring GetFileExtension(wstring& FileName)
{
	wstring tmp = FileName.substr(FileName.find_last_of(L".") + 1, FileName.length());
	return tmp;
}
コード例 #27
0
ファイル: string.cpp プロジェクト: vjcagay/taiga
wstring GetPathOnly(const wstring& str) {
  return str.substr(0, str.find_last_of(L"/\\") + 1);
}
コード例 #28
0
ファイル: utils.cpp プロジェクト: leedehua/gramdisk
	wstring GetFileName(const wstring path){
		/* Treat '\\' and '/' as the separator */
		size_t found = path.find_last_of(L"/\\");
		/* return path name without '\\' or '/' */
		return path.substr(found + 1);
	}