Exemple #1
0
void gw_mkdir_with_parents(const ustring & directory)
// Creates directory, with the parents, if need be.
// Function mkdir could be used (see man 2 mkdir), but this does not allow for 
// the creation of the parent directories. The core utility mkdir provides
// this functionality, so is preferred, and used here.
// Later one g_mkdir_with_parents () was used, but this did not create 
// directories properly. Hence we are stuck with mkdir.
{
#if 0
  ustring s;
  GwSpawn spawn (Directories->get_mkdir());
  spawn.arg (Directories->get_mkdir_args());
  spawn.arg (directory);
/*   GwSpawn spawn("mkdir");
#ifndef WIN32
  spawn.arg("-p");
#endif
  spawn.arg(directory);
#ifdef WIN32
  spawn.devnull();
#endif
 */  spawn.run();
 #endif
 
#ifdef WIN32
	// Use Windows system call to do this "right"
	bool retval = CreateDirectory(directory.c_str(), NULL);
	// Returns 0 if OK
	// Returns non-zero if error, and GetLastError will tell us:
	// ERROR_ALREADY_EXISTS The specified directory already exists.
	// ERROR_PATH_NOT_FOUND One or more intermediate directories do not exist; this function will only create the final directory in the path.
	if (retval == 0) {
		int lasterr = GetLastError();
		if (lasterr == ERROR_ALREADY_EXISTS) { 
			// Not really an error, just informative
			mkdir_info("Already exists " + directory);
		}
		else if (lasterr == ERROR_PATH_NOT_FOUND) {
			mkdir_info("Cannot create " + directory + " because intermediate directories don't exist.");
			// Strip off last part of directory and try again recursively
			Glib::ustring::size_type idx = directory.find_last_of("\\");
			ustring newdir = directory.substr(0, idx);
			gw_mkdir_with_parents(newdir);
			// Now try the full path again
			gw_mkdir_with_parents(directory);
		}
	}
	else {
		// Not really an error, just informative
		mkdir_info("Created " + directory);
	}
#else
  GwSpawn spawn (Directories->get_mkdir());
  spawn.arg (Directories->get_mkdir_args());
  spawn.arg (directory);
  spawn.run();
#endif
}
Exemple #2
0
filetype_t File::getFileType(ustring filename)
{
    // Extract file extension (i.e. "stl")
  ustring extension = filename.substr(filename.find_last_of(".")+1);


    if(extension == "wrl" || extension == "WRL") {
        return VRML;
    }

    if(extension == "amf" || extension == "AMF") {
        return AMF;
    }

    if(extension != "stl" && extension != "STL") {
        return NONE_STL;
    }

    ifstream file;
    file.open(filename.c_str());

    if(file.fail()) {
      cerr << _("Error: Unable to open file - ") << filename << endl;
      return NONE_STL;
    }

    // ASCII files start with "solid [Name_of_file]"
    ustring first_word;
    try {
      file >> first_word;

      // Find bad Solid Works STL header
      // 'solid binary STL from Solid Edge, Unigraphics Solutions Inc.'
      ustring second_word;
      if(first_word == "solid")
	file >> second_word;

      file.close();
      if(first_word == "solid" && second_word != "binary") { // ASCII
	return ASCII_STL;
      } else {
	return BINARY_STL;
      }
    } catch (Glib::ConvertError& e) {
      return BINARY_STL; // no keyword -> binary
    }

}
		ustring extract(const ustring& path)
		{
			auto pos = path.find_last_of(PATH_SEPARATORS);
			return (pos != ustring::npos) ? path.substr(++pos) : ustring();
		}