Ejemplo n.º 1
0
char *getFullPathName(char *str)
{
  char *path, *dir;

  if( str == NULL )
    return str;

  while( *str == ' ' )
    str++;

  dir = strndup(currDir, PATH_LEN);
  concatPaths( dir, str, &path);

//  printf("Path: '%s'\n", path);

  return path;
}
static int setAppWindowPropertyFn() {
	Window appWindow;
	Atom propAtom;
	_TCHAR *propVal;

	//Look for the SWT window. If it's there, set a property on it.
	appWindow = gtk.XGetSelectionOwner(gtk_GDK_DISPLAY, appWindowAtom);
	if (appWindow) {
		propAtom = gtk.XInternAtom(gtk_GDK_DISPLAY, "org.eclipse.swt.filePath.message", FALSE);
		//append a colon delimiter in case more than one file gets appended to the app windows property.
		propVal = concatPaths(openFilePath, _T_ECLIPSE(':'));
		gtk.XChangeProperty(gtk_GDK_DISPLAY, appWindow, propAtom, propAtom, 8, PropModeAppend, (unsigned char *)propVal, _tcslen(propVal));
		free(propVal);
		windowPropertySet = 1;
		return 1;
	}
	return 0;
}
Ejemplo n.º 3
0
void ExternalFileWriter::generateObjectName(std::string & out_relativePath, std::string & out_absolutePath, int type)
{
    static const ObjectIndex MAX_NUMBER = UINT_MAX-1;        // -1 to allow doing +1 without an overflow
    for (ObjectIndex number=_lastGeneratedObjectIndex+1; number<MAX_NUMBER; ++number)
    {
        std::ostringstream oss;
        oss << FILE_PREFIX[type] << number << FILE_EXTENSION[type];
        out_relativePath = oss.str();
        out_absolutePath = concatPaths(_destDirectory, out_relativePath);

        if (!absoluteObjectPathExists(out_absolutePath))
        {
            _lastGeneratedObjectIndex = number;
            return;
        }
    }
    throw std::runtime_error("Could not get a free index to write image.");
}
Ejemplo n.º 4
0
bool BZFSHTTP::handleRequest(const HTTPRequest &request, HTTPReply &reply)
{
  if (serviceMimeResources && resourceRootPath.size() && mimeTypes.size())
  {
    // parse out the resource and see if we know what it is
    std::string ext;
    tolower(getFileExtension(request.resource),ext);

    if (ext.size())
    {
      if ( mimeTypes.find(ext) != mimeTypes.end() )
      {
	// it's one we do, try and find it
	std::string filepath = concatPaths(resourceRootPath.c_str(),request.resource.c_str());

	FILE *fp = fopen(filepath.c_str(),"rb");
	if (fp)
	{
	  char buffer[1024];
	  bool done = false;

	  while (!done)
	  {
	    size_t read = fread(buffer,1,1024,fp);
	    if (read)
	      reply.addBody(buffer,read);

	    if (read != 1024)
	      done = true;
	  }
	  fclose(fp);

	  reply.docType = HTTPReply::eOther;
	  reply.otherMimeType = mimeTypes[ext];
	  reply.returnCode = HTTPReply::e200OK;
	  return true;
	}
      }
    }
  }

  return generatePage(request,reply);
}
Ejemplo n.º 5
0
static int setAppWindowPropertyFn() {
	Window appWindow;
	GdkWindow *propWindow;
	GdkAtom propAtom;
	_TCHAR *propVal;

	//Look for the SWT window. If it's there, set a property on it.
	appWindow = gtk.XGetSelectionOwner(gtk_GDK_DISPLAY, appWindowAtom);
	//appWindow = XGetSelectionOwner(GDK_DISPLAY(), appWindowAtom);
	if (appWindow) {
		propAtom = gtk.gdk_atom_intern("org.eclipse.swt.filePath.message", FALSE);
		//append a colon delimiter in case more than one file gets appended to the app windows property.
		propVal = concatPaths(openFilePath, _T_ECLIPSE(':'));
		propWindow = gtk.gdk_window_foreign_new(appWindow);
		if (propWindow != NULL) {
			gtk.gdk_property_change(propWindow, propAtom, propAtom, 8, GDK_PROP_MODE_APPEND, (guchar *) propVal, _tcslen(propVal));
			free(propVal);
			return 1;
		} //else the window got destroyed between XGetSelectionOwner and here (?)
		free(propVal);
	}
	return 0;
}
Ejemplo n.º 6
0
bool ExternalFileWriter::write(const osg::Object & obj, const Options * options, std::string * out_absolutePath, std::string * out_relativePath)
{
    ObjectsSet::iterator it( _objects.find(&obj) );
    if (it != _objects.end())
    {
        // Object has already been passed to this method
        if (out_absolutePath) *out_absolutePath = it->second.absolutePath;
        if (out_relativePath) *out_relativePath = it->second.relativePath;
        return it->second.written;
    }

    // Object is a new entry

    // Get absolute source path
    WriteType type( getType(obj) );
    std::string originalFileName( getFileName(obj, type) );
    std::string absoluteSourcePath;
    if (_keepRelativePaths && !originalFileName.empty())        // if keepRelativePaths is false, absoluteSourcePath is not used, then we can skip this part
    {
        if (isAbsolutePath(originalFileName)) absoluteSourcePath = originalFileName;
        else absoluteSourcePath = concatPaths(_srcDirectory, originalFileName);
        absoluteSourcePath = getRealPath(convertFileNameToNativeStyle(absoluteSourcePath));      // getRealPath() here is only used to canonize the path, not to add current directory in front of relative paths, hence the "concatPaths(_srcDirectory, ...)" just above
    }

    // Compute destination paths from the source path
    std::string relativeDestinationPath;
    std::string absoluteDestinationPath;
    if (absoluteSourcePath.empty())
    {
        // We have no name. Generate one.
        generateObjectName(relativeDestinationPath, absoluteDestinationPath, type);
    }
    else
    {
        // We have a name.
        if (_keepRelativePaths)
        {
            // We'll try to keep images relative path.
            relativeDestinationPath = getPathRelative(_srcDirectory, absoluteSourcePath);
            unsigned int nbDirsUp = countNbDirsUp(relativeDestinationPath);
            // TODO if nbDirsUp>nb dirs in _destDirectory, then issue a warning, and use simple file name
            if (nbDirsUp > _allowUpDirs) relativeDestinationPath = getSimpleFileName(absoluteSourcePath);
        }
        else
        {
            // We keep only the simple file name.
            relativeDestinationPath = getSimpleFileName(absoluteSourcePath);
        }
        absoluteDestinationPath = getRealPath(convertFileNameToNativeStyle( concatPaths(_destDirectory, relativeDestinationPath) ));
        // TODO Check for absolute paths collisions between multiple objects
    }

    // Write object
    bool written(false);
    if (!makeDirectoryForFile(absoluteDestinationPath))
    {
        OSG_NOTICE << "Can't create directory for file '" << absoluteDestinationPath << "'. May fail creating the image file." << std::endl;
    }
    if (!doWrite(obj, type, absoluteDestinationPath, options))
    {
        OSG_WARN << "Can't write file '" << absoluteDestinationPath << "'." << std::endl;
    }
    else written = true;

    // Add entry
    _objects.insert(ObjectsSet::value_type(&obj, ObjectData(absoluteDestinationPath, relativeDestinationPath, written)));
    _searchMap.insert(SearchMap::value_type(pathHash(absoluteDestinationPath), &obj));

    // Fill output strings
    if (out_absolutePath) *out_absolutePath = absoluteDestinationPath;
    if (out_relativePath) *out_relativePath = relativeDestinationPath;

    return written;
}