/* compare strings that contains time periods in format 00:00:00 */ static int CompareTimeString(const wxString& first,const wxString& second) { long dtFirst,dtSecond; wxString hours,minutes,seconds; long lHours,lMinutes,lSeconds; //converting the first string to long value hours = first.BeforeFirst(':'); seconds = first.AfterLast(':'); minutes = first.AfterFirst(':').BeforeFirst(':'); hours.ToLong(&lHours); minutes.ToLong(&lMinutes); seconds.ToLong(&lSeconds); dtFirst = lSeconds + lMinutes * 60 + lHours * 3600; //converting the second string hours = second.BeforeFirst(':'); seconds = second.AfterLast(':'); minutes = second.AfterFirst(':').BeforeFirst(':'); hours.ToLong(&lHours); minutes.ToLong(&lMinutes); seconds.ToLong(&lSeconds); dtSecond = lSeconds + lMinutes * 60 + lHours * 3600; if(dtFirst < dtSecond) { return reverseCompareOrder ? 1 : -1 ; } if(dtSecond < dtFirst) { return reverseCompareOrder ? -1 : 1 ; } return 0; }
void Thesaurus::SetFiles(wxString idxpath, const wxString datpath) { delete m_pT; m_pT = NULL; if ( wxFile::Exists(idxpath) && wxFile::Exists(datpath) ) { m_pT = new wxThes( idxpath, datpath ); } else { Manager::Get()->GetLogManager()->Log(_T("SpellChecker: Thesaurus files '") + idxpath + _T("' not found!")); if (!wxDirExists(idxpath.BeforeLast(wxFILE_SEP_PATH)) || !wxDirExists(datpath.BeforeLast(wxFILE_SEP_PATH))) return; // path does not exist, silence invalid directory warnings wxString altIdx = wxFindFirstFile(idxpath.BeforeLast(wxT('.')) + wxT("*.idx"), wxFILE); // "*_v2.idx" if (altIdx.IsEmpty()) // try again with more wildcards { altIdx = idxpath.AfterLast(wxFILE_SEP_PATH).BeforeLast(wxT('.')) + wxT("*.idx"); altIdx.Replace(wxT("_"), wxT("*")); altIdx.Replace(wxT("-"), wxT("*")); altIdx = wxFindFirstFile(idxpath.BeforeLast(wxFILE_SEP_PATH) + wxFILE_SEP_PATH + altIdx, wxFILE); } if (altIdx.IsEmpty()) // try to find the thesaurus of a related language (something is better than nothing) { altIdx = idxpath.AfterLast(wxFILE_SEP_PATH); altIdx.Replace(wxT("_"), wxT("*")); altIdx.Replace(wxT("-"), wxT("*")); altIdx = altIdx.BeforeLast(wxT('*')) + wxT("*.idx"); altIdx = wxFindFirstFile(idxpath.BeforeLast(wxFILE_SEP_PATH) + wxFILE_SEP_PATH + altIdx, wxFILE); } wxString altDat = wxFindFirstFile(datpath.BeforeLast(wxT('.')) + wxT("*.dat"), wxFILE); // "*_v2.dat" if (altDat.IsEmpty()) // try again with more wildcards { altDat = datpath.AfterLast(wxFILE_SEP_PATH).BeforeLast(wxT('.')) + wxT("*.dat"); altDat.Replace(wxT("_"), wxT("*")); altDat.Replace(wxT("-"), wxT("*")); altDat = wxFindFirstFile(datpath.BeforeLast(wxFILE_SEP_PATH) + wxFILE_SEP_PATH + altDat, wxFILE); } if (altDat.IsEmpty()) // try to find the thesaurus of a related language (something is better than nothing) { altDat = datpath.AfterLast(wxFILE_SEP_PATH); altDat.Replace(wxT("_"), wxT("*")); altDat.Replace(wxT("-"), wxT("*")); altDat = altDat.BeforeLast(wxT('*')) + wxT("*.dat"); altDat = wxFindFirstFile(datpath.BeforeLast(wxFILE_SEP_PATH) + wxFILE_SEP_PATH + altDat, wxFILE); } if (!altIdx.IsEmpty() && !altDat.IsEmpty() && wxFileExists(altIdx) && wxFileExists(altDat)) { m_pT = new wxThes(altIdx, altDat); Manager::Get()->GetLogManager()->Log(wxT("SpellChecker: Loading '") + altIdx + wxT("' instead...")); } } }
//----------------------------------------------------------------------------- // sorting function for strings, after = is the page #, don't sort by that //----------------------------------------------------------------------------- int wxCMPFUNC_CONV STN_SortNameCompareFunction(const wxString& first, const wxString& second) { int ret = wxStrcmp(first.BeforeLast(wxT('=')), second.BeforeLast(wxT('='))); if (ret == 0) { // same names, keep the same order long f = 0, s = 0; wxCHECK_MSG(first.AfterLast(wxT('=')).ToLong(&f), 0, wxT("Invalid first page name for sorting")); wxCHECK_MSG(second.AfterLast(wxT('=')).ToLong(&s), 0, wxT("Invalid second page name for sorting")); ret = f > s ? 1 : -1; } return ret; }
bool FortranFileExt::IsFileFortran(const wxString& filename, FortranSourceForm& fsForm) { if (!m_ExtDone) { RereadFileExtensions(); m_ExtDone = true; } bool isf; wxString ext = filename.AfterLast(_T('.')).Lower(); if (m_FortranExtFree.count(ext)) { fsForm = fsfFree; isf = true; } else if (m_FortranExtFixed.count(ext)) { fsForm = fsfFixed; isf = true; } else isf = false; return isf; }
bool PeerID::AddressMatches(const wxString& a) { unsigned long porta = DEFAULT_PORT, portb = DEFAULT_PORT; wxIPV4address addra, addrb; if (a.Contains(":")) { addra.Hostname(a.BeforeLast(':')); a.AfterLast(':').ToULong(&porta); addra.Service(porta); } else { addra.Hostname(a); addra.Service(porta); } if (this->address.Contains(":")) { addrb.Hostname(this->address.BeforeLast(':')); this->address.AfterLast(':').ToULong(&portb); addrb.Service(portb); } else { addrb.Hostname(this->address); addrb.Service(portb); } return (addra.IPAddress() == addrb.IPAddress() && addra.Service() == addrb.Service()); }
wxString KeynameConverter::discardModifier( const wxString& keystring ) { wxString result; if ( keystring.EndsWith(wxT("+")) ) //handle stuff like numpad+ or ctrl++ { wxString tmp = keystring; result = tmp.RemoveLast().AfterLast(wxT('+')) + wxT('+'); } else if ( keystring.StartsWith(wxT("+")) ) //handle stuff like "+ (numpad)" { result = keystring; } else { size_t lastAdd = keystring.find_last_of(wxT('+')); if ( ( lastAdd != keystring.npos ) && ( keystring.GetChar(lastAdd - 1) == wxT('+') ) ) { assert( (lastAdd > 0) && "character '+' found in unexcepted location!" ); result = keystring.substr( lastAdd ); } else { result = keystring.AfterLast(wxT('+')); } } return result; }
wxString wxTarOutputStream::PaxHeaderPath(const wxString& format, const wxString& path) { wxString d = path.BeforeLast(wxT('/')); wxString f = path.AfterLast(wxT('/')); wxString ret; if (d.empty()) d = wxT("."); ret.reserve(format.length() + path.length() + 16); size_t begin = 0; for (;;) { size_t end; end = format.find('%', begin); if (end == wxString::npos || end + 1 >= format.length()) break; ret << format.substr(begin, end - begin); switch ( format[end + 1].GetValue() ) { case 'd': ret << d; break; case 'f': ret << f; break; case 'p': ret << wxGetProcessId(); break; case '%': ret << wxT("%"); break; } begin = end + 2; } ret << format.substr(begin); return ret; }
bool wxDatabaseConfig::DoWriteString(const wxString& key, const wxString& szValue) { wxString name = key.AfterLast(wxCONFIG_PATH_SEPARATOR); if (name.StartsWith(wxCONFIG_IMMUTABLE_PREFIX)) { wxLogError("Immutable entries cannot be changed"); return false; } dbentries entries; if (!FindEntries(key, entries)) { wxConfigPathChanger path(this, key); //wxLogTrace(DBLCONF_TRACE_MASK, wxString::Format("Adding Entry '%s' = '%s' to Group '%s'", name, szValue, m_entry.path)); AddEntry(m_entry, name, &szValue); } else if (entries[0].isgroup) { wxLogError("Can't set value of a group!."); } else { //wxLogTrace(DBLCONF_TRACE_MASK, wxString::Format("Writing Entry '%s' = '%s' in Group '%s'", name, szValue, entries[0].path)); WriteEntry(entries[0], name, szValue); } return true; }
Maximas::Maximas( const wxString &filename ) : Glyph(), m_displayType( SLICES ), m_dataType( 16 ) { m_fullPath = filename; m_scalingFactor = 5.0f; #ifdef __WXMSW__ m_name = filename.AfterLast( '\\' ); #else m_name = filename.AfterLast( '/' ); #endif }
bool MPQFile::exists(wxString filename) { if( useLocalFiles ) { wxString fn1 = wxGetCwd()+SLASH+wxT("Import")+SLASH; wxString fn2 = fn1; wxString fn3 = gamePath; fn1.Append(filename); fn2.Append(filename.AfterLast(SLASH)); fn3.Append(filename); wxString fns[] = { fn1, fn2, fn3 }; for(size_t i=0; i<WXSIZEOF(fns); i++) { wxString fn = fns[i]; if (wxFile::Exists(fn)) return true; } } for(ArchiveSet::iterator i=gOpenArchives.begin(); i!=gOpenArchives.end();++i) { HANDLE &mpq_a = *i->second; #ifndef _MINGW if( SFileHasFile( mpq_a, filename.fn_str() ) ) #else if( SFileHasFile( mpq_a, filename.char_str() ) ) #endif return true; } return false; }
//----------------------------------------------------------------------------- void PlotCanvasFeatureVsTime::SetComponentToPlot( mvIMPACT::acquire::Component comp, const wxString& fullPath /* = wxEmptyString */ ) //----------------------------------------------------------------------------- { wxCriticalSectionLocker locker( m_critSect ); m_SelectedComponent = comp; m_PlotIdentifiers[0] = fullPath.AfterLast( wxT( '.' ) ); if( comp.isValid() ) { const TComponentType type = comp.type(); switch( type ) { case ctPropFloat: case ctPropInt: case ctPropInt64: m_dataType = type; break; default: // we don't support other component types for this feature break; } } else { m_dataType = ctPropInt64; } ClearCache(); }
wxString MPQFile::getArchive(wxString filename) { if( useLocalFiles ) { wxString fn1 = wxGetCwd()+SLASH+wxT("Import")+SLASH; wxString fn2 = fn1; wxString fn3 = gamePath; fn1.Append(filename); fn2.Append(filename.AfterLast(SLASH)); fn3.Append(filename); wxString fns[] = { fn1, fn2, fn3 }; for(size_t i=0; i<WXSIZEOF(fns); i++) { wxString fn = fns[i]; if (wxFile::Exists(fn)) { return fn; } } } for(ArchiveSet::iterator i=gOpenArchives.begin(); i!=gOpenArchives.end();++i) { HANDLE &mpq_a = *i->second; HANDLE fh; #ifndef _MINGW if( !SFileOpenFileEx( mpq_a, filename.fn_str(), SFILE_OPEN_PATCHED_FILE, &fh ) ) #else if( !SFileOpenFileEx( mpq_a, filename.char_str(), SFILE_OPEN_PATCHED_FILE, &fh ) ) #endif continue; return i->first; } return wxT("unknown"); }
wxString wxFileDialogBase::AppendExtension(const wxString &filePath, const wxString &extensionList) { // strip off path, to avoid problems with "path.bar/foo" wxString fileName = filePath.AfterLast(wxFILE_SEP_PATH); // if fileName is of form "foo.bar" it's ok, return it int idx_dot = fileName.Find(wxT('.'), true); if ((idx_dot != wxNOT_FOUND) && (idx_dot < (int)fileName.length() - 1)) return filePath; // get the first extension from extensionList, or all of it wxString ext = extensionList.BeforeFirst(wxT(';')); // if ext == "foo" or "foo." there's no extension int idx_ext_dot = ext.Find(wxT('.'), true); if ((idx_ext_dot == wxNOT_FOUND) || (idx_ext_dot == (int)ext.length() - 1)) return filePath; else ext = ext.AfterLast(wxT('.')); // if ext == "*" or "bar*" or "b?r" or " " then its not valid if ((ext.Find(wxT('*')) != wxNOT_FOUND) || (ext.Find(wxT('?')) != wxNOT_FOUND) || (ext.Strip(wxString::both).empty())) return filePath; // if fileName doesn't have a '.' then add one if (filePath.Last() != wxT('.')) ext = wxT(".") + ext; return filePath + ext; }
/*---------------------------------------------------------------------------*/ void wxSQLBook::Describe(const wxString& name) { wxSQLitePlusFrame* frame; wxString base, tempname; if (!name.IsEmpty()) { tempname = name.AfterLast(('.')); base = name.BeforeLast(('.')); frame = (wxSQLitePlusFrame*)wxGetApp().GetTopWindow(); if (frame->ExistDbObject(otTableAndView, tempname, base)) { wxDescribeDlg describeDlg(wxGetApp().GetTopWindow()); describeDlg.Describe(m_db, tempname, base); describeDlg.ShowModal(); } else { wxString msg = wxString::Format(_("Table or view \"%s\" not found."), name.c_str()); wxMessageBox(msg, _("Error")); } } }
bool ImportMIDI(wxString fName, NoteTrack * dest) { if (fName.Length() <= 4){ wxMessageBox( _("Could not open file ") + fName + _(": Filename too short.")); return false; } bool is_midi = false; if (fName.Right(4).CmpNoCase(wxT(".mid")) == 0 || fName.Right(5).CmpNoCase(wxT(".midi")) == 0) is_midi = true; else if(fName.Right(4).CmpNoCase(wxT(".gro")) != 0) { wxMessageBox( _("Could not open file ") + fName + _(": Incorrect filetype.")); return false; } wxFFile mf(fName, wxT("rb")); if (!mf.IsOpened()) { wxMessageBox( _("Could not open file ") + fName + wxT(".")); return false; } double offset = 0.0; Alg_seq_ptr new_seq = new Alg_seq(fName.mb_str(), is_midi, &offset); //Should we also check if(seq->tracks() == 0) ? if(new_seq->get_read_error() == alg_error_open){ wxMessageBox( _("Could not open file ") + fName + wxT(".")); mf.Close(); delete new_seq; return false; } dest->SetSequence(new_seq); dest->SetOffset(offset); wxString trackNameBase = fName.AfterLast(wxFILE_SEP_PATH).BeforeLast('.'); dest->SetName(trackNameBase); mf.Close(); // the mean pitch should be somewhere in the middle of the display Alg_iterator iterator(new_seq, false); iterator.begin(); // for every event Alg_event_ptr evt; int note_count = 0; int pitch_sum = 0; while ((evt = iterator.next())) { // if the event is a note if (evt->get_type() == 'n') { Alg_note_ptr note = (Alg_note_ptr) evt; pitch_sum += (int) note->pitch; note_count++; } } int mean_pitch = (note_count > 0 ? pitch_sum / note_count : 60); // initial track is about 27 half-steps high; if bottom note is C, // then middle pitch class is D. Round mean_pitch to the nearest D: int mid_pitch = ((mean_pitch - 2 + 6) / 12) * 12 + 2; dest->SetBottomNote(mid_pitch - 14); return true; }
Tensors::Tensors( const wxString &filename ) : Glyph(), m_isNormalized( false ) { m_fullPath = filename; #ifdef __WXMSW__ m_name = filename.AfterLast( '\\' ); #else m_name = filename.AfterLast( '/' ); #endif m_scalingFactor = 5.0f; m_currentLOD = LOD_3; // Generating hemispheres generateSpherePoints( m_scalingFactor / 5 ); }
bool UserVariableManager::Exists(const wxString& variable) const { if (variable.find(_T('#')) == wxString::npos) return false; wxString member(variable.AfterLast(wxT('#')).BeforeFirst(wxT('.')).BeforeFirst(wxT(')')).MakeLower()); return !m_CfgMan->Exists(cSets + m_ActiveSet + _T('/') + member + _T("/base")); }
bool Importer::IsMidi(const wxString &fName) { const auto extension = fName.AfterLast(wxT('.')); return extension.IsSameAs(wxT("gro"), false) || extension.IsSameAs(wxT("midi"), false) || extension.IsSameAs(wxT("mid"), false); }
ParserCommon::EFileType ParserCommon::FileType(const wxString& filename, bool /*force_refresh*/) { static bool empty_ext = true; static wxArrayString header_ext; header_ext.Add(_T("h")); header_ext.Add(_T("hpp")); header_ext.Add(_T("tcc")); header_ext.Add(_T("xpm")); static wxArrayString source_ext; source_ext.Add(_T("c")); source_ext.Add(_T("cpp")); source_ext.Add(_T("cxx")); source_ext.Add(_T("cc")); source_ext.Add(_T("c++")); if (filename.IsEmpty()) { wxString log; log.Printf(wxT("ParserDummy::ParserCommon::FileType() : File '%s' is of type 'ftOther' (empty)."), filename.wx_str()); //CCLogger::Get()->Log(log); return ParserCommon::ftOther; } const wxString file = filename.AfterLast(wxFILE_SEP_PATH).Lower(); const int pos = file.Find(_T('.'), true); wxString ext; if (pos != wxNOT_FOUND) ext = file.SubString(pos + 1, file.Len()); if (empty_ext && ext.IsEmpty()) { wxString log; log.Printf(wxT("ParserDummy::ParserCommon::FileType() : File '%s' is of type 'ftHeader' (w/o ext.)."), filename.wx_str()); //CCLogger::Get()->Log(log); return ParserCommon::ftHeader; } for (size_t i=0; i<header_ext.GetCount(); ++i) { if (ext==header_ext[i]) { wxString log; log.Printf(wxT("ParserDummy::ParserCommon::FileType() : File '%s' is of type 'ftHeader' (w/ ext.)."), filename.wx_str()); TRACE(log); return ParserCommon::ftHeader; } } for (size_t i=0; i<source_ext.GetCount(); ++i) { if (ext==source_ext[i]) { wxString log; log.Printf(wxT("ParserDummy::ParserCommon::FileType() : File '%s' is of type 'ftSource' (w/ ext.)."), filename.wx_str()); TRACE(log); return ParserCommon::ftSource; } } wxString log; log.Printf(wxT("ParserDummy::ParserCommon::FileType() : File '%s' is of type 'ftOther' (unknown ext)."), filename.wx_str()); TRACE(log); return ParserCommon::ftOther; }
void StringTestCase::BeforeAndAfter() { // Construct a string with 2 equal signs in it by concatenating its three // parts: before the first "=", in between the two "="s and after the last // one. This allows to avoid duplicating the string contents (which has to // be different for Unicode and ANSI builds) in the tests below. #if wxUSE_UNICODE #define FIRST_PART L"letter" #define MIDDLE_PART L"\xe9;\xe7a" #define LAST_PART L"l\xe0" #else // !wxUSE_UNICODE #define FIRST_PART "letter" #define MIDDLE_PART "e;ca" #define LAST_PART "la" #endif // wxUSE_UNICODE/!wxUSE_UNICODE const wxString s(FIRST_PART wxT("=") MIDDLE_PART wxT("=") LAST_PART); wxString r; CPPUNIT_ASSERT_EQUAL( FIRST_PART, s.BeforeFirst('=', &r) ); CPPUNIT_ASSERT_EQUAL( MIDDLE_PART wxT("=") LAST_PART, r ); CPPUNIT_ASSERT_EQUAL( s, s.BeforeFirst('!', &r) ); CPPUNIT_ASSERT_EQUAL( "", r ); CPPUNIT_ASSERT_EQUAL( FIRST_PART wxT("=") MIDDLE_PART, s.BeforeLast('=', &r) ); CPPUNIT_ASSERT_EQUAL( LAST_PART, r ); CPPUNIT_ASSERT_EQUAL( "", s.BeforeLast('!', &r) ); CPPUNIT_ASSERT_EQUAL( s, r ); CPPUNIT_ASSERT_EQUAL( MIDDLE_PART wxT("=") LAST_PART, s.AfterFirst('=') ); CPPUNIT_ASSERT_EQUAL( "", s.AfterFirst('!') ); CPPUNIT_ASSERT_EQUAL( LAST_PART, s.AfterLast('=') ); CPPUNIT_ASSERT_EQUAL( s, s.AfterLast('!') ); #undef LAST_PART #undef MIDDLE_PART #undef FIRST_PART }
virtual wxDirTraverseResult OnDir(const wxString& dirname) { if (m_Dirs.Index(dirname) == wxNOT_FOUND && dirname.AfterLast(m_SepChar).Contains(_T("."))) { m_Dirs.Add(dirname); } return wxDIR_CONTINUE; }
wxString UserVariableManager::Replace(const wxString& variable) { wxString package = variable.AfterLast(wxT('#')).BeforeFirst(wxT('.')).MakeLower(); wxString member = variable.AfterFirst(wxT('.')).MakeLower(); wxString path(cSets + m_ActiveSet + _T('/') + package + _T('/')); wxString base = m_CfgMan->Read(path + cBase); if (base.IsEmpty()) { if (Manager::Get()->GetProjectManager()->IsLoading()) { // a project/workspace is being loaded. // no need to bug the user now about global vars. // just preempt it; ProjectManager will call Arrogate() when it's done. Preempt(variable); return variable; } else { wxString msg; msg.Printf(_("In the currently active set, Code::Blocks does not know\n" "the global compiler variable \"%s\".\n\n" "Please define it."), package.wx_str()); InfoWindow::Display(_("Global Compiler Variables"), msg , 8000, 1000); UsrGlblMgrEditDialog d; d.AddVar(package); PlaceWindow(&d); d.ShowModal(); } } if (member.IsEmpty() || member.IsSameAs(cBase)) return base; if (member.IsSameAs(cInclude) || member.IsSameAs(cLib) || member.IsSameAs(cObj) || member.IsSameAs(cBin)) { wxString ret = m_CfgMan->Read(path + member); if (ret.IsEmpty()) ret = base + _T('/') + member; return ret; } const wxString wtf(wxT("#$%&???WTF???&%$#")); wxString ret = m_CfgMan->Read(path + member, wtf); if ( ret.IsSameAs(wtf) ) { wxString msg; msg.Printf(_("In the currently active set, Code::Blocks does not know\n" "the member \"%s\" of the global compiler variable \"%s\".\n\n" "Please define it."), member.wx_str(), package.wx_str()); InfoWindow::Display(_("Global Compiler Variables"), msg , 8000, 1000); } return ret; }
bool ReplayList::GetReplayInfos(const wxString& ReplayPath, Replay& ret ) const { const wxString FileName = ReplayPath.AfterLast( wxFileName::GetPathSeparator() ); // strips file path ret.Filename = ReplayPath; ret.battle.SetPlayBackFilePath(STD_STRING(ReplayPath)); ret.SpringVersion = FileName.AfterLast(_T('_')).BeforeLast(_T('.')); ret.MapName = FileName.BeforeLast(_T('_')); if (!wxFileExists(ReplayPath)) { return false; } wxFile replay(ReplayPath, wxFile::read ); if (!replay.IsOpened()) { return false; } const int replay_version = replayVersion( replay ); ret.battle.SetScript(STD_STRING(GetScriptFromReplay( replay, replay_version ))); if ( ret.battle.GetScript().empty() ) { return false; } GetHeaderInfo(replay, ret, replay_version ); ret.battle.GetBattleFromScript( false ); ret.ModName = TowxString(ret.battle.GetHostModName()); ret.battle.SetBattleType( BT_Replay ); ret.battle.SetEngineName("spring"); ret.battle.SetEngineVersion(STD_STRING(ret.SpringVersion)); ret.battle.SetPlayBackFilePath(STD_STRING(ReplayPath)); //getting this from filename seems more reliable than from demoheader wxDateTime rdate; if (rdate.ParseFormat(FileName, _T("%Y%m%d_%H%M%S")) == 0) { wxLogError(_T("Parsing %s failed"), FileName.c_str()); return false; } ret.date=rdate.GetTicks(); // now it is sorted properly ret.date_string=rdate.FormatISODate()+_T(" ")+rdate.FormatISOTime(); return true; }
bool RawData::Open(wxString filename) { wxFile f; void *tempbuffer; uint bytesread = 0, buffer_size = 0; wxString ext; bool ret; ret = false; if (f.Open(filename)) { if (IsLoaded()) Close(); m_header_offset = 0; buffer_size = (uint)f.Length(); tempbuffer = m_buffer.GetWriteBuf(buffer_size); if (tempbuffer != 0) bytesread = (uint)f.Read(tempbuffer, buffer_size); f.Close(); if (bytesread == buffer_size) { m_buffer.UngetWriteBuf(buffer_size); rawdata_filename.Assign(filename); ext = filename.AfterLast('.'); ext = ext.Lower(); if (ext == "com") SetFileType(COM); else if (ext == "rom") { SetFileType(ROM); } else if (!SetFileType(BIN)) SetFileType(UNKNOWN); ret = true; } else m_buffer.SetDataLen(0); } #ifdef IDZ80DEBUG if (ret) LogIt(wxString::Format("File opened is %s.\n",filename.c_str())); else LogIt("File not found !\n"); #endif return ret; }
void PreviewDlg::OnTitleChange(const wxString& title) { const wxString tempFile = m_tempPath.AfterLast(wxT('\\')); const wxString titleEnd = title.AfterLast(wxT('\\')); // This is a bit of a hack, but the easiest way to see if // it does not have a title and returns path is to compare // filenames (very litle chance for match with other) m_parent.SetWebPreviewTitle(wxT("Preview: ") + (tempFile != titleEnd) ? title : m_truePath); }
wxString CMedia::GetFileTypeStr(const wxString& Path) { wxString ext = Path.AfterLast('.'); if (ext == "m4a" || ext == "M4A" || ext == "mp4" || ext == "MP4" || ext == "aac" || ext == "AAC") return "m4a"; else if (ext == "mp3" || ext == "MP3") return "mp3"; else return wxEmptyString; }
cmsFileType CMedia::GetFileType(const wxString& Path) { wxString ext = Path.AfterLast('.'); if (ext == "m4a" || ext == "M4A" || ext == "mp4" || ext == "MP4" || ext == "aac" || ext == "AAC") return FILETYPE_M4A; else if (ext == "mp3") return FILETYPE_MP3; else return FILETYPE_UNKNOWN; }
void TCloneManager::load ( wxString file ) { wxFile f ( file , wxFile::read ) ; long l = f.Length() ; unsigned char *t = new unsigned char [l+5] ; f.Read ( t , l ) ; f.Close() ; if ( t[0] != 26 || t[1] != 'S' || t[2] != 'E' || t[3] != 'S' ) { delete t ; return ; } int a , b ; TVector *v = new TVector ; wxString name = file.AfterLast('/').AfterLast('\\').BeforeLast('.') ; wxString seq , desc ; // Items a = 12 ; while ( t[a+2] == 0 && t[2+3] == 0 ) { unsigned char a1 = t[a] ; unsigned char a2 = t[a+1] ; if ( a1 == 255 && a2 == 255 ) a = scan_item ( t , a , v ) ; else { a += 8 ; } } // Sequence while ( t[a] >= 65 ) seq += t[a++] ; // Rest for ( a = l - 1 ; t[a-1] || t[a-2] ; a-- ) ; for ( ; a < l ; a++ ) { if ( t[a] == 10 ) continue ; if ( t[a] == 13 || t[a] == 0 ) desc += '\n' ; else desc += t[a] ; } // Set vector v->setName ( name ) ; v->setSequence ( seq ) ; v->setDescription ( desc ) ; if ( seq.length() > 3000 ) v->setCircular () ; // Guessing _v.push_back ( v ) ; _success = true ; delete t ; }
EFileType FileType(const wxString& filename, bool force_refresh) { static bool cfg_read = false; static bool empty_ext = true; static wxArrayString header_ext; static wxArrayString source_ext; if (!cfg_read || force_refresh) { ConfigManager* cfg = Manager::Get()->GetConfigManager(_T("code_completion")); empty_ext = cfg->ReadBool(_T("/empty_ext"), true); wxString header_ext_str = cfg->Read(_T("/header_ext"), _T("h,hpp,tcc,xpm")); wxString source_ext_str = cfg->Read(_T("/source_ext"), _T("c,cpp,cxx,cc,c++")); header_ext.Clear(); wxStringTokenizer header_ext_tknzr(header_ext_str, _T(",")); while (header_ext_tknzr.HasMoreTokens()) header_ext.Add(header_ext_tknzr.GetNextToken().Trim(false).Trim(true).Lower()); source_ext.Clear(); wxStringTokenizer source_ext_tknzr(source_ext_str, _T(",")); while (source_ext_tknzr.HasMoreTokens()) source_ext.Add(source_ext_tknzr.GetNextToken().Trim(false).Trim(true).Lower()); cfg_read = true; // caching done } if (filename.IsEmpty()) return ParserCommon::ftOther; const wxString file = filename.AfterLast(wxFILE_SEP_PATH).Lower(); const int pos = file.Find(_T('.'), true); wxString ext; if (pos != wxNOT_FOUND) ext = file.SubString(pos + 1, file.Len()); if (empty_ext && ext.IsEmpty()) return ParserCommon::ftHeader; for (size_t i=0; i<header_ext.GetCount(); ++i) { if (ext==header_ext[i]) return ParserCommon::ftHeader; } for (size_t i=0; i<source_ext.GetCount(); ++i) { if (ext==source_ext[i]) return ParserCommon::ftSource; } return ParserCommon::ftOther; }
void MainFrame::UpdateFile(wxString host, wxString url) { wxProgressDialog progress(_T("Downloading..."), _T("Please wait while the VisualBoyAdvance-M update is downloading.")); wxHTTP get; get.SetHeader(_T("Content-type"), _T("text/html; charset=utf-8")); get.SetTimeout(10); while (!get.Connect(host)) wxSleep(5); wxInputStream* httpStream = get.GetInputStream(url); if (get.GetError() == wxPROTO_NOERR) { if (httpStream != NULL) { size_t size = httpStream->GetSize(); char* data = new char[size]; wxFileName name(wxStandardPaths::Get().GetPluginsDir(), url.AfterLast('/'), wxEmptyString); if (httpStream) { size_t chunks = 100; size_t chunkSize = httpStream->GetSize() / chunks; char* fileContent = new char[chunkSize]; #if (wxMAJOR_VERSION >= 3) progress.SetRange(chunks); #endif wxFFile file(name.GetFullPath(), _T("wb")); for (size_t i = 0; i <= chunks; i++) { progress.Update(i); httpStream->Read(fileContent, chunkSize); file.Write(fileContent, httpStream->LastRead()); } file.Flush(); wxDELETE(fileContent); } if (name.FileExists() && name.GetFullName().Lower().Contains(wxT(".7z"))) { utilExtract(name.GetPathWithSep().mb_str(wxConvUTF8), name.GetFullName().mb_str(wxConvUTF8)); } delete[] data; delete httpStream; } } get.Close(); }