Exemple #1
0
std::string show(SrcKey sk) {
  auto func = sk.func();
  auto unit = sk.unit();
  const char *filepath = "*anonFile*";
  if (unit->filepath()->data() && unit->filepath()->size()) {
    filepath = unit->filepath()->data();
  }
  return folly::format("{}:{} in {}(id 0x{:#x})@{: >6}",
                       filepath, unit->getLineNumber(sk.offset()),
                       func->isPseudoMain() ? "pseudoMain"
                                            : func->fullName()->data(),
                       (unsigned long long)sk.getFuncId(), sk.offset()).str();
}
Exemple #2
0
void Plugin::handleStatus(const std::string& name, const std::string& value)
{
    // Checking status of changed file that is tracked by git-bin
    File f(Plugin::GIT_CONFIG);
    if (!f.exists())
    {
        logger().error("Git bin has not been initialized");
        return;
    } 
    readIndex();
    for (auto it = _index.begin(); it != _index.end(); it++)
    {
        std::cout << (*it).filepath.c_str();
        std::string filepath(Plugin::GIT_CACHE_DIR);
        filepath.append("/wf/").append((*it).uuid);
        std::cout << (*it).md5.c_str() << std::endl;
        std::cout << getFileMd5(filepath) << std::endl;
        if ((*it).md5 != getFileMd5(filepath))
        {
            std::cout << " > Modified" << std::endl;
        } 
        else
        {
            std::cout << " > Not changed" << std::endl;
        }
    }
}
void AegisubApp::MacOpenFile(const wxString &filename) {
	if (frame != NULL && !filename.empty()) {
		frame->LoadSubtitles(filename);
		wxFileName filepath(filename);
		Options.SetText(_T("Last open subtitles path"), filepath.GetPath());
	}
}
Exemple #4
0
void MainWindow::saveFile()
{
    QFileInfo filepath(path);
    if(filepath.exists()) {
        QFile file(path);
        if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
            QMessageBox::warning(this, tr("Write File"),
                                       tr("Cannot open file:\n%1").arg(path));
            return;
        }
        QTextStream out(&file);
        out << ui->textEdit->toPlainText();
        QTextStream in(&file);
        in.seek(0);
        QFileInfo fi(path);
        if (fi.suffix()=="asm"||fi.suffix()=="ASM"){
            Mips mip(in);
            instrutions=mip;
        }else if (fi.suffix()=="coe"){
            Mipscoe mipcoe(in);
            coeinst=mipcoe;
        }else {

        }
        file.close();
        emit hasSaved();
    }else
        saveasFile();
}
Exemple #5
0
int HdfsFileSystem::listDirectory(const char* pathname, std::list<std::string>& contents) const
{
	// clear the return list
	contents.erase( contents.begin(), contents.end() );

	int numEntries;
	hdfsFileInfo* fileinfo;
	if( !exists( pathname ) ) {
		errno = ENOENT;
		return -1;
	}

	// hdfs not happy if you call list directory on a path that does not exist
	fileinfo = hdfsListDirectory(m_fs,pathname, &numEntries);
	for( int i = 0; i < numEntries && fileinfo; ++i )
	{
		// hdfs returns a fully specified path name but we want to
		// only return paths relative to the directory passed in.
	    boost::filesystem::path filepath( fileinfo[i].mName );
		contents.push_back( filepath.filename().c_str() );
	}
	if( fileinfo )
		hdfsFreeFileInfo(fileinfo, numEntries);

	return 0;
}
ft_data load_ft_jzp(string fname) {
    fs::path filepath(fname);
    if (fs::exists(filepath)) {
        if (fs::is_directory(filepath)) {
            fs::path annotationfilePath(filepath / "annotations.yaml");
            if (fs::exists(annotationfilePath)) {
                ft_data data = load_ft<ft_data>(annotationfilePath.string().c_str());
                data.baseDir = filepath.string()+fs::path("/").make_preferred().native();
                return data;
            } else {
                cout<<annotationfilePath<<" does NOT exists. Return default one."<<endl;
                return ft_data();
            }
        }
        if (fs::is_regular_file(filepath) && boost::iequals(filepath.filename().string(), "annotations.yaml")) {
            ft_data data = load_ft<ft_data>(filepath.string().c_str());
            data.baseDir = filepath.parent_path().string()+fs::path("/").make_preferred().native();
            return data;
            
        } else {
            cout<<filepath<<" is not annotations.yaml. Return default one."<<endl;
            return ft_data();
        }
    }
    return ft_data();
    
}
void FileEndpoint::deliver_impl(NMEAmsg_ptr msg){
    if(recording && out_file_stream.is_open()){
        if(min_available_mbs > 0){
            boost::filesystem::path filepath(filename);
            boost::filesystem::space_info space = boost::filesystem::space(filepath);
            if(space.available != -1 && min_available_mbs != -1 && ((space.available/1024/1024)<=min_available_mbs)){
                if(!wasFull){
                    std::ostringstream oss;
                    oss << "Space available not sufficient:" << space.available/1024/1024;
                    log(oss.str());
                }
                wasFull=true;
                return;
            }
            else{
                 wasFull=false;
            }
        }
        {
            boost::mutex::scoped_lock lock(out_file_streamMutex);
            try{
                boost::posix_time::time_facet *timefacet = new boost::posix_time::time_facet(timestamp_format.c_str());
                out_file_stream.imbue(std::locale(out_file_stream.getloc(), timefacet));
                out_file_stream << msg->getReceived() << msg->to_str(checksum);//msg->data(checksum);
                out_file_stream.flush();
            }catch (std::ifstream::failure e){
                std::ostringstream oss;
                oss << "FileEndpoint Exception of File " << filename;
                log(oss.str());
                cancleReconnectTimer();
            }
        }
    }
}
Exemple #8
0
std::string show(SrcKey sk) {
  auto func = sk.func();
  auto unit = sk.unit();
  const char *filepath = "*anonFile*";
  if (unit->filepath()->data() && unit->filepath()->size()) {
    filepath = unit->filepath()->data();
  }
  return folly::sformat("{}:{} in {}(id 0x{:#x})@{: >6}{}{}",
                        filepath, unit->getLineNumber(sk.offset()),
                        func->isPseudoMain() ? "pseudoMain"
                                             : func->fullName()->data(),
                        (uint32_t)sk.funcID(), sk.offset(),
                        sk.resumed()  ? "r" : "",
                        sk.hasThis()  ? "t" : "",
                        sk.prologue() ? "p" : "");
}
Exemple #9
0
void MainMenu_OnFileOpen(HWND hwnd)
{
  OPENFILENAME ofn;
  char filename[1024];
  ZeroMemory(&ofn, sizeof(OPENFILENAME));
  ZeroMemory(filename, sizeof(filename));
  ofn.lStructSize = sizeof(OPENFILENAME);
  ofn.hwndOwner   = hwnd;
  ofn.lpstrFilter = "Brightmoon Archive (*.dat)\0*.dat\0";
  ofn.lpstrFile   = filename;
  ofn.nMaxFile    = sizeof filename;
  ofn.Flags       = OFN_EXPLORER | OFN_FILEMUSTEXIST;
  if(!GetOpenFileName(&ofn)) return;

  ListView_SetItemCountEx(g_hListWnd, 0, LVSICF_NOINVALIDATEALL);
  g_listItems.clear();

  if(!TryToOpenArchive(hwnd, filename)) {
    MessageBox(hwnd, "failed to open archive.", "error", MB_OK | MB_ICONSTOP);
    return;
  }

  do {
    MYLISTITEM item;
    PBGArchiveEntry *entry = g_archive.get()->GetEntry();
    item.entry.reset(entry);

    std::string entryname(entry->GetEntryName());
    std::vector<char> filename(entryname.begin(), entryname.end());
    filename.push_back(0);
    PathStripPath(&filename[0]);
    item.column[0] = std::string(&filename[0]);

    std::vector<char> filepath(entryname.begin(), entryname.end());
    filepath.push_back(0);
    PathRemoveFileSpecEx(&filepath[0]);
    item.column[1] = std::string(&filepath[0]);

    SHFILEINFO sfi;
    SHGetFileInfo(&filename[0], 0, &sfi, sizeof sfi,
            SHGFI_TYPENAME | SHGFI_USEFILEATTRIBUTES);
    item.column[2] = std::string(sfi.szTypeName);

    char buffer[64];
    wsprintf(buffer, "%d", entry->GetOriginalSize());
    item.column[3] = std::string(buffer);
   
    long comp_ratio = MulDiv(entry->GetCompressedSize(), 100, entry->GetOriginalSize());
    wsprintf(buffer, "%d", comp_ratio);
    item.column[4] = std::string(buffer);

    g_listItems.push_back(item);
  } while(g_archive.get()->EnumNext());
  ListView_SetItemCountEx(g_hListWnd, g_listItems.size(), LVSICF_NOINVALIDATEALL);

  EnableMenuItem(g_hMenu, ID_FILE_CLOSE  , MF_ENABLED);
  EnableMenuItem(g_hMenu, ID_FILE_EXTRACT, MF_ENABLED);
  EnableMenuItem(g_hMenu, 1, MF_BYPOSITION | MF_ENABLED);
  DrawMenuBar(hwnd);
}
Exemple #10
0
QString FileSpecification::contents() const
{
  Q_D(const FileSpecification);
  switch (format()) {
  default:
  case InvalidFileSpecification:
    Logger::logWarning(Logger::tr("Cannot read contents of invalid filespec:"
                                  "\n%1").arg(asJsonString()));
    return QString();
  case PathFileSpecification: {
    QFile file(filepath());
    if (!file.open(QFile::ReadOnly | QFile::Text)) {
      Logger::logError(Logger::tr("Error opening file for read: '%1'")
                       .arg(file.fileName()));
      return QString();
    }
    QString result = file.readAll();
    file.close();
    return result;
  }
  case ContentsFileSpecification:
    return QString(d->json["contents"].asCString());
  }

}
Exemple #11
0
void fn_rmr (inode_state& state, const wordvec& words){
   DEBUGF ('c', state);
   DEBUGF ('c', words);
   if(words.size() == 1){
      complain() << "rmr: Specify file name" << endl;
   } else if(words.size() > 2){
      complain() << "rmr: Too many arguments" << endl;
   } else if(words.at(1) == "." or words.at(1) == ".." or 
      (words.at(1).at(0) == '/' and words.at(1).length() == 1)){
      complain() << "rmr: Cannot remove directory" << endl;
   } else {
      path_name_set(words.at(1));
      const auto placeholder = state.get_cwd();
      if(words.at(1).at(0) == '/') state.setCwd(state.get_root());
      wordvec navpath = split(words[1], "/");
      string ffname = navpath.back();
      if(navpath.size() == 1){
         state.function_rmr(state.get_cwd(), ffname);
         return;
      }
      wordvec filepath(&navpath[0], &navpath[navpath.size() - 1]);
      state.function_final_rmr(ffname, filepath);
      state.setCwd(placeholder);
   }
}
Exemple #12
0
void biv::Files::ListFiles(std::vector<std::string> *files,const std::string &filePath)
{
    //std::cout<<"file path"<<filePath<<std::endl;
    namespace fs = boost::filesystem;
    fs::path filepath(filePath/*,fs::native*/);
    if(fs::exists(filepath))
    {
        fs::recursive_directory_iterator end_iter;
        for(fs::recursive_directory_iterator iter(filepath);iter!=end_iter;++iter)
        {
            try
            {
                if(fs::is_directory(*iter))
                {
                    //std::cout<<*iter<<" is directory"<<std::endl;
                    //ListFiles(files,iter->path().string());
                }
                else
                {
                    //std::cout<<*iter<<" is file"<<std::endl;
                    files->push_back(iter->path().string());
                }
            }catch(std::exception &ex)
            {
                std::cerr<<ex.what()<<std::endl;
                continue;
            }

        }

    }
}
int main(int argc, char * argv[]) {
    if (argc == 1) {
        std::cerr << "Usage: read_tree <DATAFILE> [nexus|phylip|fasta]" << std::endl;
        exit(1);
    }
    if (argc > 3) {
        std::cerr << "Expecting at most two arguments" << std::endl;
        exit(1);
    }
    std::string format;
    if (argc == 3) {
        format = argv[2];
    } else {
        format = "fasta";
    }
    std::string filepath(argv[1]);
    // treeshrew::NucleotideSequences * dna = treeshrew::create_sequences_from_filepath<treeshrew::NucleotideSequences>(filepath, format);
    // dna->write_fasta(std::cout);
    treeshrew::NucleotideSequences dna;
    std::ifstream src(filepath);
    dna.read_fasta(src);
    // treeshrew::sequenceio::read_from_filepath(dna, filepath, format);
    for (auto & seq : dna) {
        std::cout << seq->get_label() << ":";
        std::copy(seq->partials_cbegin(), seq->partials_cend(), std::ostream_iterator<double>(std::cout, ";"));
        std::cout << std::endl;
    }
}
Exemple #14
0
static void recordActRecPush(const SrcKey sk,
                             const StringData* name,
                             const StringData* clsName,
                             bool staticCall) {
  auto unit = sk.unit();
  FTRACE(2, "annotation: recordActRecPush: {}@{} {}{}{} ({}static)\n",
         unit->filepath()->data(),
         sk.offset(),
         clsName ? clsName->data() : "",
         clsName ? "::" : "",
         name,
         !staticCall ? "non" : "");

  SrcKey next(sk);
  next.advance(unit);
  const FPIEnt *fpi = sk.func()->findFPI(next.offset());
  assert(fpi);
  assert(name->isStatic());
  assert(sk.offset() == fpi->m_fpushOff);
  auto const fcall = SrcKey { sk.func(), fpi->m_fcallOff, sk.resumed() };
  assert(isFCallStar(*reinterpret_cast<const Op*>(unit->at(fcall.offset()))));
  auto const func = lookupDirectFunc(sk, name, clsName, staticCall);
  if (func) {
    recordFunc(fcall, func);
  }
}
Exemple #15
0
	void file_writer::open( const char* file_name, bool append )
	{
		if (file_stream_.is_open())
		{
			file_stream_.close();
		}

		std::ios_base::openmode open_mode_ = std::ios_base::out;
		if (!append)
		{
			open_mode_|=std::ios_base::trunc;
		}
		else
		{
			open_mode_|=std::ios_base::app;
		}

		boost::filesystem::path	filepath(file_name);
		if ( ! filepath.branch_path().empty() )
		{
			if ( ! boost::filesystem::exists(filepath.branch_path()) )
			{
				boost::filesystem::create_directories(filepath.branch_path());
			}
		}

		file_stream_.open(file_name,open_mode_);
		file_stream_ << std::left;
	}
