Ejemplo n.º 1
0
void SetupPar(char* pararchivename)
{
  //Load par files, create analysis libraries
  //For testing, if par file already decompressed and modified
  //classes then do not decompress.
 
  TString cdir(Form("%s", gSystem->WorkingDirectory() )) ; 
  TString parpar(Form("%s.par", pararchivename)) ; 
  if ( gSystem->AccessPathName(parpar.Data()) ) {
    gSystem->ChangeDirectory(gSystem->Getenv("ALICE_ROOT")) ;
    TString processline(Form(".! make %s", parpar.Data())) ; 
    gROOT->ProcessLine(processline.Data()) ;
    gSystem->ChangeDirectory(cdir) ; 
    processline = Form(".! mv $ALICE_ROOT/%s .", parpar.Data()) ;
    gROOT->ProcessLine(processline.Data()) ;
  } 
  if ( gSystem->AccessPathName(pararchivename) ) {  
    TString processline = Form(".! tar xvzf %s",parpar.Data()) ;
    gROOT->ProcessLine(processline.Data());
  }
  
  TString ocwd = gSystem->WorkingDirectory();
  gSystem->ChangeDirectory(pararchivename);
  
  // check for BUILD.sh and execute
  if (!gSystem->AccessPathName("PROOF-INF/BUILD.sh")) {
    printf("*******************************\n");
    printf("*** Building PAR archive    ***\n");
    cout<<pararchivename<<endl;
    printf("*******************************\n");
    
    if (gSystem->Exec("PROOF-INF/BUILD.sh")) {
      Error("runProcess","Cannot Build the PAR Archive! - Abort!");
      return -1;
    }
  }
  // check for SETUP.C and execute
  if (!gSystem->AccessPathName("PROOF-INF/SETUP.C")) {
    printf("*******************************\n");
    printf("*** Setup PAR archive       ***\n");
    cout<<pararchivename<<endl;
    printf("*******************************\n");
    gROOT->Macro("PROOF-INF/SETUP.C");
  }
  
  gSystem->ChangeDirectory(ocwd.Data());
  printf("Current dir: %s\n", ocwd.Data());
}
Ejemplo n.º 2
0
bool GalleryUtil::Rename(const QString &currDir, const QString &oldName,
                         const QString &newName)
{
    // make sure there isn't already a file/directory with the same name
    QFileInfo fi(currDir + '/' + newName);
    if (fi.exists())
        return false;

    fi.setFile(currDir + '/' + oldName);
    if (fi.isDir())
        return RenameDirectory(currDir, oldName, newName);

    // rename the file
    QDir cdir(currDir);
    if (!cdir.rename(oldName, newName))
        return false;

    // rename the file's thumbnail if it exists
    if (QFile::exists(currDir + "/.thumbcache/" + oldName))
    {
        QDir d(currDir + "/cache/gallery-thumbcache/");
        d.rename(oldName, newName);
    }

    int prefixLen = gCoreContext->GetSetting("GalleryDir").length();
    QString path = GetConfDir() + "/MythGallery";
    path += currDir.right(currDir.length() - prefixLen);
    path += QString("/.thumbcache/");
    if (QFile::exists(path + oldName))
    {
        QDir d(path);
        d.rename(oldName, newName);
    }

    // fix up the metadata in the database
    MSqlQuery query(MSqlQuery::InitCon());
    query.prepare("UPDATE gallerymetadata "
                  "SET image = :IMAGENEW "
                  "WHERE image = :IMAGEOLD");
    query.bindValue(":IMAGENEW", QString(currDir + '/' + newName));
    query.bindValue(":IMAGEOLD", QString(currDir + '/' + oldName));
    if (query.exec())
        return true;

    // try to undo rename on DB failure
    cdir.rename(newName, oldName);
    return false;
}
Ejemplo n.º 3
0
int main(int argc, char *argv[]) {
    char buf[NET_BUF];
    int s, len, port;
    char *server_name;

    if(argc != 3) {
        printf("usage: ./myftp <server> <port>\n");
        return 0;
    }
    server_name = argv[1];
    port = atoi(argv[2]);

    s = get_client_socket(argv[1], port);    

    char line[BUF_SIZE];
    help();
    while(1) {
        printf("myftp>>> ");
        read_line(line);

        if (strcmp(line, "DWLD") == 0) {
            dwld(s);
        } else if (strcmp(line, "UPLD") == 0) {
            upld(s);
        } else if (strcmp(line, "LIST") == 0) {
            list(s);
        } else if (strcmp(line, "MDIR") == 0) {
            mdir(s);
        } else if (strcmp(line, "RDIR") == 0) {
            rdir(s);
        } else if (strcmp(line, "CDIR") == 0) {
            cdir(s);
        } else if (strcmp(line, "DELF") == 0) {
            delf(s);
        } else if (strcmp(line, "HELP") == 0) {
            help();
        } else if (strcmp(line, "QUIT") == 0) {
            printf("goodbye\n");
            quit(s);
            close(s);
            break;
        } else {
            printf("Unrecognized command: %s\n", line);
        }
        
    }
    return 0;
}
Ejemplo n.º 4
0
void CreateFromXMLFile( SPointer< IFile > fileInput )
{
    std::string ln,data;
    IFileStream desc_file( fileInput );

    while ( std::getline( desc_file, ln ) )
    {
        data += ln;
        data += "\n";
    }

    std::string name = fileInput->GetName();
    if ( ':' != name[1] )
    {
        char buffer[255] = {0,};
        memset( buffer, 0, 255);
        getcwd( buffer, 255);
        std::string cdir( buffer );
        name = cdir + "/" + name;
    }
    CreateFromXML( data, name );
}
Ejemplo n.º 5
0
void FileBrowser::addItems(const QString & path )
{
	if( m_dirsAsItems )
	{
		m_l->addTopLevelItem( new Directory( path,
						QString::null, m_filter ) );
		return;
	}

	QDir cdir( path );
	QStringList files = cdir.entryList( QDir::Dirs, QDir::Name );
	for( QStringList::const_iterator it = files.constBegin();
						it != files.constEnd(); ++it )
	{
		QString cur_file = *it;
		if( cur_file[0] != '.' )
		{
			bool orphan = true;
			for( int i = 0; i < m_l->topLevelItemCount(); ++i )
			{
				Directory * d = dynamic_cast<Directory *>(
						m_l->topLevelItem( i ) );
				if( d == NULL || cur_file < d->text( 0 ) )
				{
					m_l->insertTopLevelItem( i,
						new Directory( cur_file, path,
								m_filter ) );
					orphan = false;
					break;
				}
				else if( cur_file == d->text( 0 ) )
				{
					d->addDirectory( path );
					orphan = false;
					break;
				}
			}
			if( orphan )
			{
				m_l->addTopLevelItem( new Directory( cur_file,
							path, m_filter ) );
			}
		}
	}

	files = cdir.entryList( QDir::Files, QDir::Name );
	for( QStringList::const_iterator it = files.constBegin();
						it != files.constEnd(); ++it )
	{
		QString cur_file = *it;
		if( cur_file[0] != '.' )
		{
			// TODO: don't insert instead of removing, order changed
			// remove existing file-items
			QList<QTreeWidgetItem *> existing = m_l->findItems(
					cur_file, Qt::MatchFixedString );
			if( !existing.empty() )
			{
				delete existing.front();
			}
			(void) new FileItem( m_l, cur_file, path );
		}
	}
}
Ejemplo n.º 6
0
bool GalleryUtil::RenameDirectory(const QString &currDir, const QString &oldName,
                                const QString &newName)
{
    // rename the directory
    QDir cdir(currDir);
    if (!cdir.rename(oldName, newName))
        return false;

    // rename the directory's thumbnail if it exists in the parent directory
    if (QFile::exists(currDir + "/.thumbcache/" + oldName))
    {
        QDir d(currDir + "/cache/gallery-thumbcache/");
        d.rename(oldName, newName);
    }

    // also look in HOME directory for any thumbnails
    int prefixLen = gCoreContext->GetSetting("GalleryDir").length();
    QString path = GetConfDir() + "/MythGallery";
    path += currDir.right(currDir.length() - prefixLen) + '/';
    if (QFile::exists(path + oldName))
    {
        QDir d(path);
        d.rename(oldName, newName);

        // rename this directory's thumbnail
        path += QString(".thumbcache/");
        if (QFile::exists(path + oldName))
        {
            QDir d(path);
            d.rename(oldName, newName);
        }
    }

    // fix up the metadata in the database
    MSqlQuery query(MSqlQuery::InitCon());
    query.prepare("SELECT image, angle FROM gallerymetadata "
                  "WHERE image LIKE :IMAGEOLD");
    query.bindValue(":IMAGEOLD", QString(currDir + '/' + oldName + '%'));
    if (query.exec())
    {
        while (query.next())
        {
            QString oldImage = query.value(0).toString();
            QString newImage = oldImage;
            newImage = newImage.replace(currDir + '/' + oldName,
                                        currDir + '/' + newName);

            MSqlQuery subquery(MSqlQuery::InitCon());
            subquery.prepare("UPDATE gallerymetadata "
                        "SET image = :IMAGENEW "
                        "WHERE image = :IMAGEOLD");
            subquery.bindValue(":IMAGENEW", newImage);
            subquery.bindValue(":IMAGEOLD", oldImage);
            if (!subquery.exec())
                MythDB::DBError("GalleryUtil::RenameDirectory - update image",
                                subquery);
        }
    }

    return true;
}
Ejemplo n.º 7
0
int builtin(char *argv[])
{
    if (strcmp(argv[0], "help") == 0)
    {
        help();
        return 1;
    }
    if (strcmp(argv[0], "exit") == 0)     /* exit command */
    {
        int count = 0; //job_count();
        if (count > 0)
        {
            printf("There are %d jobs still running.\n", count);
        }
        else
        {
            exit(0);
        }

        return 1;
    }

    if (strcmp(argv[0], "&") == 0)        /* ignore singleton & */
    {
        return 1;
    }

    if (strcmp(argv[0], "echo") == 0)     /* echo command */
    {
        argv++;
        for (; *argv != NULL; argv++)
        {
            printf("%s%s", *argv, " ");
        }
        printf("\n");
        return 1;
    }

    if (strcmp(argv[0], "dir") == 0)    /* dir command */
    {   /* some implementations of PATH_MAX are not
           compile time constants (appearantly) */
        char* path = (char*) malloc(PATH_MAX * sizeof(char));
        if (NULL == path || NULL == getcwd(path, PATH_MAX))
        {   /* path name exceeded the max length */
            fprintf(stderr, "Error allocating space for getcwd: %s",
                    strerror(errno));
            exit(EXIT_FAILURE);
        }
        printf("%s\n", path);
        free(path);
        return 1;
    }

    if (strcmp(argv[0], "cdir") == 0)   /* cdir command */
    {
        cdir(argv);
        return 1;
    }

    if (strcmp(argv[0], "penv") == 0)   /* penv command */
    {
        penv(argv);
        return 1;
    }

    if (strcmp(argv[0], "senv") == 0)
    {
        senv(argv);
        return 1;
    }

    if (strcmp(argv[0], "unsenv") == 0)
    {
        unsenv(argv);
        return 1;
    }

    if (strcmp(argv[0], "pjobs") == 0)
    {
        pjobs();
        return 1;
    }

    if (strcmp(argv[0], "set") == 0)
    {
        set(argv);
        return 1;
    }
    if (strcmp(argv[0], "limits") == 0)
    {
        limits();
        return 1;
    }

    return 0;                             /* not a builtin command */
}
Ejemplo n.º 8
0
// Recursivly add all book files to the list
void BookList::addAllBooks (QString dirpath, bool isUserBooks, int parentindex)
{
    QDir cdir(absPath(dirpath));

    //Get all .folder or .obk files in the directory
    QStringList filter; filter << "*.folder" << "*.obk" << "*.pdf" << "*.link" << "*.html" << "*.htm";
    QFileInfoList list = cdir.entryInfoList(filter, QDir::AllEntries | QDir::NoSymLinks | QDir::NoDotAndDotDot, QDir::Name);

    //TODO: Add pdf, html, etc'

    for (int i=0; i<list.size(); i++)
    {
        Book::Filetype ft;
        if (list[i].fileName().endsWith(".folder", Qt::CaseInsensitive))
            ft = Book::Dir;
        else if (list[i].fileName().endsWith(".obk", Qt::CaseInsensitive))
            ft = Book::Normal;
        else if (list[i].fileName().endsWith(".html", Qt::CaseInsensitive) || list[i].fileName().endsWith(".htm", Qt::CaseInsensitive))
            ft = Book::Html;
        else if (list[i].fileName().endsWith(".pdf", Qt::CaseInsensitive))
            ft = Book::Pdf;
        else if (list[i].fileName().endsWith(".link", Qt::CaseInsensitive))
            ft = Book::Link;
        else
            ft = Book::Unkown;

        if ( ft != Book::Unkown )
        {
            if ( list[i].fileName().indexOf("Pics") != -1 )
                continue;

            QString Name = list[i].fileName();
            if (!isUserBooks)
                Name.replace(QRegExp("^[0-9 ]*"), "").replace("_", " ").replace(".obk", "");

            //Create BookListItem
            Book *b = new Book(parentindex != -1 ? (*this)[parentindex] : NULL,
                                   list[i].absoluteFilePath(), list[i].absoluteFilePath(), Name, ft, isUserBooks);

            //Tell the parent it has a new child
            if (b->getParent() != NULL)
                b->getParent()->add_child(b);

            //Add this book to the list
            push_back(b);

            //Add folder entry, and all files in that folder
            if (ft == Book::Dir)
            {
                //Do the whole thing again for any dir, sending it's index in the list as the
                // Parents index of all it's children
                addAllBooks(list[i].absoluteFilePath().replace(".folder", ""), isUserBooks, this->size() - 1);

                //Add confs for this directory
                QList <QString> t;
                t.clear();
                if (ReadFileToList(list[i].absoluteFilePath(), t , "UTF-8")) AddBookConfs(b, t);
            }

            //Add orayta-book
            else if ( ft == Book::Normal )
            {
                //Add confs for this book
                QList <QString> t;
                t.clear();
                if (ReadZipComment(list[i].absoluteFilePath(), t, "UTF-8")) AddBookConfs(b, t);
            }

            else if ( ft == Book::Link )
            {
                //Add confs for this book
                AddBookConfs(b, readfile(b->getPath(), "UTF-8").split("\n"));
            }

            else if ( ft == Book::Html )
            {
                //Add confs for this book
                AddBookConfs(b, readfile(b->getPath().replace(QRegExp("\\.\\w{3,4}$"),".conf"), "UTF-8").split("\n"));
            }

        }
    }

    /*
    for (int i=0; i<list.size(); i++)
    {
        Book::Filetype ft;

        // set the file type
        if (list[i].isDir())
            ft = Book::Dir;
        else if (list[i].fileName().endsWith(".txt", Qt::CaseInsensitive))
            ft = Book::Normal;
        else if (list[i].fileName().endsWith(".html", Qt::CaseInsensitive) || list[i].fileName().endsWith(".htm", Qt::CaseInsensitive))
            ft = Book::Html;
        else if (list[i].fileName().endsWith(".pdf", Qt::CaseInsensitive))
            ft = Book::Pdf;
        else if (list[i].fileName().endsWith(".link", Qt::CaseInsensitive))
            ft = Book::Link;
        else
            ft = Book::Unkown;

        if ( ft != Book::Unkown )
        {
            if ( list[i].fileName().indexOf("Pics") != -1 )
                continue;

            QString Name = list[i].fileName();
            if (!isUserBooks)
                Name.replace(QRegExp("^[0-9 ]*"), "").replace("_", " ");

            //Create BookListItem
            Book *b = new Book(parentindex != -1 ? (*this)[parentindex] : NULL,
                                   list[i].absoluteFilePath(), list[i].absoluteFilePath(), Name, ft, isUserBooks);

            //Tell the parent it has a new child
            if (b->getParent() != NULL)
                b->getParent()->add_child(b);

            //Add this book to the list
            push_back(b);

            if ( ft == Book::Normal )
            {
                //Add confs for this book
                AddBookConfs(b, b->getPath().replace(".txt",".conf"));
            }

            if ( ft == Book::Html )
            {
                //Add confs for this book
                AddBookConfs(b, b->getPath().replace(QRegExp("\\.\\w{3,4}$"),".conf"));
            }

            if ( ft == Book::Link )
            {
                //Add confs for this book
                AddBookConfs(b, b->getPath());
            }

            if ( isUserBooks )
            {
                //b->setIsInSearch(false);
            }
            else
            {
                // call this after AddBookConfs
                b->loadFont();
            }

            if (ft == Book::Dir)
            {
                //Do the whole thing again for any dir, sending it's index in the list as the
                // Parents index of all it's children
                addAllBooks(list[i].absoluteFilePath(), isUserBooks, this->size() - 1);

                //Add confs for this directory
                AddBookConfs(b, b->getPath().append(".conf"));

            }
        }
    }
    */
}
void cmd_Up(char str[10],char strname[14])
{
	int l,i,itemp;
	char *a;
	l=strlen(strname);
	if(l>=14)
	{
		printf("文件名过长!\n");
		return;
	}
	if(strcmp(str,"cd")==0)
	{
		if(Enterdir(strname)>=0)
		{

			l=strlen(cmdhead);

		//	printf("进入目录成功!\n");
			if(strcmp(strname,"..")==0)
			{
					if(strcmp(cmdhead,"root")!=0)
					{
						i=0;
						while(cmdhead[i]!='\0')
						{

							if(cmdhead[i]=='\\')
								{
									itemp=i;

								}
							i++;
						}
						cmdhead[itemp]='\0';

					}

			}
			else if(strcmp(strname,".")!=0)
			{

				strcat(cmdhead,"\\");
				strcat(cmdhead,strname);
			}
		}
		else
		{
			printf("进入目录失败!\n");
		}

	}
	else if(strcmp(str,"create")==0)
	{
		if(create(strname))
			{
			//	printf("文件创建成功!\n");
			}
			else
			{
				printf("文件创建失败!\n");
			}

	}
	else if(strcmp(str,"read")==0)
	{
		char * buf;
		buf=ReadFile(strname);
		if(buf==NULL)
		{
			printf("读取失败!\n");
		}
		else
		{
			printf("所读文件内容:\n%s\n",buf);
		}

		free(buf);
	}
	else if(strcmp(str,"cdir")==0)
	{
		if(cdir(strname))
		{
		//	printf("文件夹创建成功!\n");
		}
		else
		{
			printf("文件夹创建失败!\n");
		}
	}
	else if(strcmp(str,"adduser")==0)
	{
		if(adduser(strname))
		{
		//	printf("文件夹创建成功!\n");
		}
		else
		{
			printf("用户创建失败!\n");
		}
	}
	else if(strcmp(str,"del")==0)
	{
		if(deletefd(strname))
		{
		//	printf("%s成功删除!\n",strname);
		}
		else
		{
			printf("%s删除失败!\n",strname);
		}


	}
	else if(strcmp(str,"write")==0)
	{
		if(mywrite(strname))
		{
				printf("%s保存成功!\n",strname);
		}
		else
		{
				printf("%s保存失败!\n",strname);
		}

	}
	
	else
	{
		printf("错误命令!\n");
	}
}