Beispiel #1
0
	void createFile(const std::string& name, const User* pOwner, const std::string& content)
	{
		if (getObjectByName(name, files_))
		{
			throw AlreadyExistException(name);
		}

		files_.emplace_back(name, this, pOwner, content);
	}
Beispiel #2
0
	void createDir(const std::string& name, const User* pOwner) //создание директории
	{
		if (getObjectByName(name, dirs_))
		{
			throw AlreadyExistException(name);  //нельзя две директории с одним именем!
		}

		dirs_.emplace_back(name, this, pOwner); //пихаем директорию в вектор( в кач-ве родителя передаем текущую директорию!!!)
	}
Beispiel #3
0
	void createBackup(const std::string& backupName)
	{
		if (getObjectByName(backupName, backups_))
		{
			throw AlreadyExistException(backupName);
		}

		backups_.emplace_back(pRoot_.get(), backupName);
	}
Beispiel #4
0
	File* getFile(const std::string& name) 
	{
		File* pFile = getObjectByName(name, files_);

		if (!pFile)
		{
			throw DoesntExistException(name);
		}

		return pFile;
	}
Beispiel #5
0
	Directory* getDir(const std::string& name) //получает директорию по имени
	{
		Directory* pDir = getObjectByName(name, dirs_); 

		if (!pDir)
		{
			throw DoesntExistException(name);
		}

		return pDir;
	}
Beispiel #6
0
MStatus getPlugByName(const MString & objName, const MString & attrName,
            MPlug & plug)
{
    MObject object = MObject::kNullObj;
    MStatus status = getObjectByName(objName, object);
    if (status == MS::kSuccess)
    {
        MFnDependencyNode mFn(object, &status);
        if (status == MS::kSuccess)
            plug = mFn.findPlug(attrName, &status);
    }

    return status;
}
Beispiel #7
0
Object getAnyObjectNamed(vector<vector<Object> > &v, string name, int depth)
{
    Object o;
    for (int i=depth; i>=0; i--)
    {
        if (i>=v.size()) continue;
        o = getObjectByName(v[i], name);
        if (o.name!="invalid object name") //we found a variable for this value!
        {
            return o;
        }
    }
    return o;
}
Beispiel #8
0
	void restoreBackup(const std::string& backupName)
	{
		Backup* pBackup = getObjectByName(backupName, backups_);

		if (!pBackup)
		{
			throw DoesntExistException(backupName);
		}

		std::unique_ptr<Directory> pRoot = Directory::CreateRoot();
		pRoot->copyDirContentFromSrc(pBackup->root().get());
		pRoot_ = std::move(pRoot);
		pCurrentDir_ = pRoot_.get();
	}
Beispiel #9
0
	void login() //пока текущий пользователь не установлен
	{
		while (!pCurrentUser_)
		{
			std::cout << "Username: "******"User '" << username << "' not found" << std::endl;
			}
			else
			{
				authentication(pUser); //попытка идентифицировать
			}
		}
	}
Beispiel #10
0
MStatus setInitialShadingGroup(const MString & dagNodeName)
{
    MObject initShader;
    MDagPath dagPath;

    if (getObjectByName("initialShadingGroup", initShader) == MS::kSuccess &&
        getDagPathByName(dagNodeName, dagPath) == MS::kSuccess)
    {
        MFnSet set(initShader);
        set.addMember(dagPath);
    }
    else
    {
        MString theError("Error getting adding ");
        theError += dagNodeName;
        theError += MString(" to initalShadingGroup.");
        MGlobal::displayError(theError);
        return MS::kFailure;
    }
    return MS::kSuccess;
}
Beispiel #11
0
	bool executeUserCommand(const std::string& command, const std::vector<std::string>& commandArgs) //выполнить пользовательскую команду
	{
		if (command == "users")
		{
			listAvailableUsers();
		}
		else if (command == "user")
		{
			if (commandArgs.empty())
			{
				if (!pCurrentUser_)
				{
					std::cout << "Not authenticated" << std::endl;
				}
				else
				{
					std::cout << "Current user: '******'" << std::endl;
				}
			}
			else
			{
				const std::string& username = commandArgs.at(0);
				User* pUser = getObjectByName(username, users_);
				if (!pUser)
				{
					std::cout << "User '" << username << "' not found" << std::endl;
				}
				else
				{
					authentication(pUser);
				}
			}
		}
		else
		{
			return false;
		}

		return true;
	}
