Example #1
0
/*
#include <ctime>
#include <iostream>

struct FunctionTimer
{
	FunctionTimer(const char *f) : funcName(f), start(clock()) {
		std::cerr << "Entered " << funcName << std::endl;
		std::cerr.flush();
	}
	~FunctionTimer() {
		std::cerr << funcName << " finished at "
		          << (double(clock() - start) * 1000. / CLOCKS_PER_SEC) << " ms"
		          << std::endl;
		std::cerr.flush();
	}

	const char *funcName;
	clock_t start;
};
*/
void Library::collectBookFileNames(std::set<std::string> &bookFileNames, std::vector<shared_ptr<ZLInputStream> > &inputStreamCache) const {
	AppLog("Library::collectBookFileNames()");
//	FunctionTimer timer(__PRETTY_FUNCTION__);
	std::set<std::string> dirs;
	AppLog("collectDirNames");
	collectDirNames(dirs);

	while (!dirs.empty()) {
		std::string dirname = *dirs.begin();
		dirs.erase(dirs.begin());
		AppLog("dirname %s",dirname.c_str());
		ZLFile dirfile(dirname);
		std::vector<std::string> files;
		bool inZip = false;
		AppLog("dirfile.directory");
		shared_ptr<ZLDir> dir = dirfile.directory();
		if (dir.isNull()) {
			AppLog("dir.isNull");
			continue;
		}
		
		if (!dirfile.isDirectory())
			inputStreamCache.push_back(dirfile.inputStream());

		if (dirfile.extension() == "zip") {
			ZLFile phys(dirfile.physicalFilePath());
			if (!BooksDBUtil::checkInfo(phys)) {
				BooksDBUtil::resetZipInfo(phys);
				BooksDBUtil::saveInfo(phys);
			}
			BooksDBUtil::listZipEntries(dirfile, files);
			inZip = true;
		} else {
			dir->collectFiles(files, true);
		}
		//std::cerr.precision(5);
		if (!files.empty()) {
			const bool collectBookWithoutMetaInfo = CollectAllBooksOption.value();
			for (std::vector<std::string>::const_iterator jt = files.begin(); jt != files.end(); ++jt) {
				const std::string fileName = (inZip) ? (*jt) : (dir->itemPath(*jt));
				AppLog("fileName %s",fileName.c_str());
				ZLFile file(fileName);
//				std::cerr << "Check file \"" << fileName << "\" ... ";
//				std::cerr.flush();
//				clock_t start = clock();
				if (PluginCollection::Instance().plugin(file, !collectBookWithoutMetaInfo) != 0) {
					bookFileNames.insert(fileName);
				// TODO: zip -> any archive
				} else if (file.extension() == "zip") {
					if (myScanSubdirs || !inZip) {
						AppLog("myScanSubdirs fileName %s",fileName.c_str());
						dirs.insert(fileName);
					}
				}
//				std::cerr << (double(clock() - start) * 1000. / CLOCKS_PER_SEC) << " ms" << std::endl;
//				std::cerr.flush();
			}
		}
	}
}
Example #2
0
int
main(int argc, char *argv[])
{
  printf("*******usertests starting*******\n\n");

  printf("=====test file usertests.ran does not exists=====\n");

  if(open("usertests.ran", O_RDONLY) >= 0){
    printf("already ran user tests (file usertests.ran exists) -- recreate certikos_disk.img\n");
    exit();
  }
  printf("=====test file usertests.ran does not exists: ok\n\n");
  close(open("usertests.ran", O_CREATE));

  smallfile();
  bigfile1();
  createtest();

  rmdot();
  fourteen();
  bigfile2();
  subdir();
  linktest();
  unlinkread();
  dirfile();
  iref();
  bigdir(); // slow
  printf("*******end of tests*******\n");
}
    virtual wxDirTraverseResult OnDir(const wxString& dirname)
    {
        wxFileName dirfile(dirname);
        dirfile.MakeRelativeTo(m_basePath);
        if (dirfile.GetFullPath().Find(dirfile.GetPathSeparator()) == wxNOT_FOUND)
            m_files.push_back(dirname);

        return wxDIR_CONTINUE;
    }
