Example #1
0
void CopyApp::doUpdate()
{
    static int partial = 0;
    if(partial == 0) {
        if(!checkPermissions(destination)) {
            startAsSudo();
            QApplication::quit();
            return;
        }
    }
    partial += 500;
    if(timeToWait != 0) {
        ui->progressBar->setValue(partial * 100 / timeToWait);
        if(partial < timeToWait) {
            QTimer::singleShot(500, this, SLOT(doUpdate()));
            return;
        }
    }
    emit currentOperation(tr("Looking for local file list info"));
    QStringList destinationFileList = processFileList(destination);
    emit currentOperation(tr("Looking for remote file list info"));
    QStringList remoteFileList = processFileList(origin);
    if(destinationFileList.isEmpty() || remoteFileList.isEmpty())
        return;
    emit currentOperation(tr("Deleting old files..."));
    bool result = true;
    result &= deleteFiles(destinationFileList, destination);
    emit currentOperation(tr("Copying new files..."));
    result &= copyFiles(remoteFileList, origin, destination);
    QString resultStr;
    if(result)
        resultStr = tr("Update finished successfully. ");
    else
        resultStr = tr("Update finished with errors. ");
    if(!appToRun.isEmpty())
        resultStr = resultStr + tr("Click ok to restart application");
    QMessageBox::information(this, tr("Update finished"), resultStr);
    if(!appToRun.isEmpty()) {
 #ifdef Q_OS_OSX
        QProcess::startDetached("open", QStringList() << QDir(destination).filePath(appToRun));
#else
        QProcess::startDetached(QDir(destination).filePath(appToRun));
#endif
    }
    QApplication::quit();
}
int main(int argc, char **argv) {
	po::options_description desc("Options");
    desc.add_options()
		("help,h",
		 "Print help messages")
      	("indir", po::value<std::string>()->required(),
		 "input directory")
		("outdir", po::value<std::string>()->required(),
		 "output directory");
	po::positional_options_description posOpt;
	posOpt.add("indir", 1);
	posOpt.add("outdir", 1);
    po::variables_map vm;

	try {
		po::store(po::command_line_parser(argc, argv)
		 		  .options(desc).positional(posOpt).run(),
                  vm);
		if (vm.count("help") ) {
			std::cout << "Usage: stacktr INDIR OUTDIR" << std::endl;
			std::cout << std::endl;
			std::cout << "  INDIR is the input directory" << std::endl;
			std::cout << "  OUTDIR is the output directory" << std::endl;
		    return 0;
		}
		po::notify(vm); //
	} catch (po::required_option &e) {
		std::cerr << "Missing a required option" << std::endl;
		return 1;
	} catch (po::error &e) {
		std::cerr << "Something wrong during the parsing" << std::endl;
		return 2;
	}

	std::cout << std::endl;

    fs::path inDir(vm["indir"].as<std::string>());
	fs::path outDir(vm["outdir"].as<std::string>());

	std::vector<fs::path> fileList;
	retrieveFileList(fileList, inDir);

	// Create folder if not exist.
	boost::system::error_code retErr;
	fs::create_directories(outDir, retErr);
	if (!retErr) {
		std::cout << "Output directory created" << std::endl;
	}

	// Transposed stack will contain as much layer as the amount of stacks.
 	size_t nLayer = fileList.size();
	processFileList(fileList, outDir, static_cast<uint16_t>(nLayer));

	waitForKeypress();

	return 0;
}
bool ConfigReader::ReadConfigs(std::string path){
    std::vector<std::string> fileList = ScanFolder(path);
    if(fileList.size() == 1 && fileList[0].compare("ERROR") == 0){
        return false;
    }

    if(fileList.size() > 0){
        if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Found %d config files\n",fileList.size()); }
        processFileList(fileList);
    }
    return true;
}
void TcpClient::slotReadyRead()
{
    while(m_pTcpSocket->bytesAvailable())
    {
        if (m_pTcpSocket->bytesAvailable() > headerMsgSize) {

            QByteArray buffer = m_pTcpSocket->read(headerMsgSize);
            QByteArray newarray;

            for (int i = 0; i < buffer.size(); i++) {
                if (buffer.at(i) == '\0')
                    continue;

                newarray.append(buffer.at(i));
            }

            int msgSize = QString(newarray.toStdString().c_str()).toInt();
            buffer.clear();
            newarray.clear();

            buffer = m_pTcpSocket->read(msgSize);
            while(buffer.size() < msgSize - headerMsgSize)
            {
                m_pTcpSocket->waitForReadyRead(3000);
                buffer.append(m_pTcpSocket->read(msgSize - buffer.size()));
            }

            for (int i = 0; i < buffer.size(); i++) {
                newarray.append(buffer.at(i));
            }

            if (msgSize != (newarray.length() + headerMsgSize)) {
                emit fileLoadingError("Данные были повреждены при скачивании. Попробуйте повторить процедуру сначала.");
                emit startFileDownloading();
                return;
            }

            QString fullMsg(newarray.toStdString().c_str());
            if (fullMsg.contains(newfileMsg) && fullMsg.contains(newentryMsg)) {
                processFileSaving(newarray);
            } else {
                processFileList(fullMsg);
            }
        } else {
            emit fileLoadingError("Сервер не содержит запрашиваемых файлов. Обратитесь за помощью скачивания файлов к преподавателю.");
            return;
        }
    }
}
Example #5
0
int main( int argc, char *argv[] )
{
    int         ch, i;

    while( (ch = getopt( argc, argv, optStr )) != -1 ) {
        if( ch == '?' ) {
            Quit( usageMsg, NULL );
        }
        doOption( ch );
    }
    displayBanner();

    if( argc < 2 ) {
        Quit( usageMsg, "No files specified\n" );
    }

    if( quietFlag ) {
        VerboseFlag = false;
    }

    for( i = 1; i < argc; i++ ) {
        if( argv[i][0] == '@' ) {
            processOptionFile( &argv[i][1] );
        } else {
            processFileList( argv[i] );
        }
    }
    if( appendFlag ) {
        if( VerboseFlag ) {
            printf( "Generated %u tags.\n", TagCount );
        }
        ReadExtraTags( fileName );
    }
    GenerateTagsFile( fileName );
    return( 0 );

} /* main */
Example #6
0
/*
 * processOptionFile - process an option file
 */