void common::fill_graphicfiles_combobox(std::string directory, QComboBox *comboWidget)
{
    comboWidget->clear(); // delete all previous entries

    std::string str_filepath(FILEPATH+directory);
    QString filepath(str_filepath.c_str());
    QDir dir = QDir(filepath);
    if (!dir.exists()) {
        //std::cout << ">> MainWindow::fill_graphicfiles_listwidget ERROR: Directory '" << str_filepath << " does not exist. <<" << std::endl;
        exit(-1);
    }
    dir.setFilter(QDir::Files | QDir::NoSymLinks | QDir::NoDotAndDotDot);
    dir.setSorting(QDir::Size | QDir::Reversed);
    QFileInfoList list = dir.entryInfoList();

    for (int i = 0; i < list.size(); ++i) {
        QFileInfo fileInfo = list.at(i);
        if (fileInfo.fileName().length() > 30) {
            std::cout << "ERROR: file '" << fileInfo.fileName().toStdString() << "' surpasses the maximum number of file-characters (" << CHAR_FILENAME_SIZE << ")" << std::endl;
        } else {
            std::string filename = FILEPATH + directory + "/" + fileInfo.fileName().toStdString();
            QIcon icon(filename.c_str());
            comboWidget->addItem(icon, fileInfo.fileName());
        }
    }
    comboWidget->repaint();
}
int main(int argc, char* argv[])
{
	std::string filepath("CARTPOLENN");
	unsigned int nbrepi = 100;
	float gamma_ = 0.5f;
	
	float EOE = 5.0f;	//in seconds...
	SimulatorRKCARTPOLE env_(EOE);

	float lr_ = 5e-2f;//unused...
	
	if( argc>1)
	{
		lr_ = atof(argv[1]);
	}
	
	float eps_ = 0.1f;
	int dimActionSpace_ = 1;
	
	int dimStateSpace_ = 4;
	
	QFANN<float> fa_( lr_, eps_, gamma_, dimActionSpace_, filepath);
	 
	QLEARNINGXPReplay instance(nbrepi, gamma_, (Environment<float>*)(&env_), (FA<float>*)&fa_);
	
	instance.run(nbrepi);
	
	fa_.save(filepath);
}
Exemple #18
0
void
edit(char *file, char *linenum)
{
	char	msg[MSGLEN + 1];	/* message */
	char	plusnum[NUMLEN + 20];	/* line number option: allow space for wordy line# flag */
	char	*s;
	char    path[PATHLEN + 1];

	file = filepath(file, path, PATHLEN + 1);
	(void) snprintf(msg, sizeof(msg), "%s +%s %s", mybasename(editor), linenum, file);
	postmsg(msg);
	(void) snprintf(plusnum, sizeof(plusnum), lineflag, linenum);
	/* if this is the more or page commands */
	if (strcmp(s = mybasename(editor), "more") == 0 || strcmp(s, "page") == 0) {
		
		/* get it to pause after displaying a file smaller than the screen
		   length */
		(void) execute(editor, editor, plusnum, file, "/dev/null", NULL);
	}
	else if (lineflagafterfile) {
		(void) execute(editor, editor, file, plusnum, NULL);
	}
	else {
		(void) execute(editor, editor, plusnum, file, NULL);
	}
	clear();	/* redisplay screen */
}
Exemple #19
0
void BodyInfo::loadSegmentsData(){
    if (_sub_segments.size() == 0){
        CSVParser parser;
        QString filepath("../assets/CSV/input/segments_subs.csv");
        QString sub_segment_name;
        QString segment_name;
        float mass;

        parser.parseFile(filepath,";");
        if (parser.size() > 1){
            for (int i = 1; i < parser.size(); ++i) {
                sub_segment_name = parser.at(i).at(0).toLower().replace(" ","");
                segment_name =     parser.at(i).at(1).toLower().replace(" ","");
                mass = parser.at(i).at(5).toFloat();
                _sub_segments.insert(sub_segment_name,mass);
                _segments_parenting.insert(sub_segment_name,segment_name);

                if (qFind(_segments,segment_name)==_segments.end()){
                    _segments.append(segment_name);
                }
            }
            qDebug()<<"Loaded segment mass file "<<filepath;
        } else {
            qWarning()<<"Target file "<<filepath<<" not found";
        }
    }
}
AutoPtr<ArrayOf<Byte> > SystemProperties::GetFakeImage()
{
    // try{
    String filepath("/system/media/PDroid.jpeg");
    AutoPtr<IFile> imagefile;
    AutoPtr<IFileInputStream> fis;
    AutoPtr<IBitmap> bm;
    AutoPtr<IByteArrayOutputStream> helper;
    AutoPtr<ArrayOf<Byte> > bytes;
    Boolean bval;
    AutoPtr<IBitmapFactory> fact;

    FAIL_GOTO(CFile::New(filepath, (IFile**)&imagefile), _EXIT_);
    FAIL_GOTO(CFileInputStream::New(imagefile, (IFileInputStream**)&fis), _EXIT_);

    CBitmapFactory::AcquireSingleton((IBitmapFactory**)&fact);
    FAIL_GOTO(fact->DecodeStream(fis, (IBitmap**)&bm), _EXIT_);

    FAIL_GOTO(CByteArrayOutputStream::New((IByteArrayOutputStream**)&helper), _EXIT_);
    FAIL_GOTO(bm->Compress(BitmapCompressFormat_JPEG, 100 , helper, &bval), _EXIT_);
    FAIL_GOTO(helper->ToByteArray((ArrayOf<Byte>**)&bytes), _EXIT_);

_EXIT_:
    if (fis != NULL) {
        fis->Close();
    }
    return bytes;
    // }
    // catch (Exception e){
    //     Log.e(PRIVACY_TAG,"something went wrong with getting the picture!");
    //     e.printStackTrace();
    //     return NULL;
    // }
}
void FileEndpoint::space_left_cmd(Command_ptr command){
    boost::filesystem::path filepath(filename);
    boost::filesystem::space_info space = boost::filesystem::space(filepath);
    std::ostringstream oss;
    oss << (space.available/1024/1024) << "MB left on device\n";
    command->answer(oss.str(), this->shared_from_this());
}
	boost::filesystem::path rolling_file_writer::file_name_by_date( const tm& file_tm, bool cur_file )
	{
		char buffer[4096];
		sprintf( buffer, "%s_%04d%02d%02d_%02d%02d%02d"
			, settinges_.file_path.c_str()
			, file_tm.tm_year + 1900
			, file_tm.tm_mon + 1
			, file_tm.tm_mday
			, file_tm.tm_hour
			, file_tm.tm_min
			, file_tm.tm_sec
			);

		std::ostringstream out; 
		out << buffer;

		if (cur_file)
		{
			out << ".tmp";
		}
		if (!settinges_.extension_name.empty())
		{
			out << '.' << settinges_.extension_name;
		}
		boost::filesystem::path	filepath( out.str() );
		return filepath;
	}