Example #4
0
int
main(int argc, char *argv[])
{
  printf(1, "usertests starting\n");

  if(open("usertests.ran", 0) >= 0){
    printf(1, "already ran user tests -- rebuild fs.img\n");
    exit();
  }
  close(open("usertests.ran", O_CREATE));

  createdelete();
  linkunlink();
  concreate();
  fourfiles();
  sharedfd();

  bigargtest();
  bigwrite();
  bigargtest();
  bsstest();
  sbrktest();
  validatetest();

  opentest();
  writetest();
  writetest1();
  createtest();

  openiputtest();
  exitiputtest();
  iputtest();

  mem();
  pipe1();
  preempt();
  exitwait();

  rmdot();
  fourteen();
  bigfile();
  subdir();
  linktest();
  unlinkread();
  dirfile();
  iref();
  forktest();
  bigdir(); // slow
  exectest();

  exit();
}
Example #5
0
void Library::collectBookFileNames(std::set<std::string> &bookFileNames) const {
	std::set<std::string> dirs;
	collectDirNames(dirs);

	while (!dirs.empty()) {
		std::string dirname = *dirs.begin();
		dirs.erase(dirs.begin());
		
		ZLFile dirfile(dirname);
		std::vector<std::string> files;
		bool inZip = false;

		shared_ptr<ZLDir> dir = dirfile.directory();
		if (dir.isNull()) {
			continue;
		}

		if (dirfile.extension() == "zip") {
			ZLFile phys(dirfile.physicalFilePath());
			if (!BooksDBUtil::checkInfo(phys)) {
				BooksDBUtil::resetZipInfo(phys);
				BooksDBUtil::saveInfo(phys);
			}
			BooksDBUtil::listZipEntries(dirfile, files);
			inZip = true;
		} else {
			dir->collectFiles(files, true);
		}
		if (!files.empty()) {
			const bool collectBookWithoutMetaInfo = CollectAllBooksOption.value();
			for (std::vector<std::string>::const_iterator jt = files.begin(); jt != files.end(); ++jt) {
				const std::string fileName = (inZip) ? (*jt) : (dir->itemPath(*jt));
				ZLFile file(fileName);
				if (PluginCollection::Instance().plugin(file, !collectBookWithoutMetaInfo) != 0) {
					bookFileNames.insert(fileName);
				// TODO: zip -> any archive
				} else if (file.extension() == "zip") {
					if (myScanSubdirs || !inZip) {
						dirs.insert(fileName);
					}
				}
			}
		}
	}
}
Example #6
0
void Gource::findUserImages() {
    if(!gGourceUserImageDir.size()) return;

#ifdef _WIN32
    HANDLE          hList;
    char            szDir[MAX_PATH+1];
    WIN32_FIND_DATAA FileData;

    // Get the proper directory path
    sprintf(szDir, "%s\\*", gGourceUserImageDir.c_str());

    // Get the first file
    hList = FindFirstFileA(szDir, &FileData);
    if (hList == INVALID_HANDLE_VALUE)
    { 
        debugLog("No files found\n\n");
        return;
    }
    else
    {
        // Traverse through the directory structure
        for (;;)
        {
            // Check the object is a directory or not
            if ((FileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0)
            {
                std::string dirfile(FileData.cFileName);

                size_t extpos = 0;

                if ((extpos=dirfile.rfind(".jpg"))  != std::string::npos ||
                    (extpos=dirfile.rfind(".jpeg")) != std::string::npos ||
                    (extpos=dirfile.rfind(".png"))  != std::string::npos)
                {
                    std::string image_path = gGourceUserImageDir + dirfile;
                    std::string name       = dirfile.substr(0,extpos);

                    debugLog("%s => %s\n", name.c_str(), image_path.c_str());

                    gGourceUserImageMap[name] = image_path;
                }
            }

            // get the next file
            if (!FindNextFileA(hList, &FileData))
            {
                if (GetLastError() == ERROR_NO_MORE_FILES)
                {
                    break;
                }
            }
        }
    }

    FindClose(hList);
#else
    //get jpg and png images in dir
    DIR *dp;
    struct dirent *dirp;

    if((dp = opendir(gGourceUserImageDir.c_str())) == 0) return;

    while ((dirp = readdir(dp)) != 0) {
        std::string dirfile = std::string(dirp->d_name);

        int extpos = 0;

        if(   (extpos=dirfile.rfind(".jpg"))  == std::string::npos
           && (extpos=dirfile.rfind(".jpeg")) == std::string::npos
           && (extpos=dirfile.rfind(".png"))  == std::string::npos) continue;


        std::string image_path = gGourceUserImageDir + dirfile;
        std::string name       = dirfile.substr(0,extpos);

        debugLog("%s => %s\n", name.c_str(), image_path.c_str());

        gGourceUserImageMap[name] = image_path;
    }

    closedir(dp);
#endif
}