static void processOptionFile( const char *fname )
{
    FILE        *optfile;
    char        option[MAX_STR];
    char        *ptr;
    char        *cmd, *arg;
    int         ch;

    optfile = fopen( fname, "r" );
    if( optfile == NULL ) {
        printf( "Could not open option file %s\n", fname );
        return;
    }
    while( (ptr = fgets( option, sizeof( option ), optfile )) != NULL ) {
        while( isspace( *ptr ) ) {
            ptr++;
        }
        if( *ptr == '#' || *ptr == '\0' ) {
            continue;
        }
        cmd = ptr;
        while( !isspace( *ptr ) && *ptr != '\0' ) {
            ptr++;
        }
        if( *ptr == '\0' ) {
            continue;
        }
        *ptr = '\0';
        ptr++;
        while( isspace( *ptr ) ) {
            ptr++;
        }
        if( *ptr == '\0' ) {
            continue;
        }
        if( !stricmp( cmd, "file" ) ) {
            for( ;; ) {
                arg = ptr;
                while( !isspace( *ptr ) && *ptr != ',' && *ptr != '\0' ) {
                    ptr++;
                }
                ch = *ptr;
                *ptr = '\0';
                processFileList( arg );
                if( ch == '\0' ) {
                    break;
                }
                ptr++;
                while( isspace( *ptr ) || *ptr == ',' ) {
                    ptr++;
                }
                if( *ptr == '\0' ) {
                    break;
                }
            }
        } else if( !stricmp( cmd, "option" ) ) {
            WantTypedefs = false;
            WantMacros = false;
            WantAllDefines = false;
            WantUSE = false;
            while( *ptr != '\0' ) {
                if( *ptr == 'f' ) {
                    ptr++;
                    while( isspace( *ptr ) ) {
                        ptr++;
                    }
                    if( *ptr == '\0' ) {
                        break;
                    }
                    strcpy( tmpFileName, ptr );
                    ptr = tmpFileName;
                    while( !isspace( *ptr ) ) {
                        ptr++;
                    }
                    *ptr = '\0';
                    optarg = tmpFileName;
                    doOption( 'f' );
                    break;
                }
                doOption( *ptr );
                ptr++;
            }
        }

    }
    fclose( optfile );

} /* processOptionFile */