int DBBrowserDB::addRecord(const QString& sTableName)
{
    char *errmsg;
    if (!isOpen()) return false;

    // add record is seldom called, for now this is ok
    // but if we ever going to add a lot of records
    // we should cache the parsed tables somewhere
    sqlb::Table table = sqlb::Table::parseSQL(getObjectByName(sTableName).getsql()).first;
    QString sInsertstmt = table.emptyInsertStmt();
    lastErrorMessage = "";
    logSQL(sInsertstmt, kLogMsg_App);
    setRestorePoint();

    if (SQLITE_OK != sqlite3_exec(_db, sInsertstmt.toUtf8(), NULL, NULL, &errmsg))
    {
        lastErrorMessage = QString::fromUtf8(errmsg);
        qWarning() << "addRecord: " << lastErrorMessage;
        return -1;
    } else {
        return sqlite3_last_insert_rowid(_db);
    }
}
MStatus AlembicAssignInitialSGCommand::doIt(const MArgList& args)
{
  MStatus status;
  MArgParser argData(syntax(), args, &status);

  if (argData.isFlagSet("help"))
  {
    MGlobal::displayInfo("[ExocortexAlembic]: ExocortexAlembic_assignFaceset command:");
    MGlobal::displayInfo("                    -m : mesh to assign the initialShadingGroup on");
    return MS::kSuccess;
  }

  if (!argData.isFlagSet("mesh"))
  {
    MGlobal::displayError("No mesh/subdiv specified!");
    return MS::kFailure;
  }

  MObject initShader;
  MDagPath dagPath;

  if (getObjectByName("initialShadingGroup", initShader) == MS::kSuccess && getDagPathByName(argData.flagArgumentString("mesh", 0), dagPath) == MS::kSuccess)
  {
    ESS_PROFILE_SCOPE("AlembicAssignInitialSGCommand::doIt::MFnSet");
    MFnSet set(initShader);
    set.addMember(dagPath);
  }
  else
  {
    MString theError("Error getting adding ");
    theError += argData.flagArgumentString("mesh", 0);
    theError += MString(" to initalShadingGroup.");
    MGlobal::displayError(theError);
    return MS::kFailure;
  }
  return MS::kSuccess;
}
Beispiel #14
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()));
        }
