Example #1
0
int ISSImages::loadFilenames(const std::string directory, bool recursive)
{
	DIR *dir;
	class dirent *ent;
	class stat st;

	dir = opendir(directory.c_str());
	while ( (ent = readdir(dir)) != NULL )
	{
		const std::string filename = ent->d_name;
		const std::string full_filename = directory + '/' + filename;

		// Skip "." and ".."
		if ( filename[0] == '.' )
			continue;

		// Skip files that error out.  If we care, we can
		// check errno and see why we failed, but for now,
		// simply skip 'em
		if ( stat(full_filename.c_str(), &st) == -1 )
			continue;

		// If we're a directory, act accordingly
		if ( (st.st_mode & S_IFDIR) != 0 )
		{
			// Skip directory symlinks to take the easy way out
			// of a potential infinite recursion loop. TODO: fancy
			// this up to look for a subdir of our current dir or
			// something more sophisticated than simply skipping
			if ( (st.st_mode & S_IFLNK ) != 0 )
				continue;

			// Recurse if set
			if ( recursive )
				loadFilenames( full_filename, recursive );
			// Otherwise, skip the directory
			else
				continue;
		}
		// We're just a file
		else
		{
			std::string jpg(".jpg");
			std::string jpeg(".jpeg");
			//Check that it's a .jpg or .jpeg
			if ( full_filename.find(jpg, 0) != -1 || full_filename.find(jpeg, 0) != -1 )
				filenames.push_back(full_filename);
			else
				std::cout << "Skipping non-JPG file " << full_filename << std::endl;
		}
	}
	closedir(dir);

	return 0;
}
Example #2
0
ISSImages::ISSImages(SDL_Surface *sdl, const std::string directory, bool recursive) :
	mSDL(sdl),
	current_image_surface(NULL),
	previous_image_surface(NULL)
{
	loadFilenames(directory, recursive);

	if ( filenames.size() > 0 )
		current_image = filenames.begin();
	else
		printf("ERROR, no filenames!\n");
}
Example #3
0
uint MVFileDialog::execute()
/****************************************************************************
*
* Function:		MVFileDialog::execute
* Returns:		Command ending the execution.
*
* Description:	We overload the execute method to automatically set things
*				up for us. If the contents of the current directory are
*				not loaded, we load them first.
*
****************************************************************************/
{
	if (!(flags & fdDirLoaded))
		loadFilenames();
	select(fileLine);				// Focus on the file input line
	return MVDialog::execute();
}
Example #4
0
void MVFileDialog::changeDirectory()
/****************************************************************************
*
* Function:		MVFileDialog::changeDirectory
*
* Description:	Changes to the directory specified by the directory list
*				box, reads in the new filenames for the directory.
*
****************************************************************************/
{
	MVPoint		cursor;
	const char	*dir;
	char		path[PM_MAX_PATH];

	directoryList->getCurrentCell(cursor);
	directoryList->getCell(cursor.x,cursor.y,dir);

	// Build the name for the new directory to change to

	strcpy(path,driveSel->getText());
	strcat(path,directory);
	if (dir[0] == '.' && dir[1] == '.') {
		// Go back one directory. We do this by removing the last directory
		// entry from the path that we have built so far
		for (int index = strlen(path)-2; index >= 2; index--)
			if (path[index] == '\\' || path[index] == '/') {
				path[index+1] = '\0';
				break;
				}
		}
	else {
		strcat(path,dir);
		strcat(path,"/");
		}
	strcat(path,fileLine->getText());
	setFilename(path);
	loadFilenames();
}
Example #5
0
ibool MVFileDialog::valid(ulong command)
/****************************************************************************
*
* Function:		MVFileDialog::valid
* Parameters:	command	- Command causing the dialog to complete
* Returns:		True if the dialog is valid, false if not
*
* Description:	Determines if the value in the file input box is a valid
*				filename or not. We will not allow the user to quit
*				correctly unless the filename is valid.
*
****************************************************************************/
{
	if (command == cmValid || command == cmCancel)
		return true;

	if (MVDialog::valid(command)) {
		if (directoryList->getState() & sfFocused)
			changeDirectory();
		else if (fileList->getState() & sfFocused) {
			updateFileLine();
			return !hasWilds;
			}
		else {
			if (validFilename(fileLine->getText())) {
				setFilename(fileLine->getText());
				if (hasWilds) {
					loadFilenames();
        			fileList->select();
					}
				else
					return true;
				}
			}
		}
	return false;
}
Example #6
0
void PluginManager::loadPlugins()
{
    QList<QPair<QString,QString> > pluginFilenames = loadFilenames();

    foreach (auto filename, pluginFilenames) {
        QPluginLoader loader(filename.second);
        if(!loader.load())
        {
            qWarning()<<"Unable to laod plugin: "<<filename.first;
            continue;
        }

        IPlugin * plugin = qobject_cast<IPlugin*>(loader.instance());
        if(plugin) // Load a plugin
        {
            plugin->getQObject()->setObjectName(filename.first);
            qDebug() << "Load IPlugin " << filename.first;
            QJsonObject meta = loader.metaData();
            QStringList dependancyList = meta.value("MetaData").toObject().value("dependencies").toVariant().toStringList();
            foreach(QString dep, dependancyList) {
                plugin->addDependancy(getObjectByName(dep));
            }
            instance._allObjects.append(qMakePair(filename.first, plugin->getQObject()));
        }
Example #7
0
static uint64_t loadFromFile(tr_torrent* tor, uint64_t fieldsToLoad)
{
    TR_ASSERT(tr_isTorrent(tor));

    size_t len;
    int64_t i;
    char const* str;
    char* filename;
    tr_variant top;
    bool boolVal;
    uint64_t fieldsLoaded = 0;
    bool const wasDirty = tor->isDirty;
    tr_error* error = NULL;

    filename = getResumeFilename(tor);

    if (!tr_variantFromFile(&top, TR_VARIANT_FMT_BENC, filename, &error))
    {
        tr_logAddTorDbg(tor, "Couldn't read \"%s\": %s", filename, error->message);
        tr_error_free(error);

        tr_free(filename);
        return fieldsLoaded;
    }

    tr_logAddTorDbg(tor, "Read resume file \"%s\"", filename);

    if ((fieldsToLoad & TR_FR_CORRUPT) != 0 && tr_variantDictFindInt(&top, TR_KEY_corrupt, &i))
    {
        tor->corruptPrev = i;
        fieldsLoaded |= TR_FR_CORRUPT;
    }

    if ((fieldsToLoad & (TR_FR_PROGRESS | TR_FR_DOWNLOAD_DIR)) != 0 &&
        tr_variantDictFindStr(&top, TR_KEY_destination, &str, &len) && str != NULL && *str != '\0')
    {
        bool const is_current_dir = tor->currentDir == tor->downloadDir;
        tr_free(tor->downloadDir);
        tor->downloadDir = tr_strndup(str, len);

        if (is_current_dir)
        {
            tor->currentDir = tor->downloadDir;
        }

        fieldsLoaded |= TR_FR_DOWNLOAD_DIR;
    }

    if ((fieldsToLoad & (TR_FR_PROGRESS | TR_FR_INCOMPLETE_DIR)) != 0 &&
        tr_variantDictFindStr(&top, TR_KEY_incomplete_dir, &str, &len) && str != NULL && *str != '\0')
    {
        bool const is_current_dir = tor->currentDir == tor->incompleteDir;
        tr_free(tor->incompleteDir);
        tor->incompleteDir = tr_strndup(str, len);

        if (is_current_dir)
        {
            tor->currentDir = tor->incompleteDir;
        }

        fieldsLoaded |= TR_FR_INCOMPLETE_DIR;
    }

    if ((fieldsToLoad & TR_FR_DOWNLOADED) != 0 && tr_variantDictFindInt(&top, TR_KEY_downloaded, &i))
    {
        tor->downloadedPrev = i;
        fieldsLoaded |= TR_FR_DOWNLOADED;
    }

    if ((fieldsToLoad & TR_FR_UPLOADED) != 0 && tr_variantDictFindInt(&top, TR_KEY_uploaded, &i))
    {
        tor->uploadedPrev = i;
        fieldsLoaded |= TR_FR_UPLOADED;
    }

    if ((fieldsToLoad & TR_FR_MAX_PEERS) != 0 && tr_variantDictFindInt(&top, TR_KEY_max_peers, &i))
    {
        tor->maxConnectedPeers = i;
        fieldsLoaded |= TR_FR_MAX_PEERS;
    }

    if ((fieldsToLoad & TR_FR_RUN) != 0 && tr_variantDictFindBool(&top, TR_KEY_paused, &boolVal))
    {
        tor->isRunning = !boolVal;
        fieldsLoaded |= TR_FR_RUN;
    }

    if ((fieldsToLoad & TR_FR_ADDED_DATE) != 0 && tr_variantDictFindInt(&top, TR_KEY_added_date, &i))
    {
        tor->addedDate = i;
        fieldsLoaded |= TR_FR_ADDED_DATE;
    }

    if ((fieldsToLoad & TR_FR_DONE_DATE) != 0 && tr_variantDictFindInt(&top, TR_KEY_done_date, &i))
    {
        tor->doneDate = i;
        fieldsLoaded |= TR_FR_DONE_DATE;
    }

    if ((fieldsToLoad & TR_FR_ACTIVITY_DATE) != 0 && tr_variantDictFindInt(&top, TR_KEY_activity_date, &i))
    {
        tr_torrentSetActivityDate(tor, i);
        fieldsLoaded |= TR_FR_ACTIVITY_DATE;
    }

    if ((fieldsToLoad & TR_FR_TIME_SEEDING) != 0 && tr_variantDictFindInt(&top, TR_KEY_seeding_time_seconds, &i))
    {
        tor->secondsSeeding = i;
        fieldsLoaded |= TR_FR_TIME_SEEDING;
    }

    if ((fieldsToLoad & TR_FR_TIME_DOWNLOADING) != 0 && tr_variantDictFindInt(&top, TR_KEY_downloading_time_seconds, &i))
    {
        tor->secondsDownloading = i;
        fieldsLoaded |= TR_FR_TIME_DOWNLOADING;
    }

    if ((fieldsToLoad & TR_FR_BANDWIDTH_PRIORITY) != 0 &&
        tr_variantDictFindInt(&top, TR_KEY_bandwidth_priority, &i) && tr_isPriority(i))
    {
        tr_torrentSetPriority(tor, i);
        fieldsLoaded |= TR_FR_BANDWIDTH_PRIORITY;
    }

    if ((fieldsToLoad & TR_FR_PEERS) != 0)
    {
        fieldsLoaded |= loadPeers(&top, tor);
    }

    if ((fieldsToLoad & TR_FR_FILE_PRIORITIES) != 0)
    {
        fieldsLoaded |= loadFilePriorities(&top, tor);
    }

    if ((fieldsToLoad & TR_FR_PROGRESS) != 0)
    {
        fieldsLoaded |= loadProgress(&top, tor);
    }

    if ((fieldsToLoad & TR_FR_DND) != 0)
    {
        fieldsLoaded |= loadDND(&top, tor);
    }

    if ((fieldsToLoad & TR_FR_SPEEDLIMIT) != 0)
    {
        fieldsLoaded |= loadSpeedLimits(&top, tor);
    }

    if ((fieldsToLoad & TR_FR_RATIOLIMIT) != 0)
    {
        fieldsLoaded |= loadRatioLimits(&top, tor);
    }

    if ((fieldsToLoad & TR_FR_IDLELIMIT) != 0)
    {
        fieldsLoaded |= loadIdleLimits(&top, tor);
    }

    if ((fieldsToLoad & TR_FR_FILENAMES) != 0)
    {
        fieldsLoaded |= loadFilenames(&top, tor);
    }

    if ((fieldsToLoad & TR_FR_NAME) != 0)
    {
        fieldsLoaded |= loadName(&top, tor);
    }

    /* loading the resume file triggers of a lot of changes,
     * but none of them needs to trigger a re-saving of the
     * same resume information... */
    tor->isDirty = wasDirty;

    tr_variantFree(&top);
    tr_free(filename);
    return fieldsLoaded;
}