Exemplo n.º 1
0
void FileTests::testLockUnlock()
{
	// Create pre-condition
#ifndef _WIN32
	CPPUNIT_ASSERT(!system("echo someStuff > testdir/existingFile"));
#else
	CPPUNIT_ASSERT(!system("echo someStuff > testdir\\existingFile"));
#endif
	CPPUNIT_ASSERT(exists("existingFile"));

#ifndef _WIN32
	File file1("testdir/existingFile");
	File file2("testdir/existingFile");
#else
	File file1("testdir\\existingFile");
	File file2("testdir\\existingFile");
#endif

	CPPUNIT_ASSERT(file1.lock(false));
	CPPUNIT_ASSERT(!file1.lock(false));
	CPPUNIT_ASSERT(file2.lock(false));
	CPPUNIT_ASSERT(file2.unlock());
	CPPUNIT_ASSERT(file1.unlock());
	CPPUNIT_ASSERT(file1.lock());
	CPPUNIT_ASSERT(file2.lock());
	CPPUNIT_ASSERT(file2.unlock());
	CPPUNIT_ASSERT(file1.unlock());
}
TEST_F( PlatformFileSystemTests, File_Ops )
{
	std::vector< std::wstring > file_names;
	IP::File::Enumerate_Matching_Files( TEST_FILE_PATTERN, file_names );

	ASSERT_TRUE( file_names.size() == 0 );

	std::basic_ofstream< wchar_t > file1( TEST_FILE1.c_str(), std::ios_base::out | std::ios_base::trunc );
	file1 << L"test1\n";
	file1.close();

	std::basic_ofstream< wchar_t > file2( TEST_FILE2.c_str(), std::ios_base::out | std::ios_base::trunc );
	file2 << L"test2\n";
	file2.close();

	IP::File::Enumerate_Matching_Files( TEST_FILE_PATTERN, file_names );
	ASSERT_TRUE( file_names.size() == 2 );

	for ( uint32_t i = 0; i < file_names.size(); i++ )
	{
		IP::File::Delete_File( file_names[ i ] );
	}

	file_names.clear();

	IP::File::Enumerate_Matching_Files( TEST_FILE_PATTERN, file_names );
	ASSERT_TRUE( file_names.size() == 0 );
}
Exemplo n.º 3
0
int mergeGraphs(QString fileName1, QString fileName2, ATMProgressIFC *prg) {
    fileName1 = fileName1.split("\n")[0];
    QFile file1(fileName1);

    if (!file1.open(QIODevice::ReadOnly)) {
        return -1;
    }

    QDataStream fileStream1(&file1);
    NarratorGraph *graph1 = new NarratorGraph(fileStream1, prg);
    file1.close();
    fileName2 = fileName2.split("\n")[0];
    QFile file2(fileName2);

    if (!file2.open(QIODevice::ReadOnly)) {
        return -1;
    }

    QDataStream fileStream2(&file2);
    NarratorGraph *graph2 = new NarratorGraph(fileStream2, prg);
    file2.close();
    graph1->mergeWith(graph2);
    delete graph2;
    QFile file(fileName1.remove(".por") + "Merged.por");

    if (!file.open(QIODevice::ReadWrite)) {
        return -1;
    }

    QDataStream fileStream(&file);
    graph1->serialize(fileStream);
    file.close();
    delete graph1;
    return 0;
}
Exemplo n.º 4
0
std::string encrypt(std::string key, const char* input, const char* output)
{
    std::ifstream file(input);
    std::ofstream file2(output);
    std::string line;
    std::string full;

    if (file.is_open()) {
    while(getline(file,line)) {
    full+=line;
    full+='\n';
    }
    full.erase(full.length()-1,full.length());
    file.close();
    }

    std::string tmp(key);
    while (key.size() < full.size())
        key += tmp;

    for (std::string::size_type i = 0; i < full.size(); ++i)
        full[i] ^= key[i];

    file2 << full;
    file2.close();

    return full;
}
Exemplo n.º 5
0
int main(int argc, const char *argv[]){
	if(argc<3){
		std::cerr << "umerge is copyright (c) 2016 by Ed Trager and released under GPL 2.0." << std::endl;
		std::cerr << "Usage: umerge file1 file2 <optional_prefix>" << std::endl;
		exit(1);
	}
	bool hasPrefix=false;
	std::string prefix;
	if(argc==4){
		hasPrefix=true;
		prefix=argv[3];
	}
	
	std::ifstream file1(argv[1]);
	std::ifstream file2(argv[2]);
	std::string line1;
	std::string line2;
	
	while (std::getline(file1, line1)){
		
		std::getline(file2,line2);
		if(hasPrefix){
			std::cout << prefix << "\t" << line1 << "\t" << line2 << std::endl;
		}else{
			std::cout << line1 << "\t" << line2 << std::endl;
		}
	}
	return 0;
}
Exemplo n.º 6
0
int main(void)
{
	IniFile file2("test.ini");
	IniFile file3(file2);
	IniFile file4 = file3;

	int v_int;
	double v_double;
	char v_char[10];

	for (int i = 0;i < 1000;i++)
	{
		IniFile file;
		file.createIniFile("test.ini");

		file.setStringValue("Another", "Test", "Succeed");
		file.setIntegerValue("Another", "Count", i);
		int count;
		file.getIntegerValue("Another", "Count", count);
		std::cout << count << std::endl;
	}

	file2.getStringValue("General", "Language", v_char,10);
	file3.getIntegerValue("General", "Age", v_int);
	file4.getDoubleValue("Info", "Cost", v_double);
	std::cout << v_char << std::endl;
	std::cout << v_int << std::endl;
	std::cout << v_double << std::endl;

	file2.setDoubleValue("Test", "Double", 478.1231);
	
	system("pause");
	return 0;
}
Exemplo n.º 7
0
int main (int argc, char *argv[])
{
	QApplication app(argc, argv);

	VCard vcard;
	const VCard *vc2 = VCardFactory::vcard("*****@*****.**");
	if ( vc2 )
		vcard = *vc2;

	QFile file2 ( "vcard-out.xml" );
	file2.open ( IO_WriteOnly );
	QTextStream out ( &file2 );

	QDomDocument doc2;
	doc2.appendChild( vcard.toXml ( &doc2 ) );

	out << doc2.toString(8);

	if ( vcard.isEmpty() )
		qWarning("VCard is empty!!!");

	qWarning ( "%s", doc2.toString(8).latin1() );*/

	return 0;
}
int main(){
	CRNG rng;
	scalar_t m1[2][1] = {0, 0};
	Mat mean_matrix(2, 1, CV_64FC1, m1);
	scalar_t m2[2][2] = {small_deviation, 0, 0, small_deviation};
	Mat sigma_matrix(2, 2, CV_64FC1, m2);

	CCSV file1(".\\Matlab\\test1.csv");
	CCSV file2(".\\Matlab\\test2.csv");
	for(int i = 0; i < 1000; ++i){
		
		vector<scalar_t> mean(2);    mean[0] = 0;    mean[1] = 0;
		vector<scalar_t> d(2);    d[0] = 0;    d[1] = 0;
		vector<vector<scalar_t> > body(100);
		for(int j = 0; j < 100; ++j){
			
			vector<scalar_t> stem = get(mean_matrix, sigma_matrix, rng);
			mean[0] += stem[0];    mean[1] += stem[1];
			body[j] = stem;
		}
		mean[0] /= 100;    mean[1] /= 100;
		file1.put(mean);

		for(int j = 0; j < 100; ++j){
			d[0] += (body[j][0]-mean[0])*(body[j][0]-mean[0]);    d[1] += (body[j][1]-mean[1])*(body[j][1]-mean[1]);
		}
		d[0] /= 100;    d[1] /= 100;
		file2.put(d);
	}

}
Exemplo n.º 9
0
void MainWindow::checkAndGenerateNecessaryFile()
{
  QDir dir;
  QString path = dir.absolutePath();
  
  if(!dir.exists(path + "/data"))
    dir.mkdir(path + "/data");
  
  if(!dir.exists(path + "/data/.temp"))
    dir.mkdir(path + "/data/.temp");
  
  if(!dir.exists(path + "/data/.temp/VirtualFence"))
    dir.mkdir(path + "/data/.temp/VirtualFence");
  
  QFile file;
  path = path + "/data/.temp/VirtualFence/";
  if (!file.exists(path + "config.ini"))
  {
    QString fileName = path + "config.ini";
    QFile file2(fileName);
    if (!file2.open(QFile::WriteOnly | QFile::Text))
    {
      QMessageBox::warning(this, tr("Create ini file"),
                           tr("Cannot create ini file %1:\n%2.")
                           .arg(fileName)
                           .arg(file.errorString()));
      return;
    }
    
    //write the ini file content here
    QTextStream out(&file2);         
    helper::writeDefautlVirtualFecingIni(out);
    file2.close();     
  }
}
Exemplo n.º 10
0
int main(int argc, char **argv) {

 try {

  // write
  std::map<std::string, int> m = { {"a",1}, {"b",2} };
  std::map<std::string, std::vector<double>> mv = { {"a",{1.0, 2.0}}, {"b",{2.0, 3.0, 4.0}} };

  {
   h5::file file1("test_map.h5", H5F_ACC_TRUNC);
   h5::group top1(file1);
   h5_write(top1, "map_int", m);
   h5_write(top1, "map_vec", mv);
  }

  // read
  std::map<std::string, int> mm = { {"c",1} };
  std::map<std::string, std::vector<double>> mmv = { {"c",{1.0}} };

  h5::file file2("test_map.h5", H5F_ACC_RDONLY);
  h5::group top2(file2);
  h5_read(top2, "map_int", mm);
  h5_read(top2, "map_vec", mmv);

  for (auto const & val: mm) std::cout << val.first << " " << val.second << std::endl;
  for (auto const & val: mmv) {
    std::cout << val.first << std::endl;
    for (auto const & x: val.second) std::cout << x << std::endl;
  }

 }
 TRIQS_CATCH_AND_ABORT;
}
Exemplo n.º 11
0
QString ELFToA43(const QByteArray &elf, QString &error) {
// 	error = "4";
	QString f_in = QDir::tempPath() + "/test.dump";
	QString f_out = QDir::tempPath() + "/test.a43";
	QFile file(f_in);
	if (!file.open(QFile::WriteOnly | QFile::Truncate)) {
		error = QString("Cannot open '%1' for writting.").arg(f_in);
		return "";
	}

	file.write(elf);
	file.close();

	QProcess objdump;
	QSettings settings("QSimKit", "MSP430");
	objdump.start(settings.value("objcopy", "msp430-objcopy").toString(), QStringList() << "-O" << "ihex" << f_in << f_out);
	if (!objdump.waitForStarted()) {
		error = QString("'msp430-objcopy' cannot be started. Is msp430-gcc installed and is msp430-objcopy in PATH?");
		return "";
 	}
 
	if (!objdump.waitForFinished()) {
		error = QString("'msp430-objcopy' did not finish properly.");
		return "";
	}

	QFile file2(f_out);
	if (!file2.open(QIODevice::ReadOnly | QIODevice::Text)) {
		error = QString("Cannot open '%1' for reading.").arg(f_out);
		return "";
	}

	return file2.readAll();
}
Exemplo n.º 12
0
void
TestLocalXform::testIOHDF5()
{
    USING_NK_NS
    USING_NKHIVE_NS

    LocalXform xform(vec3d(0.1, 0.2, 0.5));

    LocalXform xform2;

    CPPUNIT_ASSERT(xform != xform2);

    remove("testingHDF5.hv");                                   
    VolumeFile file("testingHDF5.hv", VoidFile::WRITE_TRUNC);  
    
    HDF5Group root_group;                                       
    root_group.open(file.m_id, NK_NS::String("/"));                
    HDF5Id root_group_id = root_group.id();                      
    
    xform.write(root_group_id);
    
    file.close();                                               
    
    VolumeFile file2("testingHDF5.hv", VoidFile::READ_ONLY);    
    HDF5Group root_group2;                                      
    root_group2.open(file2.m_id, NK_NS::String("/"));              
    HDF5Id root_group_id2 = root_group2.id();                    
    
    xform2.read(root_group_id2);
    CPPUNIT_ASSERT(xform == xform2);
    
    file2.close();                                              
    remove("testingHDF5.hv");
}
Exemplo n.º 13
0
void Dialog::clear()
{
    QFile file("info.ifo");
    int temp = 0;
    if(file.open(QIODevice::ReadOnly | QIODevice::Text))
    {
        QTextStream txtInput(&file);
        int temp1;
        while(!txtInput.atEnd())
        {
            txtInput >> temp1;
            temp++;
        }
        file.close();
        QFile file2("info.ifo");
        if(file2.open(QIODevice::WriteOnly | QIODevice::Text))
        {
            QTextStream txtOutput(&file2);
            temp--;
            for(int i = 0; i < temp; ++i)
            {
                qDebug() << temp;
                txtOutput << 0 << " ";
            }
        }
    }
Exemplo n.º 14
0
int		main(int argc, char **argv)
{
	ExpertSystem	*e = new ExpertSystem();
	std::string		line;

	if ( argc == 2 )
	{
		std::ifstream	file( argv[1] );
		while ( std::getline( file, line ) )
		{
			if ( line[0] != '#' )
			{
				e->parsing_init_fact(line);
				e->parsing_init_queries(line);
			}
		}
		std::ifstream	file2( argv[1] );
		while ( std::getline( file2, line ) )
		{
			if ( line[0] != '#' )
				e->check_syntax_rule(line);
		}
		e->expert();
		delete(e);
	}
	else
		return (-1);
	return (0);
}
Exemplo n.º 15
0
bool compareFiles(const QString& filename1, const QString& filename2)
{
	// Compare sizes
	QFile file1(filename1);
	QFile file2(filename2);
	if (file1.size() != file2.size()) {
		return false;
	}

	// Compare contents
	bool equal = true;
	if (file1.open(QFile::ReadOnly) && file2.open(QFile::ReadOnly)) {
		while (!file1.atEnd()) {
			if (file1.read(1000) != file2.read(1000)) {
				equal = false;
				break;
			}
		}
		file1.close();
		file2.close();
	} else {
		equal = false;
	}
	return equal;
}
Exemplo n.º 16
0
void read_dssz2()
{
   TTree *tr = new TTree("tree","tree");
   TTree *tr2 = new TTree("tree2","tree2");

   ifstream file("WP-CMS-CT-DSSZ.dat");
   ifstream file2("All_Wplus_EPS09.dta");
   float val, val0=1;
   int idx2;
   tr->Branch("val",&val,"val/F");
   tr->Branch("val0",&val0,"val0/F");
   tr2->Branch("val",&val,"val/F");
   tr2->Branch("val0",&val0,"val0/F");
   tr2->Branch("idx2",&idx2,"idx2/I");
   int i=0;

   while (file.good())
   {
      file >> val;
      if (!file.good()) break;
      if (i==0) cout << val;
      if (i==1) cout << " " << val << endl;
      if (i==1) val0=val;
      if (i>50) i=-1;
      tr->Fill();
      i++;
   }

   int i2=0;

   while (file2.good())
   {
      file2 >> val;
      if (!file2.good()) break;
      i2++;
      if (i==0) cout << val;
      if (i2==2 || i2==3) continue;
      if (i==1) cout << " " << val << endl;
      if (i==1) val0=val;
      if (i2>4&&i2<=56) continue;
      idx2 = translate(i-1)+1;
      cout << i << " " << i2 << " " << idx2 << " " << val0 << " " << val << endl;
      if (i>50) {cout << i2 << endl;i=-1; i2=0;}
      tr2->Fill();
      i++;
   }

   TCanvas *c1 = new TCanvas(); c1->cd();
   tr->Draw("Entry$>>h0(520,0,520)","(val>10.)*((val-val0)/val0)", "hist");
   h0->SetFillColor(kRed);
   // tr2->Scan("TMath::Floor(Entry$/52)*52+idx2+1:Entry$:idx2:TMath::Floor(Entry$/52)","(val>10.)");
   tr2->Draw("TMath::Floor(Entry$/52)*52+idx2>>h2(520,0,520)","(val>10.)*((val-val0)/val0)", "hist same");
   h2->SetFillStyle(3003);
   h2->SetFillColor(kGreen);
   tr->Draw("Entry$>>h1(520,0,520)","(val<10.)*0.02", "hist same");
   h1->SetFillColor(kBlue);
   TCanvas *c2 = new TCanvas(); c2->cd();
   tr->Draw("(val-val0)/val0","val>10.");
}
Exemplo n.º 17
0
void QPolyTime::parse(QString& filePath)
{
    if(filePath.isEmpty() == true)
    {
        return ;
    }

    QFile file(filePath);

    if(file.open(QIODevice::ReadOnly) == false)
    {
        return ;
    }

    QTextStream stream(&file);
    stream.setCodec("UTF-8");
    QStringList list;
    while(stream.atEnd() == false)
    {
        QString line1 = stream.readLine().trimmed();
        list.append(convert(line1));
        //qDebug()<<convert(line);
    }

    file.close();

    QString newfilePath = filePath;
    newfilePath.replace("timeTable.txt", "tracePoints.lua");
    QFile file2(newfilePath);

    if(file2.open(QIODevice::WriteOnly) == false)
    {
        qDebug()<<"open failed";
        return ;
    }

    QString str;
    str += QString("function tracePoints.elapse(cityID1, cityID2)\n");
    str += QString("    local funName = \"elapse_\" .. tostring(cityID1) .. \"_\" .. tostring(cityID2)\n ");
    str += QString("    if cityID1 > cityID2 then\n");
    str += QString("        funName = \"elapse_\" .. tostring(cityID2) .. \"_\" .. tostring(cityID1)\n ");
    str += QString("    end\n");
    str += QString("    if tracePoints[funName] == nil then\n");
    str += QString("        return nil\n");
    str += QString("    end\n");
    str += QString("    return tracePoints[funName]();\n");
    str += QString("end\n\n");

    QTextStream stream2(&file2);
    stream2.setCodec("UTF-8");
    stream2<<QString("tracePoints = {}\n");
    foreach(QString single, list)
    {
        stream2<<single<<"\n";
    }
    stream2<<str;
    file2.close();
    qDebug()<<"ok";
}
Exemplo n.º 18
0
bool init_unit_test() {
	std::ofstream file1("mapgen_1.csv");
	file1 << csv1;

	std::ofstream file2("mapgen_2.csv");
	file2 << csv2;

	return true;
}
Exemplo n.º 19
0
void Backend::writeUserLastDesktop(QString user, QString desktop){
  QFile file2( Backend::getUserHomeDir(user) + "/.lastlogin" );
  if(!file2.open(QIODevice::Truncate | QIODevice::WriteOnly | QIODevice::Text)){
    Backend::log("PCDM: Unable to save last login data for user:"+user);	  
  }else{
    QTextStream out(&file2);
    out << desktop;
    file2.close();
  }
}
Exemplo n.º 20
0
bool MaItem::load(const QString& filename)
{
	bool res = false;

	if (!filename.isEmpty())
		mFilename = filename;

	mRelPath.clear();
	mRelPath = relPath();
#ifdef _DEBUG
//	qDebug() << absPath();
#endif  // _DEBUG

	QFile file(absPath());
	if (file.open(QIODevice::ReadOnly))
	{
		QTextStream in(&file);
		in.setCodec("UTF-8");
		parseConfigLine(in.readLine());
		if (mIsEncrypted)
		{
			QByteArray s = in.readAll().toAscii();
			_engine->encrypt(s);
			QString s2(s);
			int i = s2.indexOf("\n");
			if (i > -1)
			{
				mCaption = s2.left(i);
				mNotes = s2.right(s2.length() - i - 1);
			}
		}
		else
		{
			mCaption = in.readLine();
			mNotes = in.readAll();
		}
		file.close();
		res = true;
	}

	// Loading the password from the password file:
	QFile file2(absPathToFilename(kPathwordFilename));
	if (file.exists() && file2.open(QIODevice::ReadOnly))
	{
		QTextStream in(&file2);
		in.setCodec("UTF-8");
		QByteArray ba = in.readAll().toAscii();
		QByteArray salt(QString(_engine->passwordEncryptionSalt()).toAscii());
		_engine->encrypt(ba, _engine->passwordEncryptionKey().toAscii(), salt);
		mPassword = ba;
		mPasswordDirty = false;
	}

	return res;
}
Exemplo n.º 21
0
AboutDialog::AboutDialog(QWidget *parent) :
    QDialog(parent)
{

    mTabWidget = new QTabWidget;
    mAboutHeader= new AboutHeader;
    mContributorTextEdit = new QTextBrowser;
    mLicenceTextEdit = new QTextBrowser;
    QVBoxLayout * layout = new QVBoxLayout;
    layout->setContentsMargins(0,0,0,0);

    mLicenceTextEdit->setReadOnly(true);
    mContributorTextEdit->setReadOnly(true);

    mContributorTextEdit->setOpenExternalLinks(true);

    QFile file(":license.html");
    file.open(QIODevice::ReadOnly);
    mLicenceTextEdit->setText(file.readAll());

    file.close();

    QFile file2(":contributor.html");
    file2.open(QIODevice::ReadOnly);
    mContributorTextEdit->setText(file2.readAll());
    file2.close();


    layout->addWidget(mAboutHeader);
    layout->addWidget(mTabWidget);

    mTabWidget->addTab(mContributorTextEdit,"Contributeur");
    mTabWidget->addTab(mLicenceTextEdit,"Licence");


    setLayout(layout);
    setWindowTitle("A propos...");
    mKonamiValid = 0;
    mKonamiCodes.append(Qt::Key_Up);
    mKonamiCodes.append(Qt::Key_Up);
    mKonamiCodes.append(Qt::Key_Down);
    mKonamiCodes.append(Qt::Key_Down);
    mKonamiCodes.append(Qt::Key_Left);
    mKonamiCodes.append(Qt::Key_Right);
    mKonamiCodes.append(Qt::Key_Left);
    mKonamiCodes.append(Qt::Key_Right);
    mKonamiCodes.append(Qt::Key_B);
    mKonamiCodes.append(Qt::Key_A);

    mTabWidget->setFocusPolicy(Qt::NoFocus);
    setFocus();

    setFixedWidth(mAboutHeader->width());

}
Exemplo n.º 22
0
void TDirectoryDiffDocument::DoCompareDirectories(TDirectory& directory1, TDirectory& directory2)
{
	directory1.Open();
	directory2.Open();
	
	// iterate through directory 1
	int	count = directory1.GetFileCount();
	for (int i = 0; i < count; i++)
	{
		TString	name;
		bool	isDirectory;
		
		directory1.GetFile(i, name, isDirectory);
		if (isDirectory)
		{
			// ignore CVS, subversion and directories
			if (Tstrcmp(name, "CVS") != 0 && Tstrcmp(name, ".svn") != 0 && Tstrcmp(name, ".git") != 0)
			{
				TDirectory	subDir2(directory2, name);
				
				if (subDir2.Exists())
				{
					TDirectory	subDir1(directory1, name);
					DoCompareDirectories(subDir1, subDir2);
				}
			}
		}
		else
		{
			TFile	file2(directory2, name);
			
			if (file2.Exists())
			{
				TFile	file1(directory1, name);
				
				// ignore class files and compiled python files
				const char* extension = file1.GetFileExtension();
				if (Tstrcmp(extension, "class") != 0 && Tstrcmp(extension, "pyc") != 0)
				{
					if (!TFile::FilesAreEqual(file1, file2, true))
					{
						TString* path = new TString;;
						
						TFile::ComputeRelativePath(file1.GetPath(), fDirectory1.GetPath(), *path);
						fDiffList.InsertLast(path);
					}
				}
			}
		}
	}

	directory1.Close();
	directory2.Close();
}
Exemplo n.º 23
0
bool QUtf8Convert::checkBOM(QString filePath)
{
    if(filePath.isEmpty() == true)
    {
        return false;
    }

    QFile file(filePath);

    if(file.open(QIODevice::ReadOnly) == false)
    {
        return false;
    }

    QDataStream stream(&file);
    //EF BB BF
    unsigned char a1 = 0;
    unsigned char a2 = 0;
    unsigned char a3 = 0;

    unsigned char b1 = 239;
    unsigned char b2 = 187;
    unsigned char b3 = 191;

    stream>>a1;
    stream>>a2;
    stream>>a3;

    //qDebug()<<a1<<a2<<a3;

    bool result = false;
    if( a1 == b1 && a2 == b2 && a3 == b3 )
    {
        result = true;

        QString filePath2 = filePath + QString(".lua");
        QFile file2(filePath2);

        if(file2.open(QIODevice::WriteOnly) == false)
        {
            return false;
        }

        QDataStream stream2(&file2);

        while(stream.atEnd() == false)
        {
            unsigned char t;
            stream>>t;
            stream2<<t;
        }

        file2.close();
    }
Exemplo n.º 24
0
void SEGSAdminTool::check_db_exist(bool on_startup)
{
    QPixmap check_icon(":icons/Resources/check.svg");
    QPixmap alert_triangle(":icons/Resources/alert-triangle.svg");
    ui->output->appendPlainText("Checking for existing databases...");
    qDebug() << "Checking for existing databases...";
    QFileInfo file1("segs");
    QFileInfo file2("segs_game");
    if(on_startup) // Runs this check on startup or for checking creation in other methods
    {
        if(file1.exists() && file2.exists())
        {
            ui->output->appendPlainText("SUCCESS: Existing databases found!");
            ui->icon_status_db->setPixmap(check_icon);
            ui->runDBTool->setText("Create New Databases");
            ui->runDBTool->setEnabled(true);
            ui->createUser->setEnabled(true);
        }
        else
        {
            ui->output->appendPlainText("WARNING: Not all databases were found. Please use the server setup to your left");
            ui->icon_status_db->setPixmap(alert_triangle);
            ui->createUser->setEnabled(false); // Cannot create users until DB's created
        }
    }
    else
    {
        if(file1.exists() || file2.exists())
        {
            QMessageBox db_overwrite_msgBox;
            //db_overwrite_msgBox.setGeometry(266,125,1142,633);
            db_overwrite_msgBox.setText("Overwrite Databases?");
            db_overwrite_msgBox.setInformativeText("All existing data will be lost, this cannot be undone");
            db_overwrite_msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
            db_overwrite_msgBox.setDefaultButton(QMessageBox::No);
            db_overwrite_msgBox.setIcon(QMessageBox::Warning);
            int confirm = db_overwrite_msgBox.exec();
            switch (confirm) {
            case QMessageBox::Yes:
                SEGSAdminTool::create_databases(true);
                break;
            case QMessageBox::No:
                break;
            default:
                break;
            }
        }
        else
        {
            SEGSAdminTool::create_databases(false);
        }
    }
}
Exemplo n.º 25
0
void csv::boundary_scan(){

    FILE *fp2;

    fp2 = fopen("script_jtag2.txt", "w");

    fprintf(fp2,"cable jz47xx\n");
    fprintf(fp2,"detect\n");
    fprintf(fp2,"instruction CFG_OUT 000100 BYPASS\n");
    fprintf(fp2,"instruction CFG_IN 000101 BYPASS\n");
    fprintf(fp2,"instruction JSTART 001100 BYPASS\n");
    fprintf(fp2,"instruction JPROGRAM 001011 BYPASS\n");
    fprintf(fp2,"pld load /root/Generador_Script/pulsa.bit\n");
    fprintf(fp2,"reset\n");
    fprintf(fp2,"quit");
    fclose(fp2);
    system("jtag script_jtag2.txt");

    QStringList pin;
    QString signals_name1;
    QString line;

    QFile file(dir_csv.toAscii().data());// Lectura CSV
    if (!file.open(QIODevice::ReadOnly | QIODevice::Text)){
        QMessageBox::about(this,"Error", "Error opening CSV file");
        return;
    }
    QTextStream in(&file);

    QFile file2("register_out.txt");
    if (!file2.open(QIODevice::ReadOnly | QIODevice::Text)){
        QMessageBox::about(this,"Error", "Error opening UrJtag file");
        return;
    }

    while (!in.atEnd()) {
       line = in.readLine();
       if(line.contains("#",Qt::CaseInsensitive)!=true && line.isEmpty()!=true){
            pin=line.split(",");
            if(pin[4]=="INPUT" || pin[4]=="OUTPUT" || pin[4]=="BIDIR"){
              signals_name1=signals_name1.append(pin[1]+',');
            }
        }
    }

   signals_name=signals_name1.split(',');

    QTextStream in2(&file2);
    line=in2.readAll();
    remove("register_out.txt");
    registers=line.split("\n");
    remove("script_jtag2.txt");
}
MetalinkEditor create_test1()
{
    MetalinkEditor editor;
    MetalinkSource src(wxT("http://example.com/"));
    MetalinkFile file1(wxT("test1"));
    MetalinkFile file2(wxT("test2"));
    file1.add_source(src);
    file2.add_source(src);
    editor.add_file(file1);
    editor.add_file(file2);
    return editor;
}
Exemplo n.º 27
0
bool CompareFiles(const std::string& filename1, const std::string& filename2)
{
    std::ifstream file1(filename1);
    std::ifstream file2(filename2);
    
    std::istreambuf_iterator<char> begin1(file1);
    std::istreambuf_iterator<char> begin2(file2);
    
    std::istreambuf_iterator<char> end;
    
    return range_equal(begin1, end, begin2, end);
}
Exemplo n.º 28
0
int main(int argc, char *argv[]) {
	float proba[27][27];
	for (int i=0;i<27;i++)
		for (int j=0;j<27;j++)
			proba[i][j] = 0;
	int numb[27] = {0};
	std::string line;
	std::ifstream file("human_names.txt", std::ios::in);
	if (file) {
		while (std::getline(file, line)) {
			numb[0]++;
			int asciiP = 0;
			for (unsigned int i=0;i<line.size();i++) {
				int ascii = line[i];
				if (ascii < 97)
					ascii += 32;
				ascii -= 96;
				if (i != line.size()-1)
					numb[ascii]++;
				proba[asciiP][ascii]++;
				asciiP = ascii;
			}
		}
		file.close();
	}
	std::ofstream file2("human_analyze.h", std::ios::out | std::ios::trunc);
	for (int i=0;i<27;i++)
		for (int j=0;j<27;j++)
			if (numb[i] != 0)
				proba[i][j] /= numb[i];
	for (int i=0;i<27;i++)
		for (int j=0;j<27;j++) {
			if (j > 0)
				proba[i][j] += proba[i][j-1];
		}
	if (file2) {
		file2 << "static const float tableau[27][27] = {\n";
		for (int i=0;i<27;i++) {
			if (i > 0)
				file2 << ",";
			file2 << "{";
			for (int j=0;j<27;j++) {
				if (j > 0)
					file2 << ",";
				file2 << proba[i][j];
			}
			file2 << "}\n";
		}
		file2 << "};";
		file2.close();
	}
	return 0;
}
Exemplo n.º 29
0
void cpuInfo::getOsInfo(void)
{
    // setting host name aka user of the system
    QFile file("/etc/hostname");
    if(file.open(QIODevice::ReadOnly))
    {
        QTextStream readFile(&file);
        QString userName = readFile.readLine();
        userName = "******" + userName + "</h2></b></u>";
        user->setText(userName);
        file.close();
    }

    QFile file1("/etc/lsb-release");
    if(file1.open(QIODevice::ReadOnly))
    {
        // Setting Operating System Name
        QTextStream readFile(&file1);
        QString temp = readFile.readLine();
        QStringList list = temp.split("=");
        temp = list.at(1);
        temp = "<b><h2>"  + temp + "</b></h2>";
        operatingSys->setText(temp);

        // Setting release version
        temp = readFile.readLine();
        list.clear();
        list = temp.split("=");
        QString temp2;
        temp2 = "    Release " + list.at(1);

        temp = readFile.readLine();
        list.clear();
        list = temp.split("=");
        temp2 = temp2 + " (" + list.at(1) + ")";
        release->setText(temp2);
        file1.close();
    }

    // setting kernel version used
    QFile file2("/proc/version");
    if(file2.open(QIODevice::ReadOnly))
    {
        QTextStream readFile(&file2);
        QString temp = readFile.readLine();
        QStringList list = temp.split(" ");
        temp = "    Kernel " + list.at(0) + "  " + list.at(2);
        kernelInfo->setText(temp);
        file2.close();
    }

}
Exemplo n.º 30
0
void testMapFile()
{
	NS_STDEXT::MapFileRW file("__TestMapFiel__.txt");

	file.resize(0x100);
	char* psz = (char*)file.map(0, 32);
	strcpy(psz + 2, "hello, world!");
	file.flush(psz, 32);
	
	NS_STDEXT::MapFileRO file2("__TestMapFiel__.txt");
	psz = (char*)file2.map(0, 32);
	puts(psz + 2);
}