Ejemplo n.º 1
0
static bool maybeAddDirectory(const std::string& newPath, Array<Directory>& directoryArray, bool recurse = true) {
    if (fileExists(newPath)) {
        Directory& d = directoryArray.next();
        d.path = newPath;
        getFiles(pathConcat(newPath, "*"), d.contents);
        Array<std::string> dirs;
        getDirs(pathConcat(newPath, "*"), dirs);
        d.contents.append(dirs);

        if (recurse) {
            // Look for subdirectories
            static const std::string subdirs[] = 
            {"font", "gui", "SuperShader", "cubemap", "icon", "material", "image", "md2", "md3", "ifs", "3ds", "sky", ""};

            for (int j = 0; j < dirs.size(); ++j) {
                for (int i = 0; ! subdirs[i].empty(); ++i) {
                    if (dirs[j] == subdirs[i]) {
                        maybeAddDirectory(pathConcat(newPath, dirs[j]), directoryArray, false);
                    }
                }
            }
        }
        return true;
    } else {
        return false;
    }
}
Ejemplo n.º 2
0
YipDirectory::YipDirectory(const std::string & prjPath, const Project * project)
	: m_Path(pathConcat(prjPath, ".yip")),
	  m_Project(project)
{
	pathCreate(m_Path);
	m_Path = pathMakeCanonical(m_Path);

	m_DB = std::make_shared<SQLiteDatabase>(pathConcat(m_Path, "db"));
	initDB();
}
Ejemplo n.º 3
0
void CppInliner::inlineCode(const vector<string>& cppFilePaths, const string& outputFilePath) const {
    const string concatStage{pathConcat(temporaryDirectory, "concat.cpp")};
    const string inlinedStage{pathConcat(temporaryDirectory, "inlined.cpp")};

    concatFiles(cppFilePaths, concatStage);

    internal::Inliner inliner{clangCompilationOptions};
    std::string inlinedCode{inliner.doInline(concatStage)};
    removePragmaOnce(inlinedCode, inlinedStage);

    internal::Optimizer optimizer{clangCompilationOptions, macrosToKeep};
    std::string onlyReachableCode{optimizer.doOptimize(inlinedStage)};
    removeEmptyLines(onlyReachableCode, maxConsequentEmptyLines, outputFilePath);
}
Ejemplo n.º 4
0
bool YipDirectory::shouldProcessFile(const std::string & path, const std::string & sourcePath,
	bool rebuildIfProjectFileChanged)
{
	std::string targetFile = pathSimplify(pathConcat(m_Path, path));

	// Always process input file if output file does not exist
	if (!pathIsExistent(targetFile))
		return true;

	// There is no good way to handle non-existence of the input file. Leave it to the caller.
	if (!pathIsExistent(sourcePath))
		return true;

	// Canonicalize output file path
	targetFile = pathMakeCanonical(targetFile);

	// Get information about file from the database
	bool found = false;
	time_t old_time = 0;
	m_DB->select("SELECT time FROM files WHERE path = ? LIMIT 1", { targetFile },
		[&found, &old_time](const SQLiteCursor & cursor) {
			found = true;
			old_time = cursor.toTimeT(0);
		}
	);

	// This file was never built. Build it now.
	if (!found)
		return true;

	// Check whether file has been modified since last build.
	time_t modificationTime = pathGetModificationTime(sourcePath);
	if (modificationTime > old_time)
		return true;

	// Also rebuild the file if Yipfile has been modified since last build
	if (rebuildIfProjectFileChanged &&
			m_Project->hasModificationTime() && m_Project->modificationTime() > old_time)
		return true;

	return false;
}
Ejemplo n.º 5
0
void IconSet::findImages(const String& baseDir, const String& sourceDir, Array<Source>& sourceArray) {
    Array<String> filenameArray;
    FileSystem::getFiles(pathConcat(pathConcat(baseDir, sourceDir), "*"), filenameArray);
    for (int i = 0; i < filenameArray.size(); ++i) {
        if (Image::fileSupported(filenameArray[i])) {
            String f = pathConcat(sourceDir, filenameArray[i]);
            shared_ptr<Image> im = Image::fromFile(pathConcat(baseDir, f));
            Source& s = sourceArray.next();
            s.filename = f;
            s.width    = im->width();
            s.height   = im->height();
            // todo (Image upgrade): find replacement calculation for channels
            //s.channels = im.channels;
        }
    }

    Array<String> dirArray;
    FileSystem::getDirectories(pathConcat(pathConcat(baseDir, sourceDir), "*"), dirArray);
    for (int i = 0; i < dirArray.size(); ++i) {
        if (dirArray[i] != ".svn" && dirArray[i] != "CVS") {
            findImages(baseDir, pathConcat(sourceDir, dirArray[i]), sourceArray);
        }
    }
}
Ejemplo n.º 6
0
std::string System::findDataFile
(const std::string&  full,
 bool                errorIfNotFound) {

    // Places where specific files were most recently found.  This is
    // used to cache seeking of common files.
    static Table<std::string, std::string> lastFound;

    // First check if the file exists as requested.  This will go
    // through the FileSystemCache, so most calls do not touch disk.
    if (FileSystem::exists(full)) {
        return full;
    }

    // Now check where we previously found this file.
    std::string* last = lastFound.getPointer(full);
    if (last != NULL) {
        if (FileSystem::exists(*last)) {
            // Even if cwd has changed the file is still present.
            // We won't notice if it has been deleted, however.
            return *last;
        } else {
            // Remove this from the cache it is invalid
            lastFound.remove(full);
        }
    }

    // Places to look
    static Array<std::string> directoryArray;

    std::string initialAppDataDir(instance().m_appDataDir);
    const char* g3dPath = getenv("G3DDATA");

    if (directoryArray.size() == 0) {
        // Initialize the directory array
        RealTime t0 = System::time();

        Array<std::string> baseDirArray;
        
        baseDirArray.append("");
        if (! initialAppDataDir.empty()) {
            baseDirArray.append(initialAppDataDir);
        }

#       ifdef G3D_WIN32
        if (g3dPath == NULL) {
            // If running the demos under visual studio from the G3D.sln file,
            // this will locate the data directory.
            const char* paths[] = {"../data-files/", "../../data-files/", "../../../data-files/", NULL};
            for (int i = 0; paths[i]; ++i) {
                if (FileSystem::exists(pathConcat(paths[i], "G3D-DATA-README.TXT"))) {
                    g3dPath = paths[i];
                    break;
                }
            }
        }
#       endif

        if (g3dPath && (initialAppDataDir != g3dPath)) {
            baseDirArray.append(g3dPath);
        }

        static const std::string subdirs[] = 
            {"font", "gui", "SuperShader", "cubemap", "icon", "material", "image", "md2", "md3", "ifs", "3ds", "sky", ""};
        for (int j = 0; j < baseDirArray.size(); ++j) {
            std::string d = baseDirArray[j];
            if ((d == "") || FileSystem::exists(d)) {
                directoryArray.append(d);
                for (int i = 0; ! subdirs[i].empty(); ++i) {
                    const std::string& p = pathConcat(d, subdirs[i]);
                    if (FileSystem::exists(p)) {
                        directoryArray.append(p);
                    }
                }
            }
        }

        logLazyPrintf("Initializing System::findDataFile took %fs\n", System::time() - t0);
    }

    for (int i = 0; i < directoryArray.size(); ++i) {
        const std::string& p = pathConcat(directoryArray[i], full);
        if (FileSystem::exists(p)) {
            lastFound.set(full, p);
            return p;
        }
    }

    if (errorIfNotFound) {
        // Generate an error message
        std::string locations;
        for (int i = 0; i < directoryArray.size(); ++i) {
            locations += "\'" + pathConcat(directoryArray[i], full) + "'\n";
        }

        std::string msg = "Could not find '" + full + "'.\n\n";
        msg += "cwd = \'" + FileSystem::currentDirectory() + "\'\n";
        if (g3dPath) {
            msg += "G3DDATA = ";
            if (! FileSystem::exists(g3dPath)) {
                msg += "(illegal path!) ";
            }
            msg += std::string(g3dPath) + "\'\n";
        } else {
            msg += "(G3DDATA environment variable is undefined)\n";
        }
        msg += "GApp::Settings.dataDir = ";
        if (! FileSystem::exists(initialAppDataDir)) {
            msg += "(illegal path!) ";
        }
        msg += std::string(initialAppDataDir) + "\'\n";

        msg += "\nLocations searched:\n" + locations;

        alwaysAssertM(false, msg);
    }

    // Not found
    return "";
}
Ejemplo n.º 7
0
std::string System::findDataFile
(const std::string&  full,
 bool                errorIfNotFound) {

    // Places where specific files were most recently found.  This is
    // used to cache seeking of common files.
    static Table<std::string, std::string> lastFound;

    // First check if the file exists as requested.  This will go
    // through the FileSystemCache, so most calls do not touch disk.
    if (fileExists(full)) {
        return full;
    }

    // Now check where we previously found this file.
    std::string* last = lastFound.getPointer(full);
    if (last != NULL) {
        if (fileExists(*last)) {
            // Even if cwd has changed the file is still present.
            // We won't notice if it has been deleted, however.
            return *last;
        } else {
            // Remove this from the cache it is invalid
            lastFound.remove(full);
        }
    }

    // Places to look
    static Array<std::string> directoryArray;

    if (directoryArray.size() == 0) {
        // Initialize the directory array
        RealTime t0 = System::time();

        Array<std::string> baseDirArray;

        std::string initialAppDataDir(instance().m_appDataDir);
        
        baseDirArray.append("");
        if (! initialAppDataDir.empty()) {
            baseDirArray.append(initialAppDataDir);
        }

        const char* g3dPath = getenv("G3DDATA");

        if (g3dPath && (initialAppDataDir != g3dPath)) {
            baseDirArray.append(g3dPath);
        }

        static const std::string subdirs[] = 
            {"font", "gui", "SuperShader", "cubemap", "icon", "material", "image", "md2", "md3", "ifs", "3ds", "sky", ""};
        for (int j = 0; j < baseDirArray.size(); ++j) {
            std::string d = baseDirArray[j];
            if (fileExists(d)) {
                directoryArray.append(d);
                for (int i = 0; ! subdirs[i].empty(); ++i) {
                    const std::string& p = pathConcat(d, subdirs[i]);
                    if (fileExists(p)) {
                        directoryArray.append(p);
                    }
                }
            }
        }

        logLazyPrintf("Initializing System::findDataFile took %fs\n", System::time() - t0);
    }

    for (int i = 0; i < directoryArray.size(); ++i) {
        const std::string& p = pathConcat(directoryArray[i], full);
        if (fileExists(p)) {
            lastFound.set(full, p);
            return p;
        }
    }

    if (errorIfNotFound) {
        // Generate an error message
        std::string locations;
        for (int i = 0; i < directoryArray.size(); ++i) {
            locations += pathConcat(directoryArray[i], full) + "\n";
        }
        alwaysAssertM(false, "Could not find '" + full + "' in:\n" + locations);
    }

    // Not found
    return "";
}
Ejemplo n.º 8
0
void StegoModel::openDirectory(const char* path) {
  int i, j, k;
  int num_sets = 0;
  int bin;
  char *str = (char*) malloc(512*sizeof(char));
  DIR *root = opendir(path);
  FILE *file;
  featureHeader header;
  struct dirent *entry;
  
  if (root == NULL) {
//     printf("root is NULL \n");
    return;
  }
//   printf("Root not NULL. \n");
  while ((entry = readdir(root)) != NULL) {
    if (strstr(entry->d_name, ".fv") != NULL) {
      num_sets++;
    }
  }
//   printf("about to open dir with %i feature files \n", num_sets);
  rewinddir(root);
  for(i = 0; i < num_sets; ) {
    entry = readdir(root);
    if (strstr(entry->d_name, ".fv") != NULL) {
      pathConcat(path, entry->d_name, str);
      openFile(str, i, num_sets, header);
//       file = fopen(str, "r");
//       readHeader(file, &header);
//       if (ranges == 0) {
// 	printf("first file is being added! \n");
// 	ranges = (int**) malloc(3*sizeof(int*));
// 	for (k = 0; k < 3; k++) {
// 	  ranges[k] = (int*) malloc(num_coefs[k]*sizeof(int));
// 	  for (j = 0; j < num_coefs[k]; j++)
// 	    ranges[k][j] = header.ranges[k][j];
// 	}
//       }
//       fclose(file);
// 
// //      printf("method: %i \n", header.method);
// //       printf("qp range: %i \n", header.qp_range);
//       if (header.method == 0) {
// 	if (cleanSet == 0) {
// 	  cleanSet = openFeatureSet(str, steg);
// 	} else {
// // 	  printf("adding new feature file to clean set \n");
// 	  newFeatureFile(steg, cleanSet, str);
// 	}
//       } else {
// 	if (collections[pair<int, int>(header.method,header.accept)] == 0) {
// 	  collections[pair<int, int>(header.method,header.accept)] = new FeatureCollection(&header);
// 	  printf("Created new collection for method %i and accept %i \n", header.method, header.accept);
// 	}
//         collections[pair<int, int>(header.method, header.accept)]->addFeatureFile(str, &header, steg, cleanSet);
//       }
//       i++;
//       progressChanged((double) i / (double) num_sets);
    }
  }
  collectionChanged();

  closedir(root);
  free(str);
}
Ejemplo n.º 9
0
std::string YipDirectory::getGitRepositoryPath(const std::string & url)
{
	return pathConcat(m_Path, "git-" + sha1(url).substr(1, 10));
}
Ejemplo n.º 10
0
std::string YipDirectory::writeFile(const std::string & path, const std::string & data, bool * changed)
{
	std::string file = pathSimplify(pathConcat(m_Path, path));
	bool has_sha1 = false, write = true;
	std::string new_sha1;

	SQLiteTransaction transaction(m_DB);

	// Check whether file has changed
	if (pathIsExistent(file))
	{
		// Canonicalize file path
		file = pathMakeCanonical(file);

		// Get information about file from the database
		bool found = false;
		size_t old_size = 0;
		time_t old_time = 0;
		std::string old_sha1;
		m_DB->select("SELECT size, time, sha1 FROM files WHERE path = ? LIMIT 1", { file },
			[&found, &old_size, &old_time, &old_sha1](const SQLiteCursor & cursor) {
				found = true;
				old_size = cursor.toSizeT(0);
				old_time = cursor.toTimeT(1);
				old_sha1 = cursor.toString(2);
			}
		);

		// Check whether file has been modified
		if (found && data.size() == old_size)
		{
			if (pathGetModificationTime(file) <= old_time)
			{
				new_sha1 = sha1(data);
				has_sha1 = true;
				if (new_sha1 == old_sha1)
					write = false;
			}
		}
	}

	// Do not overwrite file if it did not change
	if (!write)
	{
		std::cout << "keeping " << path << std::endl;
		if (changed)
			*changed = false;

		assert(has_sha1);
		m_DB->exec(fmt() << "REPLACE INTO files (path, size, time, sha1) VALUES (?, " << data.size() << ", "
			<< time(nullptr) << ", ?)", { file, new_sha1 });
		transaction.commit();

		return file;
	}

	std::cout << "writing " << path << std::endl;
	if (changed)
		*changed = true;

	// Calculate SHA1 sum of the file
	if (!has_sha1)
		new_sha1 = sha1(data);

	// Create directory for the file
	std::string dir = pathGetDirectory(file);
	if (dir.length() > 0)
		pathCreate(dir);

	// Write the file
	::writeFile(file, data);

	// Store information about file into the database
	m_DB->exec(fmt() << "REPLACE INTO files (path, size, time, sha1) VALUES (?, " << data.size() << ", "
		<< time(nullptr) << ", ?)", { file, new_sha1 });
	transaction.commit();

	return file;
}