int main (int argc, char * argv[]) { #ifdef ARCH_PB directory = argv[0]; size_t find; find = directory.find_last_of("/\\"); directory = directory.substr(0,find); chdir(directory.c_str()); int fd1 = open("log1.txt",O_CREAT|0666); dup2(fd1, 1); int fd2 = open("log2.txt",O_CREAT|0666); dup2(fd2, 2); #endif Logger logger; logger.WriteLog("Hello, pocketbook"); #ifdef ARCH_PB close(fd1); close(fd2); #endif InkViewMain(mainHandler); return 0; }
void APIHijack::WriteLog(void *drcontext, const char *szLog) { Logger *logger = (Logger *) drmgr_get_cls_field(drcontext, tlsIdx); if (logger == NULL) return; logger->WriteLog(szLog); }
DeckInfoList IDeck::getDeckList(std::string directory) { DeckInfoList decks; Logger logger; logger.WriteLog("current dir = " + directory); if (directory.length()==0) { directory="./decks/"; } // decks.push_back(DeckInfo("test1")); // decks.push_back(DeckInfo("test2")); // decks.push_back(DeckInfo("test3")); #if defined(ARCH_PB) || defined(ARCH_PBEMU) || defined(ARCH_LINUX) //linux-specific directory listing struct dirent **filelist; std::string temps; int n; n=scandir(directory.c_str(),&filelist,0,alphasort); if (n<0) { std::cerr<<"no decks found"<<std::endl; //should we exit here? } else { for (int ii=0;ii<n;ii++) { temps=filelist[ii]->d_name; free (filelist[ii]); if (temps.find(".anki")!=std::string::npos) { std::cout<<"loading "<<temps<<std::endl; decks.push_back(DeckInfo(temps)); } } free(filelist); // std::cout<<n<<" decks loaded"<<std::endl; } #else //std::wstring strPattern = L"./decks/*.anki"; //будь я проклят! std::string searchPattern=directory+"*.anki"; std::wstring wSearchPattern(searchPattern.length(), ' '); std::copy(searchPattern.begin(), searchPattern.end(), wSearchPattern.begin()); logger.WriteLog("search path = " + searchPattern +"\n"); HANDLE hFile; // Handle to file WIN32_FIND_DATA FileInformation; // File information hFile = ::FindFirstFile(wSearchPattern.c_str(), &FileInformation); if(hFile != INVALID_HANDLE_VALUE) { do { if(FileInformation.cFileName[0] != '.') { if(FileInformation.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { } else { std::wstring strFilePathW = (FileInformation.cFileName); ///std::string strFilePath( strFilePathW.begin(), strFilePathW.end() ); //ох ад! а кстати с кириллией не работает! std::string strFilePath; FormatHelper::wstrToUtf8(strFilePath,strFilePathW); //а так работает! //std::cout<<strFilePath<<std::endl; logger.WriteLog(" f: "+strFilePath+"\n"); decks.push_back(DeckInfo(strFilePath)); } } } while(::FindNextFile(hFile, &FileInformation) == TRUE); } else { logger.WriteLog("could not find decks"); } #endif return decks; }