bool DBBrowserDB::renameColumn(const QString& tablename, const QString& name, sqlb::FieldPtr to, int move)
{
    // NOTE: This function is working around the incomplete ALTER TABLE command in SQLite.
    // If SQLite should fully support this command one day, this entire
    // function can be changed to executing something like this:
    //QString sql;
    //if(to.isNull())
    //    sql = QString("ALTER TABLE `%1` DROP COLUMN `%2`;").arg(table).arg(column);
    //else
    //    sql = QString("ALTER TABLE `%1` MODIFY `%2` %3").arg(tablename).arg(to).arg(type);    // This is wrong...
    //return executeSQL(sql);

    // Collect information on the current DB layout
    QString tableSql = getObjectByName(tablename).getsql();
    if(tableSql.isEmpty())
    {
        lastErrorMessage = QObject::tr("renameColumn: cannot find table %1.").arg(tablename);
        qWarning() << lastErrorMessage;
        return false;
    }

    // Create table schema
    sqlb::Table oldSchema = sqlb::Table::parseSQL(tableSql).first;

    // Check if field actually exists
    if(oldSchema.findField(name) == -1)
    {
        lastErrorMessage = QObject::tr("renameColumn: cannot find column %1.").arg(name);
        qWarning() << lastErrorMessage;
        return false;
    }

    // Create savepoint to be able to go back to it in case of any error
    if(!executeSQL("SAVEPOINT sqlitebrowser_rename_column"))
    {
        lastErrorMessage = QObject::tr("renameColumn: creating savepoint failed. DB says: %1").arg(lastErrorMessage);
        qWarning() << lastErrorMessage;
        return false;
    }

    // Create a new table with a name that hopefully doesn't exist yet.
    // Its layout is exactly the same as the one of the table to change - except for the column to change
    // of course
    sqlb::Table newSchema = oldSchema;
    newSchema.setName("sqlitebrowser_rename_column_new_table");
    QString select_cols;
    if(to.isNull())
    {
        // We want drop the column - so just remove the field
        newSchema.removeField(name);

        for(int i=0;i<newSchema.fields().count();++i)
            select_cols.append(QString("`%1`,").arg(newSchema.fields().at(i)->name()));
        select_cols.chop(1);    // remove last comma
    } else {
        // We want to modify it

        // Move field
        int index = newSchema.findField(name);
        sqlb::FieldPtr temp = newSchema.fields().at(index);
        newSchema.setField(index, newSchema.fields().at(index + move));
        newSchema.setField(index + move, temp);

        // Get names of fields to select from old table now - after the field has been moved and before it might be renamed
        for(int i=0;i<newSchema.fields().count();++i)
            select_cols.append(QString("`%1`,").arg(newSchema.fields().at(i)->name()));
        select_cols.chop(1);    // remove last comma

        // Modify field
        newSchema.setField(index + move, to);
    }

    // Create the new table
    if(!executeSQL(newSchema.sql()))
    {
        lastErrorMessage = QObject::tr("renameColumn: creating new table failed. DB says: %1").arg(lastErrorMessage);
        qWarning() << lastErrorMessage;
        executeSQL("ROLLBACK TO SAVEPOINT sqlitebrowser_rename_column;");
        return false;
    }

    // Copy the data from the old table to the new one
    if(!executeSQL(QString("INSERT INTO sqlitebrowser_rename_column_new_table SELECT %1 FROM `%2`;").arg(select_cols).arg(tablename)))
    {
        lastErrorMessage = QObject::tr("renameColumn: copying data to new table failed. DB says:\n"
                                       "%1").arg(lastErrorMessage);
        qWarning() << lastErrorMessage;
        executeSQL("ROLLBACK TO SAVEPOINT sqlitebrowser_rename_column;");
        return false;
    }

    // Save all indices, triggers and views associated with this table because SQLite deletes them when we drop the table in the next step
    QString otherObjectsSql;
    for(objectMap::ConstIterator it=objMap.begin();it!=objMap.end();++it)
    {
        // If this object references the table and it's not the table itself save it's SQL string
        if((*it).getTableName() == tablename && (*it).gettype() != "table")
            otherObjectsSql += (*it).getsql() + "\n";
    }

    // Delete the old table
    if(!executeSQL(QString("DROP TABLE `%1`;").arg(tablename)))
    {
        lastErrorMessage = QObject::tr("renameColumn: deleting old table failed. DB says: %1").arg(lastErrorMessage);
        qWarning() << lastErrorMessage;
        executeSQL("ROLLBACK TO SAVEPOINT sqlitebrowser_rename_column;");
        return false;
    }

    // Rename the temporary table
    if(!renameTable("sqlitebrowser_rename_column_new_table", tablename))
    {
        executeSQL("ROLLBACK TO SAVEPOINT sqlitebrowser_rename_column;");
        return false;
    }

    // Restore the saved triggers, views and indices
    if(!executeMultiSQL(otherObjectsSql, true, true))
    {
        QMessageBox::information(0, qApp->applicationName(), QObject::tr("Restoring some of the objects associated with this table failed. "
                                                                         "This is most likely because some column names changed. "
                                                                         "Here's the SQL statement which you might want to fix and execute manually:\n\n")
                                 + otherObjectsSql);
    }

    // Release the savepoint - everything went fine
    if(!executeSQL("RELEASE SAVEPOINT sqlitebrowser_rename_column;"))
    {
        lastErrorMessage = QObject::tr("renameColumn: releasing savepoint failed. DB says: %1").arg(lastErrorMessage);
        qWarning() << lastErrorMessage;
        return false;
    }

    // Success, update the DB schema before returning
    updateSchema();
    return true;
}