void parse_file(const char *filename, GError **error, gboolean possible_default_filename) { struct memblock mem; if (readfile(filename, &mem) < 0) { /* we don't want to display an error if this was the default file */ if (default_filename && ! strcmp(filename, default_filename)) return; g_warning(_("Failed to read '%s'.\n"), filename); if (error) { *error = g_error_new(g_quark_from_string("subsurface"), DIVE_ERROR_PARSE, _("Failed to read '%s'"), filename); } /* * We do *not* want to leave the old default_filename * just because the open failed. */ if (possible_default_filename) set_filename(filename, TRUE); return; } if (possible_default_filename) set_filename(filename, TRUE); parse_file_buffer(filename, &mem, error); free(mem.buffer); }
void VbaProject::fromPPTY(NSBinPptxRW::CBinaryFileReader* pReader) { LONG _end_rec = pReader->GetPos() + pReader->GetLong() + 4; pReader->Skip(1); // start attributes while (true) { BYTE _at = pReader->GetUChar_TypeNode(); if (_at == NSBinPptxRW::g_nodeAttributeEnd) break; switch (_at) { case 0: { std::wstring file_name = pReader->GetString2(); OOX::CPath inputPath = pReader->m_strFolder + FILE_SEPARATOR_STR + _T("media") + FILE_SEPARATOR_STR + file_name; OOX::CPath outputPath = pReader->m_pRels->m_pManager->GetDstFolder() + FILE_SEPARATOR_STR + _T("vbaProject.bin"); NSFile::CFileBinary::Copy(inputPath.GetPath(), outputPath.GetPath()); set_filename(outputPath.GetPath(), false); }break; default: break; } } pReader->Seek(_end_rec); }
//get arguments void get_arguments(int argc, char **argv) { //options if(argc>1) { FILE *f = fopen(argv[1],"rb"); if(!f) fn_alert("Erreur, le programme ne peux ouvrir le fichier:\n%s\n(passé en arguments...)",argv[1]); else { fclose(f); //Changer de mode si extention u001 const char *ext = fl_filename_ext(argv[1]); if(strcmp(ext,".u001")==0) I->rassembler->value(1); //change de mode... //mets les attributs (si changés par rassembler->value(1) rassembler_click(0); //ici, le mettre dans le textbox char str[1024]; //convertissement en chemin complet! fl_filename_absolute(str,1023,argv[1]); //update taille fichier seulement si mode division if(I->rassembler->value()==0) update_taille_fichier(str); //mets str dans I->str set_filename(str); } } else rassembler_click(0); }
void MainWindow::loadFiles(const QStringList fileNames) { if (fileNames.isEmpty()) return; char *error = NULL; QByteArray fileNamePtr; for (int i = 0; i < fileNames.size(); ++i) { fileNamePtr = fileNames.at(i).toLocal8Bit(); parse_file(fileNamePtr.data(), &error); set_filename(fileNamePtr.data(), TRUE); setTitle(MWTF_FILENAME); if (error != NULL) { showError(error); free(error); } } process_dives(FALSE, FALSE); refreshDisplay(); ui.actionAutoGroup->setChecked(autogroup); }
void QMLManager::loadDives() { qmlUiShowMessage("Loading dives..."); appendTextToLog("Loading dives..."); QString url; if (getCloudURL(url)) { qmlUiShowMessage(get_error_string()); appendTextToLog(get_error_string()); return; } clear_dive_file_data(); QByteArray fileNamePrt = QFile::encodeName(url); int error = parse_file(fileNamePrt.data()); if (!error) { report_error("filename is now %s", fileNamePrt.data()); qmlUiShowMessage(get_error_string()); appendTextToLog(get_error_string()); set_filename(fileNamePrt.data(), true); appendTextToLog(fileNamePrt.data()); } else { qmlUiShowMessage(get_error_string()); appendTextToLog(get_error_string()); } process_dives(false, false); int i; struct dive *d; DiveListModel::instance()->clear(); for_each_dive(i, d) { DiveListModel::instance()->addDive(d); }
void MainWindow::on_actionCloudstorageopen_triggered() { if (!okToClose(tr("Please save or cancel the current dive edit before opening a new file."))) return; QString filename; if (getCloudURL(filename)) { getNotificationWidget()->showNotification(get_error_string(), KMessageWidget::Error); return; } qDebug() << filename; closeCurrentFile(); int error; QByteArray fileNamePtr = QFile::encodeName(filename); error = parse_file(fileNamePtr.data()); if (!error) { set_filename(fileNamePtr.data(), true); setTitle(MWTF_FILENAME); } getNotificationWidget()->hideNotification(); process_dives(false, false); refreshDisplay(); ui.actionAutoGroup->setChecked(autogroup); }
void QMLManager::openLocalThenRemote(QString url) { clear_dive_file_data(); QByteArray fileNamePrt = QFile::encodeName(url); bool glo = prefs.git_local_only; prefs.git_local_only = true; int error = parse_file(fileNamePrt.data()); setAccessingCloud(-1); prefs.git_local_only = glo; if (error) { appendTextToLog(QStringLiteral("loading dives from cache failed %1").arg(error)); } else { // if we can load from the cache, we know that we have at least a valid email if (credentialStatus() == UNKNOWN) setCredentialStatus(VALID_EMAIL); prefs.unit_system = informational_prefs.unit_system; if (informational_prefs.unit_system == IMPERIAL) informational_prefs.units = IMPERIAL_units; prefs.units = informational_prefs.units; process_dives(false, false); DiveListModel::instance()->clear(); DiveListModel::instance()->addAllDives(); appendTextToLog(QStringLiteral("%1 dives loaded from cache").arg(dive_table.nr)); } set_filename(fileNamePrt.data(), true); appendTextToLog(QStringLiteral("have cloud credentials, trying to connect")); tryRetrieveDataFromBackend(); }
char * fs_house_keeping() { create_pbook_directory(); set_filename(); return datafile; }
void QMLManager::revertToNoCloudIfNeeded() { if (currentGitLocalOnly) { // we tried to connect to the cloud for the first time and that failed currentGitLocalOnly = false; prefs.git_local_only = true; } if (oldStatus() == NOCLOUD) { // we tried to switch to a cloud account and had previously used local data, // but connecting to the cloud account (and subsequently merging the local // and cloud data) failed - so let's delete the cloud credentials and go // back to NOCLOUD mode in order to prevent us from losing the locally stored // dives if (syncToCloud() == false) { appendTextToLog(QStringLiteral("taking things back offline since sync with cloud failed")); prefs.git_local_only = syncToCloud(); } free(prefs.cloud_storage_email); prefs.cloud_storage_email = NULL; free(prefs.cloud_storage_password); prefs.cloud_storage_password = NULL; setCloudUserName(""); setCloudPassword(""); setCredentialStatus(INCOMPLETE); set_filename(NOCLOUD_LOCALSTORAGE, true); setStartPageText(RED_FONT + tr("Failed to connect to cloud server, reverting to no cloud status") + END_FONT); } setAccessingCloud(-1); alreadySaving = false; }
t_file *new_file(t_args *a, char *path, char *name) { t_file *file; char *tmp; //acl_t ac; int i; tmp = set_filename(path, name, 0); i = 0; if ((file = (t_file*)malloc(sizeof(t_file)))) { file->next = NULL; lstat(tmp, &file->s); init_print(name, &file->s, a->mask, &file->p); /*if ((ac = acl_get_file(tmp, ACL_TYPE_EXTENDED))) { file->p.acl = 1; acl_free((void *)ac); }*/ if ((file->s.st_mode & S_IFMT) == S_IFLNK && (i = readlink(tmp, file->p.lnk, sizeof(char) * 1024))) file->p.lnk[i] = 0; //file->p.attr = listxattr(tmp, NULL, 0, i ? // XATTR_SHOWCOMPRESSION | XATTR_NOFOLLOW : 0); } free(tmp); return (file); }
void MainWindow::on_actionOpen_triggered() { QString filename = QFileDialog::getOpenFileName(this, tr("Open File"), QDir::homePath(), filter()); if (filename.isEmpty()) return; // Needed to convert to char* QByteArray fileNamePtr = filename.toLocal8Bit(); on_actionClose_triggered(); char *error = NULL; parse_file(fileNamePtr.data(), &error); set_filename(fileNamePtr.data(), TRUE); if (error != NULL) { showError(error); free(error); } process_dives(FALSE, FALSE); ui->InfoWidget->reload(); ui->globe->reload(); ui->ListWidget->reload(); ui->ListWidget->setFocus(); }
void QMLManager::loadDivesWithValidCredentials() { QString url; if (getCloudURL(url)) { QString errorString(get_error_string()); appendTextToLog(errorString); setStartPageText(RED_FONT + tr("Cloud storage error: %1").arg(errorString) + END_FONT); setAccessingCloud(-1); alreadySaving = false; return; } QByteArray fileNamePrt = QFile::encodeName(url); git_repository *git; const char *branch; int error; if (check_git_sha(fileNamePrt.data(), &git, &branch) == 0) { qDebug() << "local cache was current, no need to modify dive list"; appendTextToLog("Cloud sync shows local cache was current"); setLoadFromCloud(true); setAccessingCloud(-1); alreadySaving = false; return; } appendTextToLog("Cloud sync brought newer data, reloading the dive list"); clear_dive_file_data(); if (git != dummy_git_repository) { appendTextToLog(QString("have repository and branch %1").arg(branch)); error = git_load_dives(git, branch); } else { appendTextToLog(QString("didn't receive valid git repo, try again")); error = parse_file(fileNamePrt.data()); } setAccessingCloud(-1); if (!error) { report_error("filename is now %s", fileNamePrt.data()); const char *error_string = get_error_string(); appendTextToLog(error_string); set_filename(fileNamePrt.data(), true); } else { report_error("failed to open file %s", fileNamePrt.data()); QString errorString(get_error_string()); appendTextToLog(errorString); setStartPageText(RED_FONT + tr("Cloud storage error: %1").arg(errorString) + END_FONT); alreadySaving = false; return; } prefs.unit_system = informational_prefs.unit_system; if (informational_prefs.unit_system == IMPERIAL) informational_prefs.units = IMPERIAL_units; prefs.units = informational_prefs.units; DiveListModel::instance()->clear(); process_dives(false, false); DiveListModel::instance()->addAllDives(); appendTextToLog(QStringLiteral("%1 dives loaded").arg(dive_table.nr)); if (dive_table.nr == 0) setStartPageText(tr("Cloud storage open successfully. No dives in dive list.")); setLoadFromCloud(true); alreadySaving = false; }
/** metoda testująca zawartość klasy - na razy drukująca w konsoli kolejne pytania */ void Questions::test() { qDebug() << "POCZĄTEK TESTU" ; createXMLforTest(); set_filename("testowy.xml"); //tempReader(); loadFile(); qDebug() << "Ilość pytań: "; qDebug() << questVector.size(); qDebug() << "Ilość w poziomach: "; QVector<int> vec = countQuestionInLevels(); for (QVector<int>::iterator it = vec.begin(); it != vec.end(); ++it) qDebug() << (*it); set_description("Quiz przetworzony w teście."); set_filename("przetworzony.xml"); saveFile(); qDebug() << "KONIEC TESTU" ; }
void parse_file(const char *filename, GError **error, gboolean possible_default_filename) { struct memblock mem; #ifdef SQLITE3 char *fmt; #endif if (readfile(filename, &mem) < 0) { /* we don't want to display an error if this was the default file */ if (prefs.default_filename && ! strcmp(filename, prefs.default_filename)) return; g_warning(_("Failed to read '%s'.\n"), filename); if (error) { *error = g_error_new(g_quark_from_string("subsurface"), DIVE_ERROR_PARSE, _("Failed to read '%s'"), filename); } /* * We do *not* want to leave the old default_filename * just because the open failed. */ if (possible_default_filename) set_filename(filename, TRUE); return; } if (possible_default_filename) set_filename(filename, TRUE); #ifdef SQLITE3 fmt = strrchr(filename, '.'); if (fmt && (!strcasecmp(fmt + 1, "DB") || !strcasecmp(fmt + 1, "BAK"))) { if (!try_to_open_db(filename, &mem, error)) { free(mem.buffer); return; } } #endif parse_file_buffer(filename, &mem, error); free(mem.buffer); }
void file_chooser::set_current_name (const std::string& name) { if (name == get_current_name ()) return; impl_.set_current_name (name); set_filename (get_filename ()); }
void element_ref::operator= (element_ref &rhs) { m_model = 0L; m_color = rhs.get_color(); m_matrix = rhs.get_matrix(); m_parent = 0L; m_linkpoint = rhs.linkpoint(); set_filename(rhs.filename()); }
void ingame_savegame::create_filename() { std::stringstream stream; const std::string ellipsed_name = font::make_text_ellipsis(gamestate().classification().label, font::SIZE_NORMAL, 200); stream << ellipsed_name << " " << _("Turn") << " " << gamestate().get_starting_pos()["turn_at"]; set_filename(stream.str()); }
void bsacfa::operator= (const bsacfa& other) { if (this != &other) { set_filename(other.get_filename()); set_header(other.get_header()); set_offset(other.get_offset()); set_size(other.get_size()); } }
void read_image(int direction) { int i = 0; struct stat sb; set_filename(direction); while(stat(filename, &sb) == -1 || !read_ppm_P6(filename, &img)) { set_filename(direction); if(i == args_num) exiterr("No file is readable.\n"); i++; } last_mtime = sb.st_mtime; }
void QMLManager::saveChangesLocal() { if (unsaved_changes()) { git_storage_update_progress(true, "saving dives locally"); // reset the timers if (credentialStatus() == NOCLOUD) { if (same_string(existing_filename, "")) { char *filename = NOCLOUD_LOCALSTORAGE; if (git_create_local_repo(filename)) appendTextToLog(get_error_string()); set_filename(filename, true); GeneralSettingsObjectWrapper s(this); s.setDefaultFilename(filename); s.setDefaultFileBehavior(LOCAL_DEFAULT_FILE); qDebug() << "setting default file to" << filename; } } else if (!loadFromCloud()) { // this seems silly, but you need a common ancestor in the repository in // order to be able to merge che changes later appendTextToLog("Don't save dives without loading from the cloud, first."); return; } if (alreadySaving) { appendTextToLog("save operation already in progress, can't save locally"); return; } alreadySaving = true; bool glo = prefs.git_local_only; prefs.git_local_only = true; if (save_dives(existing_filename)) { appendTextToLog(get_error_string()); set_filename(NULL, true); setAccessingCloud(-1); prefs.git_local_only = glo; alreadySaving = false; return; } prefs.git_local_only = glo; mark_divelist_changed(false); git_storage_update_progress(false, "done with local save"); alreadySaving = false; } else { appendTextToLog("local save requested with no unsaved changes"); } }
void autosave_savegame::create_filename() { std::string filename; if (gamestate().classification().label.empty()) filename = _("Auto-Save"); else filename = gamestate().classification().label + "-" + _("Auto-Save") + gamestate().get_starting_pos()["turn_at"]; set_filename(filename); }
void replay_savegame::create_filename() { std::stringstream stream; const std::string ellipsed_name = font::make_text_ellipsis(gamestate().classification().label, font::SIZE_NORMAL, 200); stream << ellipsed_name << " " << _("replay"); set_filename(stream.str()); }
GeoLayer::GeoLayer() : Layer() { surf = NULL; fsurf[0] = NULL; fsurf[1] = NULL; color = 0xffffffff; name = "GEO"; set_filename("/geometrical layer"); is_native_sdl_surface = true; }
/***********************************************************************//** * @brief Filename constructor * * @param[in] filename File name. * * Constructs GFilename object by assigning a @p filename. ***************************************************************************/ GFilename::GFilename(const std::string& filename) { // Initialise members init_members(); // Set filename set_filename(filename); // Return return; }
Tracker::Tracker(BlockIterator& zeroth_block) : db(new ofstream()) { mote_ID = Header(zeroth_block).mote(); set_filename(mote_ID); set_first_block_reboot_id(); db->exceptions(ofstream::failbit | ofstream::badbit); db->open(filename.c_str(), ofstream::app); }
t_buddy_list::t_buddy_list(t_phone_user *_phone_user) : phone_user(_phone_user), is_subscribed(false) { t_user *user_config = phone_user->get_user_profile(); set_header("name|sip_address|subscribe"); set_separator('|'); string filename = user_config->get_profile_name() + BUDDY_FILE_EXT; string f = user_config->expand_filename(filename); set_filename(f); }
int savegame::show_save_dialog(CVideo& video, const std::string& message, bool ok_cancel) { int res = 0; std::string filename = filename_; if (ok_cancel){ gui2::tgame_save dlg(filename, title_); dlg.show(video); res = dlg.get_retval(); } else { gui2::tgame_save_message dlg(title_, filename, message); dlg.show(video); res = dlg.get_retval(); } check_filename(filename, video); set_filename(filename); check_filename(filename, video); set_filename(filename); return res; }
/** * rename from_file to to_file * works for dirs as well as files * cannot rename to something that already exists * @param from_file * @param to_file * @return 1 on success, 0 on failure */ int mfs_rename_file(char *from_file, char *to_file) { int from_dir_block; int to_dir_block; int from_dir_index; int to_dir_index; int reuse_block = -1; int reuse_index = -1; if (get_dir_ent(from_file, &from_dir_block, &from_dir_index, &reuse_block, &reuse_index) && !get_dir_ent(to_file, &to_dir_block, &to_dir_index, &reuse_block, &reuse_index)) { set_filename(mfs_file_system[from_dir_block].u.dir_data.dir_ent[from_dir_index].name, get_basename(to_file)); return 1; } return 0; }
// prefix-date.log void logger::init(LOG_LEVEL level, const std::string &path, const std::string &prefix) { std::string rpath; rpath = path; if (path[path.length()] != '/') { rpath.append("/"); } create_dir(rpath.c_str()); rpath.append(prefix); rpath.append(get_current_date()); rpath.append(".log"); set_filename(rpath); //m_file_name = rpath; //std::cout << "File: " << m_file_name << std::endl; m_show_level = level; }
uint16_t flacReader::reset( const char * filename, int alignUnit ) { if( is_valid() ) finish(); state = 0; #if !defined(FLAC_API_VERSION_CURRENT) || FLAC_API_VERSION_CURRENT <= 7 set_filename( filename ); if ( init() != FLAC__FILE_DECODER_OK ) #else // flac 1.1.3+ if ( init( filename ) != FLAC__STREAM_DECODER_INIT_STATUS_OK ) #endif { ERR( "Failed to initialize flac decoder\n" ); return( 1 ); } fName = filename; state |= named; if ( ! process_until_end_of_metadata() ) { ERR( "Failed to read flac file metadata\n" ); return( 1 ); } soundCheck( this ); unsent = 0; alignment = alignUnit ? alignUnit : fmeta.data.stream_info.channels * fmeta.data.stream_info.bits_per_sample / 8; maxFrame = fmeta.data.stream_info.max_blocksize * fmeta.data.stream_info.channels * fmeta.data.stream_info.bits_per_sample / 8; if( reserve ) delete reserve; reserve = new char[ maxFrame ]; pos.max = unread = flacHeader::bytesUncompressed( &fmeta ); surplus = ( alignment ? unread % alignment : 0 ); gcount = bufPos = 0; return 0; }