Example #1
0
CKnownFile::CKnownFile(CEC_SharedFile_Tag *tag) : CECID(tag->ID())
{
	Init();
	
	SetFileName(CPath(tag->FileName()));
	m_abyFileHash = tag->FileHash();
	SetFileSize(tag->SizeFull());
	m_AvailPartFrequency.insert(m_AvailPartFrequency.end(), m_iPartCount, 0);
	m_iUpPriorityEC = tag->Prio();
	m_AICHMasterHash = tag->GetAICHHash();
	m_filePath = CPath(tag->FilePath());
}
Example #2
0
CPath CPath::JoinPaths(const CPath& other) const
{
	if (!IsOk()) {
		return CPath(other);
	} else if (!other.IsOk()) {
		return CPath(*this);
	} 

	CPath joinedPath;
	// DeepCopy shouldn't be needed, as JoinPaths results in the creation of a new string.
	joinedPath.m_printable = ::JoinPaths(m_printable, other.m_printable);
	joinedPath.m_filesystem = ::JoinPaths(m_filesystem, other.m_filesystem);

	return joinedPath;
}
Example #3
0
engine_t CMediaFormats::GetEngine(CString path) const
{
    path.Trim().MakeLower();

    if (!m_fRtspFileExtFirst && path.Find(_T("rtsp://")) == 0) {
        return m_iRtspHandler;
    }

    CString ext = CPath(path).GetExtension();
    ext.MakeLower();
    if (!ext.IsEmpty()) {
        if (path.Find(_T("rtsp://")) == 0) {
            if (ext == _T(".ram") || ext == _T(".rm") || ext == _T(".ra")) {
                return RealMedia;
            }
            if (ext == _T(".qt") || ext == _T(".mov")) {
                return QuickTime;
            }
        }

        for (size_t i = 0; i < GetCount(); i++) {
            const CMediaFormatCategory& mfc = GetAt(i);
            if (mfc.FindExt(ext)) {
                return mfc.GetEngineType();
            }
        }
    }

    if (m_fRtspFileExtFirst && path.Find(_T("rtsp://")) == 0) {
        return m_iRtspHandler;
    }

    return DirectShow;
}
Example #4
0
void CPPageExternalFilters::OnAddRegistered()
{
	CRegFilterChooserDlg dlg(this);
	if (dlg.DoModal() == IDOK) {
		while (!dlg.m_filters.IsEmpty()) {
			if (FilterOverride* f = dlg.m_filters.RemoveHead()) {
				CAutoPtr<FilterOverride> p(f);

				CString name = f->name;

				if (f->type == FilterOverride::EXTERNAL) {
					if (!CPath(MakeFullPath(f->path)).FileExists()) {
						name += _T(" <not found!>");
					}
				}

				int i = m_filters.AddString(name);
				m_filters.SetItemDataPtr(i, m_pFilters.AddTail(p));
				m_filters.SetCheck(i, 1);

				if (dlg.m_filters.IsEmpty()) {
					m_filters.SetCurSel(i);
					OnLbnSelchangeList1();
				}

				SetModified();
			}
		}
	}
}
Example #5
0
CPath CPath::FromUniv(const wxString& path)
{
	wxCharBuffer fn = wxConvISO8859_1.cWC2MB(path);

	return CPath(wxConvFile.cMB2WC(fn));

}
Example #6
0
void QtSE::addFolder( void )
{
	QString activeFilePath = activeProjectItem->getFullPath( CPath( QDir::currentPath() ).getPath( true ) );
	QDir dir( activeFilePath );

	if( dir.exists() )
	{
		bool ok = false;
		QString name = QInputDialog::getText( this , this->windowTitle() , "Directory Name:" , QLineEdit::Normal , "" , &ok );

		if( ok )
		{
			if( UTIL_validateFileName( name , false ) )
			{
				if( dir.mkdir( name ) )
				{
					CProjectTreeItem *item = new CProjectTreeItem( CProjectTreeItem::dir , activeProjectItem , QStringList( name ) );
					activeProjectItem->setExpanded( true );
				}
				else
					QMessageBox::warning( this , this->windowTitle() , "Unable to add directory." );
			}
			else
				QMessageBox::warning( this , this->windowTitle() , "Invalid directory name." );
		}
	}
	else
		QMessageBox::warning( this , this->windowTitle() , "Base path does not exist." );
}
void CSettingTypeApplication::Initialize( const char * /*AppName*/ )
{
    stdstr SettingsFile, OrigSettingsFile;

    for (int i = 0; i < 100; i++)
    {
        OrigSettingsFile = SettingsFile;
        if (!g_Settings->LoadStringVal(SupportFile_Settings,SettingsFile) && i > 0)
        {
            break;
        }
        if (SettingsFile == OrigSettingsFile)
        {
            break;
        }
        if (m_SettingsIniFile)
        {
            delete m_SettingsIniFile;
        }
        CPath SettingsDir(CPath(SettingsFile).GetDriveDirectory(),"");
        if (!SettingsDir.DirectoryExists())
        {
			SettingsDir.DirectoryCreate();
        }

        m_SettingsIniFile = new CIniFile(SettingsFile.c_str());
    }

    m_SettingsIniFile->SetAutoFlush(false);
    m_UseRegistry = g_Settings->LoadBool(Setting_UseFromRegistry);
}
Example #8
0
void CFriendList::LoadList()
{
  	CPath metfile = CPath(theApp->ConfigDir + wxT("emfriends.met"));
	
	if (!metfile.FileExists()) {
		return;
	}
	
	CFile file;
	try {
		if ( file.Open(metfile) ) {
			if ( file.ReadUInt8() /*header*/ == MET_HEADER ) {
				uint32 nRecordsNumber = file.ReadUInt32();
				for (uint32 i = 0; i < nRecordsNumber; i++) {
					CFriend* Record = new CFriend();
					Record->LoadFromFile(&file);
					m_FriendList.push_back(Record);
					Notify_ChatUpdateFriend(Record);
				}				
			}
		} else {
			AddLogLineN(_("Failed to open friend list file 'emfriends.met' for reading!"));
		}
	} catch (const CInvalidPacket& e) {
		AddDebugLogLineC(logGeneral, wxT("Invalid entry in friend list, file may be corrupt: ") + e.what());
	} catch (const CSafeIOException& e) {
		AddDebugLogLineC(logGeneral, wxT("IO error while reading 'emfriends.met': ") + e.what());
	}
	
}
Example #9
0
void CDirectoryTreeCtrl::Init()
{
	// already done ?
	if (m_IsInit) {
		return;
	}
	m_IsInit = true;

	// init image(s)
	wxImageList* images = new wxImageList(16, 16);
	images->Add(wxBitmap(amuleSpecial(1)));
	images->Add(wxBitmap(amuleSpecial(2)));
	// Gives wxTreeCtrl ownership of the list
	AssignImageList(images);


	// Create an empty root item, which we can
	// safely append when creating a full path.
	m_root = AddRoot(wxEmptyString, IMAGE_FOLDER, -1,
					new CItemData(CPath()));

	if (!m_IsRemote) {
	#ifndef __WXMSW__
		AddChildItem(m_root, CPath(wxT("/")));
	#else
		// this might take awhile, so change the cursor
		::wxSetCursor(*wxHOURGLASS_CURSOR);
		// retrieve bitmask of all drives available
		uint32 drives = GetLogicalDrives();
		drives >>= 1;
		for (char drive = 'C'; drive <= 'Z'; drive++) {
			drives >>= 1;
			if (! (drives & 1)) { // skip non existant drives
				continue;
			}
			wxString driveStr = CFormat(wxT("%c:")) % drive;
			uint32 type = GetDriveType(driveStr + wxT("\\"));

			// skip removable/undefined drives, share only fixed or remote drives
			if ((type == 3 || type == 4)   // fixed drive / remote drive
				&& CPath::DirExists(driveStr)) {
				AddChildItem(m_root, CPath(driveStr));
			}
		}
		::wxSetCursor(*wxSTANDARD_CURSOR);
	#endif
	}
Example #10
0
static CString CombinePath(CPath p, CString fn)
{
    if (fn.Find(':') >= 0 || fn.Find(_T("\\")) == 0) {
        return fn;
    }
    p.Append(CPath(fn));
    return (LPCTSTR)p;
}
bool CEC_Category_Tag::Apply()
{
	bool ret = theApp->glob_prefs->UpdateCategory(GetInt(), Name(), CPath(Path()), Comment(), Color(), Prio());
	if (!ret) {
		GetTagByName(EC_TAG_CATEGORY_PATH)->SetStringData(theApp->glob_prefs->GetCatPath(GetInt()).GetRaw());
	}
	return ret;
}
Example #12
0
File: bus.hpp Project: oshch/graph
 CPath CPath::add(CEdge* edge)
 {
     size_t departure = edge->e_departure;
     while(departure < p_arrival_time)
         departure += edge->e_interval;
     departure += edge->e_duration;
     return CPath(departure);
 }
void CSettingTypeApplication::Initialize(const char * /*AppName*/)
{
    WriteTrace(TraceAppInit, TraceDebug, "Start");
    CPath BaseDir(g_Settings->LoadStringVal(Cmd_BaseDirectory).c_str(), "");
    if (!BaseDir.DirectoryExists())
    {
        WriteTrace(TraceAppInit, TraceDebug, "BaseDir does not exist.  Doing nothing.");
        WriteTrace(TraceAppInit, TraceDebug, "Done");
        return;
    }

    stdstr SettingsFile, OrigSettingsFile;

    for (int i = 0; i < 100; i++)
    {
        OrigSettingsFile = SettingsFile;
        if (!g_Settings->LoadStringVal(SupportFile_Settings, SettingsFile) && i > 0)
        {
            break;
        }
        if (SettingsFile == OrigSettingsFile)
        {
            break;
        }
        if (m_SettingsIniFile)
        {
            delete m_SettingsIniFile;
        }
#ifdef _WIN32
        CPath SettingsDir(CPath(SettingsFile).GetDriveDirectory(), "");
#else
        CPath SettingsDir(CPath(SettingsFile).GetDirectory(), "");
#endif
        if (!SettingsDir.DirectoryExists())
        {
            SettingsDir.DirectoryCreate();
        }

        m_SettingsIniFile = new CIniFile(SettingsFile.c_str());
    }

    m_SettingsIniFile->SetAutoFlush(false);
    WriteTrace(TraceAppInit, TraceDebug, "Done");
}
	void CLogic::handle_new( CServer &server, CCommandSource source )
	{
		/* add connections in host if needed */ 

		for( const INode *ancestor = &m_node; ancestor; ancestor = ancestor->get_parent() )
		{
			const node_map &siblings = server.get_siblings( *ancestor );
			for( node_map::const_iterator i = siblings.begin(); i != siblings.end(); i++ )
			{
				const INode *sibling = i->second;

				if( sibling != ancestor && CGuidHelper::guids_are_equal(sibling->get_interface_definition().get_module_guid(), get_connection_interface_guid( server ) ) )
				{
					/* found a connection which might target the new node */

					const INodeEndpoint *source_path = sibling->get_node_endpoint( endpoint_source_path );
					const INodeEndpoint *target_path = sibling->get_node_endpoint( endpoint_target_path );
					assert( source_path && target_path );

					const INodeEndpoint *source_endpoint = server.find_node_endpoint( CPath( *source_path->get_value() ), ancestor->get_parent() );
					const INodeEndpoint *target_endpoint = server.find_node_endpoint( CPath( *target_path->get_value() ), ancestor->get_parent() );
	
					if( source_endpoint && target_endpoint )
					{
						internal_id source_node_id = CNode::downcast( &source_endpoint->get_node() )->get_id();
						internal_id target_node_id = CNode::downcast( &target_endpoint->get_node() )->get_id();

						if( m_node.get_id() == source_node_id || m_node.get_id() == target_node_id )
						{
							if( source_endpoint->get_endpoint_definition().is_audio_stream() && source_endpoint->get_endpoint_definition().get_stream_info()->get_direction() == CStreamInfo::OUTPUT )
							{
								if( target_endpoint->get_endpoint_definition().is_audio_stream() && target_endpoint->get_endpoint_definition().get_stream_info()->get_direction() == CStreamInfo::INPUT )
								{
									/* create connection in host */
									connect_audio_in_host( server, *source_endpoint, *target_endpoint, true );
								}
							}
						}
					}
				}
			}
		}
	}
bool CEC_Category_Tag::Create()
{
	Category_Struct * category = NULL;
	bool ret = theApp->glob_prefs->CreateCategory(category, Name(), CPath(Path()), Comment(), Color(), Prio());
	if (!ret) {
		GetTagByName(EC_TAG_CATEGORY_PATH)->SetStringData(theApp->glob_prefs->GetCatPath(
			theApp->glob_prefs->GetCatCount() - 1).GetRaw());
	}
	return ret;
}
Example #16
0
bool pjutil::TerminatedExistingExe()
{
    bool bTerminated = false;
    bool AskedUser = false;
    DWORD pid = GetCurrentProcessId();

    HANDLE nSearch = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
    if (nSearch != INVALID_HANDLE_VALUE)
    {
        PROCESSENTRY32 lppe;

        memset(&lppe, 0, sizeof(PROCESSENTRY32));
        lppe.dwSize = sizeof(PROCESSENTRY32);
        stdstr ModuleName = CPath(CPath::MODULE_FILE).GetNameExtension();

        if (Process32First(nSearch, &lppe))
        {
            do
            {
                if (_stricmp(lppe.szExeFile, ModuleName.c_str()) != 0 ||
                    lppe.th32ProcessID == pid)
                {
                    continue;
                }
                if (!AskedUser)
                {
                    AskedUser = true;
                    int res = MessageBox(NULL, stdstr_f("%s currently running\n\nTerminate pid %d now?", ModuleName.c_str(), lppe.th32ProcessID).c_str(), stdstr_f("Terminate %s",ModuleName.c_str()).c_str(), MB_YESNO | MB_ICONEXCLAMATION);
                    if (res != IDYES)
                    {
                        break;
                    }
                }
                HANDLE hHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, lppe.th32ProcessID);
                if (hHandle != NULL)
                {
                    if (TerminateProcess(hHandle, 0))
                    {
                        bTerminated = true;
                    }
                    else
                    {
                        MessageBox(NULL, stdstr_f("Failed to terminate pid %d", lppe.th32ProcessID).c_str(), stdstr_f("Terminate %s failed!",ModuleName.c_str()).c_str(), MB_YESNO | MB_ICONEXCLAMATION);
                    }
                    CloseHandle(hHandle);
                }
            } while (Process32Next(nSearch, &lppe));
        }
        CloseHandle(nSearch);
    }
    return bTerminated;
}
Example #17
0
void CMempak::LoadMempak(int32_t Control, bool Create)
{
    stdstr MempakName;
    MempakName.Format("%s_Cont_%d", g_Settings->LoadStringVal(Game_GameName).c_str(), Control + 1);

    CPath MempakPath(g_Settings->LoadStringVal(Directory_NativeSave).c_str(), stdstr_f("%s.mpk", MempakName.c_str()).c_str());
    if (g_Settings->LoadBool(Setting_UniqueSaveDir))
    {
        MempakPath.AppendDirectory(g_Settings->LoadStringVal(Game_UniqueSaveDir).c_str());
    }
#ifdef _WIN32
    MempakPath.NormalizePath(CPath(CPath::MODULE_DIRECTORY));
#endif

    if (!Create && !MempakPath.Exists())
    {
        if (!m_Formatted[Control])
        {
            CMempak::Format(Control);
            m_Formatted[Control] = true;
        }
        m_SaveExists[Control] = false;
        return;
    }

    if (!MempakPath.DirectoryExists())
    {
        MempakPath.DirectoryCreate();
    }

    bool formatMempak = !MempakPath.Exists();

    m_MempakHandle[Control].Open(MempakPath, CFileBase::modeReadWrite | CFileBase::modeNoTruncate | CFileBase::modeCreate);
    m_MempakHandle[Control].SeekToBegin();

    if (formatMempak)
    {
        if (!m_Formatted[Control])
        {
            CMempak::Format(Control);
            m_Formatted[Control] = true;
        }
        m_MempakHandle[Control].Write(m_Mempaks[Control], 0x8000);
    }
    else
    {
        m_MempakHandle[Control].Read(m_Mempaks[Control], 0x8000);
        m_Formatted[Control] = true;
    }
}
Example #18
0
void CFavoriteOrganizeDlg::OnLvnGetInfoTipList(NMHDR* pNMHDR, LRESULT* pResult)
{
    LPNMLVGETINFOTIP pGetInfoTip = reinterpret_cast<LPNMLVGETINFOTIP>(pNMHDR);

    CAtlList<CString> args;
    ExplodeEsc(m_sl[m_tab.GetCurSel()].GetAt((POSITION)m_list.GetItemData(pGetInfoTip->iItem)), args, _T(';'));
    CString path = args.RemoveTail();
    // Relative to drive value is always third. If less args are available that means it is not included.
    int rootLength = (args.GetCount() == 3 && args.RemoveTail() != _T("0")) ? CPath(path).SkipRoot() : 0;

    StringCchCopy(pGetInfoTip->pszText, pGetInfoTip->cchTextMax, path.Mid(rootLength));

    *pResult = 0;
}
Example #19
0
CWebServer::CWebServer(CMainFrame* pMainFrame, int nPort)
    : m_pMainFrame(pMainFrame)
    , m_nPort(nPort)
{
    m_webroot = CPath(GetProgramPath());
    const CAppSettings& s = AfxGetAppSettings();

    CString WebRoot = s.strWebRoot;
    WebRoot.Replace('/', '\\');
    WebRoot.Trim();
    CPath p(WebRoot);
    if (WebRoot.Find(_T(":\\")) < 0 && WebRoot.Find(_T("\\\\")) < 0) {
        m_webroot.Append(WebRoot);
    } else {
        m_webroot = p;
    }
    m_webroot.Canonicalize();
    m_webroot.MakePretty();
    if (!m_webroot.IsDirectory()) {
        m_webroot = CPath();
    }

    CAtlList<CString> sl;
    Explode(s.strWebServerCGI, sl, ';');
    POSITION pos = sl.GetHeadPosition();
    while (pos) {
        CAtlList<CString> sl2;
        CString ext = Explode(sl.GetNext(pos), sl2, '=', 2);
        if (sl2.GetCount() < 2) {
            continue;
        }
        m_cgi[ext] = sl2.GetTail();
    }

    m_ThreadId = 0;
    m_hThread = ::CreateThread(nullptr, 0, StaticThreadProc, (LPVOID)this, 0, &m_ThreadId);
}
Example #20
0
void CFileDetailDialog::OnBnClickedApply(wxCommandEvent& WXUNUSED(evt))
{
	CPath fileName = CPath(CastChild(IDC_FILENAME, wxTextCtrl)->GetValue());

	if (fileName.IsOk() && (fileName != m_file->GetFileName())) {
		if (theApp->sharedfiles->RenameFile(m_file, fileName)) {
			FindWindow(IDC_FNAME)->SetLabel(MakeStringEscaped(m_file->GetFileName().GetPrintable()));
			FindWindow(IDC_METFILE)->SetLabel(m_file->GetFullName().GetPrintable());
			
			resetValueForFilenameTextEdit();
	
			Layout();
		}
	}
}
Example #21
0
bool CKnownFileList::Init()
{
	CFile file;

	CPath fullpath = CPath(theApp->ConfigDir + m_filename);
	if (!fullpath.FileExists()) {
		// This is perfectly normal. The file was probably either
		// deleted, or this is the first time running aMule.
		return false;
	}

	if (!file.Open(fullpath)) {
		AddLogLineC(CFormat(_("WARNING: %s cannot be opened.")) % m_filename);
		return false;
	}

	try {
		uint8 version = file.ReadUInt8();
		if ((version != MET_HEADER) && (version != MET_HEADER_WITH_LARGEFILES)) {
			AddLogLineC(_("WARNING: Known file list corrupted, contains invalid header."));
			return false;
		}

		wxMutexLocker sLock(list_mut);
		uint32 RecordsNumber = file.ReadUInt32();
		AddDebugLogLineN(logKnownFiles, CFormat(wxT("Reading %i known files from file format 0x%2.2x."))
			% RecordsNumber % version);
		for (uint32 i = 0; i < RecordsNumber; i++) {
			CScopedPtr<CKnownFile> record;
			if (record->LoadFromFile(&file)) {
				AddDebugLogLineN(logKnownFiles,
					CFormat(wxT("Known file read: %s")) % record->GetFileName());
				Append(record.release());
			} else {
				AddLogLineC(_("Failed to load entry in known file list, file may be corrupt"));
			}
		}
		AddDebugLogLineN(logKnownFiles, wxT("Finished reading known files"));

		return true;
	} catch (const CInvalidPacket& e) {
		AddLogLineC(_("Invalid entry in known file list, file may be corrupt: ") + e.what());
	} catch (const CSafeIOException& e) {
		AddLogLineC(CFormat(_("IO error while reading %s file: %s")) % m_filename % e.what());
	}

	return false;
}
Example #22
0
void CSharedFilesCtrl::OnRename( wxCommandEvent& WXUNUSED(event) )
{
	int item = GetNextItem( -1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED );
	if ( item != -1 ) {
		CKnownFile* file = (CKnownFile*)GetItemData(item);

		wxString strNewName = ::wxGetTextFromUser(
			_("Enter new name for this file:"),
			_("File rename"), file->GetFileName().GetPrintable());

		CPath newName = CPath(strNewName);
		if (newName.IsOk() && (newName != file->GetFileName())) {
			theApp->sharedfiles->RenameFile(file, newName);
		}
	}
}
Example #23
0
void CIP2Country::DownloadFinished(uint32 result)
{
	if (result == HTTP_Success) {
		Disable();
		// download succeeded. Switch over to new database.
		wxString newDat = m_DataBasePath + wxT(".download");

		// Try to unpack the file, might be an archive
		wxWCharBuffer dataBaseName = m_DataBaseName.wc_str();
		const wxChar* geoip_files[] = {
			dataBaseName,
			NULL
		};

		if (UnpackArchive(CPath(newDat), geoip_files).second == EFT_Error) {
			AddLogLineC(_("Download of GeoIP.dat file failed, aborting update."));
			return;
		}

		if (wxFileExists(m_DataBasePath)) {
			if (!wxRemoveFile(m_DataBasePath)) {
				AddLogLineC(CFormat(_("Failed to remove %s file, aborting update.")) % m_DataBaseName);
				return;
			}
		}

		if (!wxRenameFile(newDat, m_DataBasePath)) {
			AddLogLineC(CFormat(_("Failed to rename %s file, aborting update.")) % m_DataBaseName);
			return;
		}

		Enable();
		if (m_geoip) {
			AddLogLineN(CFormat(_("Successfully updated %s")) % m_DataBaseName);
		} else {
			AddLogLineC(_("Error updating GeoIP.dat"));
		}
	} else if (result == HTTP_Skipped) {
		AddLogLineN(CFormat(_("Skipped download of %s, because requested file is not newer.")) % m_DataBaseName);
	} else {
		AddLogLineC(CFormat(_("Failed to download %s from %s")) % m_DataBaseName % thePrefs::GetGeoIPUpdateUrl());
		// if it failed and there is no database, turn it off
		if (!wxFileExists(m_DataBasePath)) {
			thePrefs::SetGeoIPEnabled(false);
		}
	}
}
void CPartFileConvertDlg::OnAddFolder(wxCommandEvent& WXUNUSED(event))
{
	// TODO: use MuleRemoteDirSelector
	wxString folder = ::wxDirSelector(
		_("Please choose a folder to search for temporary downloads! (subfolders will be included)"),
		wxStandardPaths::Get().GetDocumentsDir(), wxDD_DEFAULT_STYLE,
		wxDefaultPosition, this);
	if (!folder.IsEmpty()) {
		int reply = wxMessageBox(_("Do you want the source files of succesfully imported downloads be deleted?"),
					 _("Remove sources?"),
					 wxYES_NO | wxCANCEL | wxICON_QUESTION, this);
		if (reply != wxCANCEL) {
			// TODO: use notification
			CPartFileConvert::ScanFolderToAdd(CPath(folder), (reply == wxYES));
		}
	}
}
Example #25
0
bool CServerList::Init()
{
	// Load Metfile
	bool bRes = LoadServerMet(CPath(theApp->ConfigDir + wxT("server.met")));

	// insert static servers from textfile
	m_staticServersConfig = theApp->ConfigDir + wxT("staticservers.dat");
	LoadStaticServers();
	
	// Send the auto-update of server.met via HTTPThread requests
	current_url_index = 0;
	if ( thePrefs::AutoServerlist()) {
		AutoUpdate();
	}	
	
	m_initialized = true;
	return bRes;
}
Example #26
0
void CServerList::DownloadFinished(uint32 result) 
{
	if(result == HTTP_Success) {
		const CPath tempFilename = CPath(theApp->ConfigDir + wxT("server.met.download"));

		// curl succeeded. proceed with server.met loading
		LoadServerMet(tempFilename);
		SaveServerMet();

		// So, file is loaded and merged, and also saved
		CPath::RemoveFile(tempFilename);
		AddLogLineN(CFormat(_("Finished downloading the server list from %s")) % m_URLUpdate);
	} else if (result == HTTP_Skipped) {
		AddLogLineN(CFormat(_("Skipped download of %s, because requested file is not newer.")) % wxT("server.met"));
	} else {
		AddLogLineC(CFormat(_("Failed to download %s from %s")) % wxT("server.met") % m_URLUpdate);
	}
}
Example #27
0
bool CCanceledFileList::Init()
{
	CFile file;
	
	CPath fullpath = CPath(theApp->ConfigDir + m_filename);
	if (!fullpath.FileExists()) {
		// This is perfectly normal. The file was probably either
		// deleted, or this is the first time running aMule.
		return false;
	}

	if (!file.Open(fullpath)) {
		AddLogLineM(true, CFormat(_("WARNING: %s cannot be opened.")) % m_filename);
		return false;
	}
	
	try {
		uint8 version = file.ReadUInt8();
		if (version != CANCELEDFILE_VERSION) {
			AddLogLineM(true, _("WARNING: Canceled file list corrupted, contains invalid header."));
			return false;
		}
		
		uint32 RecordsNumber = file.ReadUInt32();
		AddDebugLogLineM(false, logKnownFiles,
			CFormat(wxT("Reading %i canceled files from file format 0x%02x."))
			% RecordsNumber % version);
		for (uint32 i = 0; i < RecordsNumber; i++) {
			CMD4Hash hash;
			file.Read(hash.GetHash(), 16);
			AddDebugLogLineM(false, logKnownFiles, CFormat(wxT("Canceled file read: %s")) % hash.Encode());
			if (!hash.IsEmpty()) {
				m_canceledFileList.insert(hash);
			}
		}
		AddDebugLogLineM(false, logKnownFiles, wxT("Finished reading canceled files"));
	
		return true;
	} catch (const CSafeIOException& e) {
		AddLogLineM(true, CFormat(_("IO error while reading %s file: %s")) % m_filename % e.what());
	}	
	
	return false;
}
Example #28
0
void mpc_filehash(CPlaylist& pl, CList<filehash>& fhs)
{
	fhs.RemoveAll();

	POSITION pos = pl.GetHeadPosition();
	while (pos) {
		CString fn = pl.GetNext(pos).m_fns.GetHead();
		if (AfxGetAppSettings().m_Formats.FindExt(CPath(fn).GetExtension().MakeLower(), true)) {
			continue;
		}

		filehash fh;
		if (!mpc_filehash(fn, fh)) {
			continue;
		}

		fhs.AddTail(fh);
	}
}
Example #29
0
BOOL CPPageExternalFilters::OnInitDialog()
{
	__super::OnInitDialog();

	DragAcceptFiles(TRUE);

	AppSettings& s = AfxGetAppSettings();

	m_pFilters.RemoveAll();

	POSITION pos = s.m_filters.GetHeadPosition();
	while (pos) {
		CAutoPtr<FilterOverride> f(DNew FilterOverride(s.m_filters.GetNext(pos)));

		CString name(_T("<unknown>"));

		if (f->type == FilterOverride::REGISTERED) {
			name = CFGFilterRegistry(f->dispname).GetName();
			if (name.IsEmpty()) {
				name = f->name + _T(" <not registered>");
			}
		} else if (f->type == FilterOverride::EXTERNAL) {
			name = f->name;
			if (f->fTemporary) {
				name += _T(" <temporary>");
			}
			if (!CPath(MakeFullPath(f->path)).FileExists()) {
				name += _T(" <not found!>");
			}
		}

		int i = m_filters.AddString(name);
		m_filters.SetCheck(i, f->fDisabled ? 0 : 1);
		m_filters.SetItemDataPtr(i, m_pFilters.AddTail(f));
	}

	UpdateData(FALSE);

	return TRUE;  // return TRUE unless you set the focus to a control
	// EXCEPTION: OCX Property Pages should return FALSE
}
Example #30
0
bool CLog::Open( LPCTSTR FileName, LOG_OPEN_MODE mode /* = Log_New  */)
{
	if (FileName == NULL) 
	{
		return false;
	}

	CPath File(FileName);
	if (File.IsRelative())
	{
		File = CPath(CPath::MODULE_DIRECTORY,FileName);
	}

	if (m_hLogFile.IsOpen())
	{
		m_hLogFile.Close();
	}

	ULONG nOpenFlags = CFile::modeReadWrite | CFile::modeCreate;
	if (mode == Log_Append) { nOpenFlags |= CFile::modeNoTruncate; }

	if (!m_hLogFile.Open(File, nOpenFlags))
	{
		return false;
	}
	m_FileName = (LPCTSTR)File;
	m_hLogFile.Seek(0,mode == Log_Append ? CFile::end : CFile::begin);

#ifdef _UNICODE

	if(m_hLogFile.GetLength()==0)
	{
		WORD wUNICODE = 0xFEFF;

		m_hLogFile.Write(&wUNICODE, 2);
	}
#endif	 

	return true;
}