int wmain(int argc, wchar_t* argv[]) { CommandLineArgs args; Application application; try { #if _DEBUG MessageBoxW(0, argv[1], 0, 0); #endif application.Initialize(); if (!args.ProcessCommandLine(argc, argv)) { args.WriteOutput(); return 0; } int result = 0; OpcUa_StatusCode uStatus = OpcUa_Good; if (args.StorePath.length() > 0) { OpcUa_Char* wszFilePath = 0; uStatus = OpcUa_StringToUnicode((OpcUa_StringA)args.StorePath.c_str(), &wszFilePath); if (OpcUa_IsBad(uStatus)) { args.OutputParameters["-error"] = "Could not access certificate store."; args.OutputParameters["-storePath"] = args.StorePath; args.WriteOutput(); return 0; } // create the store. result = _wmkdir((wchar_t*)wszFilePath); if (result != 0) { result = errno; } OpcUa_Free(wszFilePath); wszFilePath = 0; } if (result != 0 && result != EEXIST) { if (_strnicmp(args.StorePath.c_str(), "LocalMachine", strlen("LocalMachine")) != 0 && _strnicmp(args.StorePath.c_str(), "CurrentUser", strlen("CurrentUser")) != 0) { args.OutputParameters["-error"] = "Could not access certificate store."; args.OutputParameters["-storePath"] = args.StorePath; args.WriteOutput(); return 0; } } // create a new certificate. if (args.Command.empty() || args.Command == "issue") { application.Issue(args); args.WriteOutput(); return 0; } // revoke a certificate if (args.Command == "revoke" || args.Command == "unrevoke") { application.Revoke(args); args.WriteOutput(); return 0; } // convert a certificate if (args.Command == "convert" || args.Command == "install") { application.Convert(args); args.WriteOutput(); return 0; } // convert a replace if (args.Command == "replace") { application.Replace(args); args.WriteOutput(); return 0; } // create a certificate request. if (args.Command == "request") { application.CreateRequest(args); args.WriteOutput(); return 0; } // process a certificate request. if (args.Command == "process") { application.ProcessRequest(args); args.WriteOutput(); return 0; } args.OutputParameters["-error"] = "Unsupported command."; args.OutputParameters["-command"] = args.Command; args.WriteOutput(); } catch (StatusCodeException e) { args.OutputParameters["-error"] = e.GetMessage(); try { args.WriteOutput(); } catch (...) { // ignore. } } catch (...) { args.OutputParameters["-error"] = "Unhandled exception."; try { args.WriteOutput(); } catch (...) { // ignore. } } application.Uninitialize(); return 0; }
char *PakReader::extractFileIntoMemory(std::wstring fileName, std::string& filePath, std::wstring& destination, bool preservePath, unsigned long *fileSize) { if (fileSize == 0) { return 0; } HEADER_PAK_FILEINFO_LSPK *info = getHeaderForFileLspk(filePath); if (info != 0) { boost::filesystem::ifstream input(getFileNameByPakNumber(fileName, info->pakNumber).c_str(), std::ios_base::binary); long fileStart = dataOffsetToAbsolute(info->dataSectionOffset, info->pakNumber); input.seekg(fileStart); char *alloc = new char[info->fileSize]; input.read(alloc, info->fileSize); if (!input) { delete []alloc; input.close(); return 0; } long cwdSize = 1024; wchar_t cwd[cwdSize]; _wgetcwd(cwd, cwdSize); std::wstringstream ss; if (!preservePath) { long fileNameSize = strlen(info->fileName) + 1; std::wstring extractFileName; { wchar_t alloc[fileNameSize]; mbstowcs(alloc, info->fileName, fileNameSize); extractFileName = alloc; } long lastPathDelimiter = extractFileName.find_last_of(L'/'); if (lastPathDelimiter == std::string::npos) { ss<<destination<<(destination[destination.size() - 1] == L'/' ? L"" : L"/")<<extractFileName; } else { ss<<destination<<(destination[destination.size() - 1] == L'/' ? L"" : L"/")<<extractFileName.substr(lastPathDelimiter + 1); } } else { boost::char_separator<wchar_t> sep(L"\\/"); typedef boost::tokenizer<boost::char_separator<wchar_t> , std::wstring::const_iterator, std::wstring> PathTokenizer; long fileNameSize = strlen(info->fileName) + 1; std::wstring name; { wchar_t alloc[fileNameSize]; mbstowcs(alloc, info->fileName, fileNameSize); name = alloc; } PathTokenizer tok(name, sep); std::wstring lastToken = L""; _wchdir(destination.c_str()); ss<<destination<<(destination[destination.size() - 1] == '/' ? "" : "/"); for (PathTokenizer::iterator it = tok.begin(); it != tok.end(); ++it) { std::wstring token = *it; if (lastToken.length() != 0) { _wmkdir(lastToken.c_str()); _wchdir(lastToken.c_str()); ss<<lastToken<<L"/"; } lastToken = token; } ss<<lastToken; } lastExtractPath = ss.str(); if (info->decompressedSize > 0) { char *decompressionBuffer = new char[info->decompressedSize]; int result = compressor.decompress((char *)decompressionBuffer, (char *)alloc, info->fileSize, info->decompressedSize); if (result > 0) { *fileSize = info->decompressedSize; delete[] alloc; alloc = decompressionBuffer; } } else { *fileSize = info->fileSize; } input.close(); _wchdir(cwd); return alloc; } return 0; }
void Sys_Mkdir (const char* path) { WCHAR wpath[MAX_OSPATH]; Sys_Utf8ToUtf16(path, wpath, lengthof(wpath)); _wmkdir(wpath); }
bool FileSystem::ForceDirectories(const char* path, CString& errmsg) { errmsg.Clear(); BString<1024> normPath = path; NormalizePathSeparators(normPath); int len = strlen(normPath); if (len > 3 && normPath[len - 1] == PATH_SEPARATOR) { normPath[len - 1] = '\0'; } if (DirectoryExists(normPath)) { return true; } if (FileExists(normPath)) { errmsg.Format("path %s is not a directory", *normPath); return false; } if (strlen(normPath) > 2) { BString<1024> parentPath = *normPath; char* p = (char*)strrchr(parentPath, PATH_SEPARATOR); if (p) { if (p - parentPath == 2 && parentPath[1] == ':' && strlen(parentPath) > 2) { parentPath[3] = '\0'; } else { *p = '\0'; } if (strlen(parentPath) != strlen(path) && !ForceDirectories(parentPath, errmsg)) { return false; } } if (_wmkdir(UtfPathToWidePath(normPath)) != 0 && errno != EEXIST) { errmsg.Format("could not create directory %s: %s", *normPath, *GetLastErrorMessage()); return false; } if (DirectoryExists(normPath)) { return true; } if (FileExists(normPath)) { errmsg.Format("path %s is not a directory", *normPath); return false; } } return false; }
BOOL cupdatenetlib::downloadList(){ if ( !(_wmkdir(szUpdfilesPath) < 0 && errno == EEXIST) ){ SVP_LogMsg( _T("UPD dir not exist and writeable! ")); return 0; } resetCounter(); CString szBranch = svpToolBox.fileGetContent(szUpdfilesPath + _T("branch") ); if(szBranch.IsEmpty() ){ /* 如果 mtime 小于 stable 版本的 mtime 就更新 stable , 大于就更新 beta */ // struct __stat64 sbuf; CString szPlayerPath = svpToolBox.GetPlayerPath(_T("splayer.exe")); if(!svpToolBox.ifFileExist(szPlayerPath) ){ szPlayerPath = svpToolBox.GetPlayerPath(_T("mplayerc.exe")); if (!svpToolBox.ifFileExist(szPlayerPath)){ szPlayerPath = svpToolBox.GetPlayerPath(_T("svplayer.exe")); } } if(svpToolBox.ifFileExist(szPlayerPath) ){ CMD5Checksum cmd5; //szBranch.Format( _T("%I64d") , sbuf.st_mtime ); szBranch = cmd5.GetMD5((LPCTSTR)szPlayerPath).c_str(); //AfxMessageBox(szBranch); } else szBranch = _T("stable"); } WCHAR* wsz = this->svpToolBox.getTmpFileName(); CString szTmpFilename(wsz); delete wsz; CString szPostPerm; szPostPerm.Format(_T("ver=%s&branch=%s"), BRANCHVER, szBranch); int rret = 0; CString szLog; if (PostUsingCurl(szPostPerm, szTmpFilename)){ rret = 1; GetD3X9Dll(); //iSVPCU_TOTAL_FILE = 0; iSVPCU_TOTAL_FILEBYTE = 0; CString szData = svpToolBox.fileGetContent( szTmpFilename ) ; CStringArray szaLines; svpToolBox.Explode( szData, _T("\n") , &szaLines ); for(int i = 0; i < szaLines.GetCount(); i++){ if (szaLines.GetAt(i).IsEmpty()){break;} this->iSVPCU_TOTAL_FILE++; //szLog.Format(_T("Total Files need to download: %d"), iSVPCU_TOTAL_FILE); //SVP_LogMsg(szLog); CStringArray szaTmp; svpToolBox.Explode( szaLines.GetAt(i), _T(";") , &szaTmp ); if(szaTmp.GetCount() < LFILETOTALPARMS){ continue; } if (SkipThisFile(szaTmp.GetAt(LFILESETUPPATH), szaTmp.GetAt(LFILEACTION))) continue; //检查是否需要下载 CString szSetupPath = szaTmp.GetAt(LFILESETUPPATH); if (szSetupPath.CompareNoCase( _T("splayer.exe")) == 0){ if(!svpToolBox.ifFileExist(szBasePath + szSetupPath) ){ if (svpToolBox.ifFileExist(szBasePath + _T("mplayerc.exe"))) szSetupPath = _T("mplayerc.exe"); if (svpToolBox.ifFileExist(szBasePath + _T("svplayer.exe"))) szSetupPath = _T("svplayer.exe"); } } bool bDownloadThis = FALSE; //check file hash CMD5Checksum cmd5; CString updTmpHash ; CString currentHash ; if( svpToolBox.ifFileExist(szUpdfilesPath + szaTmp.GetAt(LFILETMPATH))) { updTmpHash = cmd5.GetMD5((LPCTSTR)(szUpdfilesPath + szaTmp.GetAt(LFILETMPATH))).c_str(); //Get Hash for current Temp File } if( svpToolBox.ifFileExist(szBasePath + szSetupPath ) ){ currentHash = cmd5.GetMD5((LPCTSTR)(szBasePath + szSetupPath)).c_str(); //Get Hash for bin file } if (currentHash.CompareNoCase( szaTmp.GetAt(LFILEHASH) ) == 0 ) continue; if ( updTmpHash.CompareNoCase( szaTmp.GetAt(LFILEHASH) ) != 0 ){ bDownloadThis = TRUE; } UpdateInfo* puinfo = new UpdateInfo; puinfo->bDownload = bDownloadThis; puinfo->dwDowloadedLength = _wtoi(szaTmp.GetAt(LFILEGZLEN)); puinfo->dwFileLength = _wtoi(szaTmp.GetAt(LFILELEN)); puinfo->strId = (szaTmp.GetAt(LFILEID)); puinfo->strAction = szaTmp.GetAt(LFILEACTION); puinfo->strDownloadfileMD5 = szaTmp.GetAt(LFILEGZHASH); puinfo->strFileMd5 = szaTmp.GetAt(LFILEHASH); puinfo->strPath = szaTmp.GetAt(LFILESETUPPATH); puinfo->strTempName = szaTmp.GetAt(LFILETMPATH); puinfo->strCurrentMD5 = currentHash; puinfo->bReadyToCopy = !bDownloadThis; m_UpdateFileArray.Add(puinfo); if(bDownloadThis){ iSVPCU_TOTAL_FILEBYTE += _wtoi(szaTmp.GetAt(LFILEGZLEN)); //szaTmp.SetSize(LFILETOTALPARMS); //szaLists.Append( szaTmp ); } } szLog.Format(_T("Total Files: %d ; Total Len %d"), iSVPCU_TOTAL_FILE, iSVPCU_TOTAL_FILEBYTE); SVP_LogMsg(szLog); } DeleteFile(szTmpFilename); return rret; }
int __cdecl My_mkdir( const char *_Path ) { return _wmkdir( FromUTF8( _Path ) ); }
int mkdir(const char *path) { return _wmkdir(nall::utf16_t(path)); }
int efile_mkdir(Efile_error* errInfo, /* Where to return error codes. */ char* name) /* Name of directory to create. */ { return check_error(_wmkdir((WCHAR *) name), errInfo); }
/** * path_mkdir: * @dir : directory * * Create directory on filesystem. * * Returns: true (1) if directory could be created, otherwise false (0). **/ bool path_mkdir(const char *dir) { /* Use heap. Real chance of stack overflow if we recurse too hard. */ const char *target = NULL; bool sret = false; bool norecurse = false; char *basedir = NULL; if (dir && *dir) basedir = strdup(dir); if (!basedir) return false; path_parent_dir(basedir); if (!*basedir || !strcmp(basedir, dir)) goto end; if (path_is_directory(basedir)) { target = dir; norecurse = true; } else { target = basedir; sret = path_mkdir(basedir); if (sret) { target = dir; norecurse = true; } } if (norecurse) { #if defined(_WIN32) #ifdef LEGACY_WIN32 int ret = _mkdir(dir); #else wchar_t *dirW = utf8_to_utf16_string_alloc(dir); int ret = -1; if (dirW) { ret = _wmkdir(dirW); free(dirW); } #endif #elif defined(IOS) int ret = mkdir(dir, 0755); #elif defined(VITA) || defined(PSP) int ret = sceIoMkdir(dir, 0777); #elif defined(__QNX__) int ret = mkdir(dir, 0777); #else int ret = mkdir(dir, 0750); #endif /* Don't treat this as an error. */ if (path_mkdir_error(ret) && path_is_directory(dir)) ret = 0; if (ret < 0) printf("mkdir(%s) error: %s.\n", dir, strerror(errno)); sret = (ret == 0); } end: if (target && !sret) printf("Failed to create directory: \"%s\".\n", target); free(basedir); return sret; }
int mkdir_( BBString *path,int mode ){ if( _bbusew ) return _wmkdir( bbTmpWString(path) ); return _mkdir( bbTmpCString(path) ); }