Exemple #23
0
	///////////// Multi 2D Histogram Agent //////////////
	Multi2DHistogramAgent::Multi2DHistogramAgent (
			const double minimum1, const double maximum1, const double resolution1,
			const double minimum2, const double maximum2, const double resolution2,
			const double minimum3, const double maximum3, const double resolution3,
			std::string prefix, std::string suffix) :

		min (minimum1), max(maximum1), res(resolution1) // extents of the analysis and thickness of the slices
		{
			// set up all the histograms
			histos.clear();
			histos.resize (
					int((max-min)/res),
					Histogram2DAgent (std::string (""), 
						minimum2, maximum2, resolution2,
						minimum3, maximum3, resolution3));

			// set the name for each of the histograms
			double pos;
			for (int i = 0; i < histos.size(); i++) {
				pos = res * i + min;
				std::stringstream sstr;
				sstr.clear();
				std::string filenum;
				filenum.clear();
				sstr << pos;
				filenum = sstr.str();
				//std::string filepath (std::string("./alcohol-oxygen-water-hydrogen.distance-rdfs/rdf.") + filenum + ".dat");
				std::string filepath (prefix + filenum + suffix);
				histos[i].SetOutputFilename (filepath);
			}
		}
Exemple #24
0
/* numberセット表示/file存在確認表示 */
void cb_trace_files::cb_set_number( void )
{
	/* Traceの番号であることを表示して示す */
	cl_gts_master.cl_number.set_type_to_trace();

	/* 必要な情報に変える */
	std::string filepath( this->get_open_path( 0 ) );
	std::string dpath , head , num , ext;
	int number=-1;
	std::vector<int> nums;
	ids::path::level_from_files(
		filepath ,dpath ,head ,num ,number ,ext ,nums
	);
	if (head.empty() || nums.empty() || nums.size() <= 0) {
		fl_alert( "Not exist file about \'%s\'" ,filepath.c_str() );
		return;
	}

	/* Trace Filesウインドウ Number設定 */
	cl_gts_gui.valout_trace_num_start->value( nums.front() );
	cl_gts_gui.valout_trace_num_end->value( nums.back() );

	/* Trace Filesウインドウ 即表示 */
	cl_gts_gui.window_trace_files->flush();

	/* Numberウインドウ Listを操作可能にする */
	cl_gts_gui.selbro_number_list->activate();

	/* Numberウインドウ再構築 */
	cl_gts_master.cl_number.reset_by_number_list( nums );
}
Exemple #25
0
void FileBrowser::onChangeCartridge(const string &path) {
  string filename;
  if(QDir(path).exists()) filename = resolveFilename(path);
  else filename = path;

  string info;
  string image = sprint(nall::basename(filename), ".png");
  string patch = sprint(filepath(nall::basename(filename), config().path.patch), ".ups");

  if(file::exists(filename)) {
    if(striend(filename, ".sfc")) {
      Cartridge::Information cartinfo;
      if(cartridge.information(filename, cartinfo)) {
        info << "<small><table>";
        info << "<tr><td><b>Title: </b></td><td>" << cartinfo.name << "</td></tr>";
        info << "<tr><td><b>Region: </b></td><td>" << cartinfo.region << "</td></tr>";
        info << "<tr><td><b>ROM: </b></td><td>" << cartinfo.romSize * 8 / 1024 / 1024 << "mbit</td></tr>";
        info << "<tr><td><b>RAM: </b></td><td>";
        cartinfo.ramSize ? info << cartinfo.ramSize * 8 / 1024 << "kbit</td></tr>" : info << "None</td></tr>";
        info << "</table></small>";
      }
    } else if(striend(filename, ".st")) {
      unsigned size = file::size(filename);
      info << "<small><table>";
      info << "<tr><td><b>ROM: </b></td><td>" << size * 8 / 1024 / 1024 << "mbit</td></tr>";
      info << "</table></small>";
    }
  }

  if(info == "") info = "<small><font color='#808080'>No preview available</font></small>";
  previewInfo->setText(info);
  previewImage->setStyleSheet(string() << "background: url('" << image << "') center left no-repeat;");
  previewApplyPatch->setVisible(file::exists(patch));
}
void common::fill_files_combo(std::string directory, QComboBox* combo, bool show_none)
{
    combo->clear(); // delete all previous entries

    combo->addItem(QString("")); // for "empty"
    std::string str_filepath(FILEPATH+directory);
    QString filepath(str_filepath.c_str());
    QDir dir = QDir(filepath);
    if (!dir.exists()) {
        std::cout << ">> MainWindow::fill_files_combo ERROR: Directory '" << str_filepath << " does not exist. <<" << std::endl;
        exit(-1);
    }
    dir.setFilter(QDir::Files | QDir::NoSymLinks | QDir::NoDotAndDotDot);
    dir.setSorting(QDir::Size | QDir::Reversed);
	if (show_none == true) {
		combo->addItem(QString("None"));
	}
    QFileInfoList list = dir.entryInfoList();
    for (int i = 0; i < list.size(); ++i) {
        QFileInfo fileInfo = list.at(i);
        if (fileInfo.fileName().length() > 30) {
            std::cout << "ERROR: file '" << fileInfo.fileName().toStdString() << "' surpasses the maximum number of file-characters (" << CHAR_FILENAME_SIZE << ")" << std::endl;
        } else {
            combo->addItem(QString(fileInfo.fileName()));
        }
    }
    combo->repaint();
}
Exemple #27
0
// write buffer to disk, replace existing file
OsStatus OsConfigDb::storeBufferToFile(const char *filename, const char *buff, unsigned long buffLen)
{
    OsStatus retval = OS_FAILED;

    if (buff != NULL && buffLen > 0)
    {
        UtlString filepath(filename);
        if (OsFileSystem::exists(filepath))
        {
            OsFileSystem::remove(filepath);

            OsFile file(filepath);
            file.open(OsFile::CREATE);
            unsigned long writtenLen;
            file.write(buff, buffLen, writtenLen);
            file.close();
            if (writtenLen == buffLen)
            {
                retval = OS_SUCCESS;
            }
        }
    }

    return retval;
}
void common::fill_graphicfiles_listwidget(std::string directory, QListWidget* listWidget)
{
    listWidget->clear();

    QListWidgetItem* item;

    std::string str_filepath(FILEPATH+directory);
    QString filepath(str_filepath.c_str());
    QDir dir = QDir(filepath);
    if (!dir.exists()) {
		//std::cout << ">> MainWindow::fill_graphicfiles_listwidget ERROR: Directory '" << str_filepath << " does not exist. <<" << std::endl;
        exit(-1);
    }
    dir.setFilter(QDir::Files | QDir::NoSymLinks | QDir::NoDotAndDotDot);
    dir.setSorting(QDir::Size | QDir::Reversed);
    QFileInfoList list = dir.entryInfoList();

    for (int i = 0; i < list.size(); ++i) {
        QFileInfo fileInfo = list.at(i);
        if (fileInfo.fileName().length() > 30) {
            std::cout << "ERROR: file '" << fileInfo.fileName().toStdString() << "' surpasses the maximum number of file-characters (" << CHAR_FILENAME_SIZE << ")" << std::endl;
        } else {
            item = new QListWidgetItem;
            item->setText(fileInfo.fileName());
            std::string filename = FILEPATH + directory + "/" + fileInfo.fileName().toStdString();
            //std::cout << ">> MainWindow::fill_graphicfiles_listwidget DEBUG: filename: '" << filename << std::endl;
            QPixmap image(filename.c_str());
            image = image.copy(0, 0, image.width(), image.height());
            image = image.scaled(32, 32);
            item->setIcon(image);
            listWidget->addItem(item);
        }
    }
    listWidget->repaint();
}
Exemple #29
0
void FileNode::share(bool recursive)
{
    Q_UNUSED(recursive);
    if (m_active) return;
    m_active = true;

    if (has_metadata())
    {
        try
        {
            m_session->addTransfer(*m_atp);
        }
        catch(...)
        {
            // catch dublicate errors
        }
    }
    else
    {
        m_session->makeTransferParamsters(filepath());
    }

    m_parent->drop_transfer_by_file();
    m_session->signal_changeNode(this);
}
int main(int argc, char *argv[]) {
  // Set the python interpreter.
  setup_python(argc, argv);

  std::string filepath(argv[0]);

  // Get the path to the helper script.
  std::string helper_path;
  size_t path_end = filepath.find_last_of('\\');
  if (path_end != std::string::npos)
    helper_path = filepath.substr(0, path_end + 1);

  helper_path += "wbadminhelper.py";

  // Configures the execution of the script to take the same
  // parameters as this helper tool.
  Py_SetProgramName(argv[0]);

  PySys_SetArgv(argc, argv);

  // Executes the helper script.
  PyObject *pFileObject = PyFile_FromString(const_cast<char *>(helper_path.c_str()), "r");

  PyRun_SimpleFileEx(PyFile_AsFile(pFileObject), "wbadminhelper.py", 1);

  finalize_python();

  return 0;
}