📄 player.cpp
字号:
if (giveToDLM)
m_dlm->ReadDownloadFile(url);
else
{
if (giveToTheme)
AddTheme(url);
else
m_plm->AddItem(url);
}
}while(FindNextFile(handle, &data));
FindClose(handle);
}
#else
strcpy(path, arg);
//printf("Path: %s\r\n", path);
// make sure we have an absolute path
ResolvePath(&path);
//printf("Resolved: %s\r\n", path);
// format this path as a URL
uint32 length = _MAX_PATH;
FilePathToURL(path, url, &length);
//printf("URL: %s\r\n", url);
// who needs to get this, plm or dlm?
bool giveToDLM = false;
bool giveToTheme = false;
char* extension = NULL;
extension = strrchr(url, '.');
if(extension)
{
DownloadFormatInfo dlfi;
uint32 i = 0;
extension++;
while(IsntError(m_dlm->GetSupportedDownloadFormats(&dlfi, i++)))
{
if(!strcasecmp(extension, dlfi.GetExtension()))
{
giveToDLM = true;
break;
}
}
if (!strcasecmp(extension, themeExtension))
giveToTheme = true;
}
if (giveToDLM)
m_dlm->ReadDownloadFile(url);
else
{
if (giveToTheme)
AddTheme(url);
else {
struct stat st;
if (stat(path, &st) == 0)
if (!(st.st_mode & S_IFDIR))
m_plm->AddItem(url);
}
}
#endif
}
delete [] path;
delete [] url;
}
void Player::AddTheme(char *url)
{
char szSavedTheme[_MAX_PATH], szNewTheme[_MAX_PATH];
char *pTempFile;
uint32 iLen = _MAX_PATH;
m_context->prefs->GetPrefString(kThemePathPref,
szSavedTheme, &iLen);
iLen = _MAX_PATH;
URLToFilePath(url, szNewTheme, &iLen);
pTempFile = tmpnam(NULL);
if (CopyFile(szNewTheme, pTempFile, false))
AcceptEvent(new LoadThemeEvent(pTempFile, szSavedTheme));
}
void
Player::
Usage(const char *progname)
{
if(m_didUsage)
return;
printf(The_BRANDING " version " FREEAMP_VERSION " -- Usage:\n\n");
printf("%s [-save] [-ui <UI plugin name>] <MP3 file/stream> "
"[MP3 file/stream] ...\n\n", progname);
printf("Example command line:\n\n");
printf(" %s -ui freeamp.ui mysong1.mp3 mysong2.mp3\n\n", progname);
m_didUsage = true;
}
int32
Player::
CompareNames(const char *p1, const char *p2)
{
// windows plugins and unix plugins are named differently...
#if defined( WIN32 ) || defined ( __BEOS__ )
return strcasecmp(p1, p2);
#else
// ut << "Comparing: " << p1 << " to " << p2 << endl;
if (strcmp(p1, p2))
{
// no direct match, try w/ .ui appended...
char foo[512];
sprintf(foo, "%s.ui", p2);
// ut << "Comparing: " << p1 << " to " << foo << endl;
if (strcmp(p1, foo))
{
// no plugin.ui match, try plugin-arch.ui
char foo[512];
sprintf(foo, "%s.ui", p2);
// cout << "Comparing: " << p1 << " to " << foo << endl;
if (strcmp(p1, foo))
{
// no match
return 1;
}
else
{
return 0;
}
}
else
{
return 0;
}
}
else
{
return 0;
}
#endif
}
void
Player::
Run()
{
uint32 uiListIndex = 0;
char *name = NULL;
uint32 len = 256;
Error error = kError_NoErr;
int32 uisActivated = 0;
bool bValue;
m_context->prefs->GetPrefBoolean(kUseDebugLogPref, &bValue);
if (bValue)
m_context->log->Open();
m_context->prefs->GetPrefBoolean(kLogInputPref, &bValue);
if (bValue)
m_context->log->AddLogLevel(LogInput);
m_context->prefs->GetPrefBoolean(kLogOutputPref, &bValue);
if (bValue)
m_context->log->AddLogLevel(LogOutput);
m_context->prefs->GetPrefBoolean(kLogDecodePref, &bValue);
if (bValue)
m_context->log->AddLogLevel(LogDecode);
m_context->prefs->GetPrefBoolean(kLogPerformancePref, &bValue);
if (bValue)
m_context->log->AddLogLevel(LogPerf);
bool loadSecondaryUIs = true;
// which ui should we instantiate first??
if (m_argUIList->size() == 0)
{
const char *pref = kUIPref;
name = new char[len];
#ifdef unix
if (!getenv("DISPLAY")) {
pref = kTextUIPref;
loadSecondaryUIs = false;
}
#endif
while ((error = m_context->prefs->GetPrefString(pref, name, &len)) ==
kError_BufferTooSmall)
{
delete[] name;
len++;
name = new char[len];
}
#ifdef unix
#ifndef HAVE_GTK
if (!strcmp("freeamp.ui", name)) {
pref = kTextUIPref;
while ((error = m_context->prefs->GetPrefString(pref, name, &len)) ==
kError_BufferTooSmall)
{
delete [] name;
len++;
name = new char[len];
}
}
#endif
#endif
}
else
{
char *orig = (*m_argUIList)[uiListIndex++];
// RAK: This pointer is later re-used when the size of the
// contents may have changed. See comment below.
name = new char[strlen(orig) + 1];
strcpy(name, orig);
}
// at this point add in any extra UIs that might be wanted
len = 255;
char* secondaries = new char[len];
while ((error = m_context->prefs->GetPrefString(kSecondaryUIPref,
secondaries, &len)) ==
kError_BufferTooSmall)
{
delete[] secondaries;
len++;
secondaries = new char[len];
}
// We use a set to make sure that only one of each is invoked
set<string> secondaryUIList;
char* cp = secondaries;
char* ui = cp;
while((cp = strchr(cp, ';')))
{
*cp = 0x00;
secondaryUIList.insert(string(ui));
//MessageBox(NULL, name, "name", MB_OK);
cp++;
ui = cp;
}
if(*ui)
{
secondaryUIList.insert(string(ui));
//MessageBox(NULL, name, "name", MB_OK);
}
set<string>::const_iterator i;
for(i = secondaryUIList.begin(); i != secondaryUIList.end(); i++)
{
char* ui = new char[(*i).size() + 1];
strcpy(ui, (*i).c_str());
m_argUIList->push_back(ui);
}
delete [] secondaries;
#ifdef HAVE_GTK
if (strcmp("freeamp.ui", name))
loadSecondaryUIs = false;
#endif
len = 255;
char *downloadName = new char[len];
while ((error = m_context->prefs->GetPrefString(kDownloadManagerUIPref,
downloadName, &len)) ==
kError_BufferTooSmall)
{
delete[] downloadName;
len++;
downloadName = new char[len];
}
len = 255;
char *musicBrowserName = new char[len];
while ((error = m_context->prefs->GetPrefString(kMusicBrowserUIPref,
musicBrowserName, &len)) ==
kError_BufferTooSmall)
{
delete[] musicBrowserName;
len++;
musicBrowserName = new char[len];
}
#ifdef WIN32
len = 255;
char *toolbarName = new char[len];
while ((error = m_context->prefs->GetPrefString(kToolbarUIPref,
toolbarName, &len)) ==
kError_BufferTooSmall)
{
delete[] toolbarName;
len++;
toolbarName = new char[len];
}
#endif
if (IsntError(error))
{
while (*name)
{
RegistryItem *item = NULL;
// UserInterface *ui = NULL;
int32 i = 0;
while (NULL != (item = m_uiRegistry->GetItem(i++)))
{
if (!CompareNames(item->Name(), downloadName) && loadSecondaryUIs)
{
m_ui = (UserInterface *) item->InitFunction()(m_context);
Error er = m_ui->Init(SECONDARY_UI_STARTUP);
if (IsntError(er))
{
RegisterActiveUI(m_ui);
m_downloadUI = m_ui;
}
else
{
delete m_ui;
m_ui = NULL;
}
}
else if (!CompareNames(item->Name(), musicBrowserName) &&
loadSecondaryUIs)
{
m_ui = (UserInterface *) item->InitFunction()(m_context);
Error er = m_ui->Init(SECONDARY_UI_STARTUP);
if (IsntError(er))
{
RegisterActiveUI(m_ui);
m_browserUI = m_ui;
}
else
{
delete m_ui;
m_ui = NULL;
}
}
#ifdef WIN32
else
if (!CompareNames(item->Name(), toolbarName))
{
m_ui = (UserInterface *) item->InitFunction()(m_context);
Error er = m_ui->Init(SECONDARY_UI_STARTUP);
if (IsntError(er))
RegisterActiveUI(m_ui);
else
{
delete m_ui;
m_ui = NULL;
}
}
#endif
else if (!CompareNames(item->Name(), name))
{
m_ui = (UserInterface *) item->InitFunction()(m_context);
//m_ui->SetPropManager((Properties *) this);
//m_ui->SetPlaylistManager(m_plm);
//m_ui->SetArgs(m_argc, m_argv);
Error er = m_ui->Init((uisActivated == 0) ? PRIMARY_UI
: SECONDARY_UI_STARTUP);
if (IsntError(er))
{
RegisterActiveUI(m_ui);
uisActivated++;
}
else
{
delete m_ui;
m_ui = NULL;
}
// break; Don't think this'll work now...
}
}
if(uiListIndex < m_argUIList->size())
{
char *p = (*m_argUIList)[uiListIndex++];
// RAK: Boundschecker was pissed about this. This copy
// may be larger than the space allocated on line 524
// So, delete the old pointer and create a new one.
delete name;
name = new char[strlen(p) + 1];
strcpy(name, p);
}
else
{
*name = '\0';
}
}
if (!uisActivated)
{
#ifdef WIN32
MessageBox(NULL, The_BRANDING" cannot find a valid user interface module.\r\n"
"Please make sure that " the_BRANDING" is installed correctly.\r\n"
"You may wish to remove and reinstall " the_BRANDING" to fix this problem",
BRANDING" Error", MB_OK);
#else
const char *thePath = getenv(FREEAMP_PATH_ENV);
if (thePath == NULL)
thePath = m_context->prefs->GetLibDirs();
cerr << "No UI plugin in '" << thePath << "' matched 'plugins/" << name << "' or 'plugins/" << name << ".ui.'" << endl;
cerr << The_BRANDING << " will quit." << endl;
#endif
Event *e = new Event(CMD_QuitPlayer);
AcceptEvent(e);
e = new Event(INFO_ReadyToDieUI);
AcceptEvent(e);
}
}
m_eventServiceThread = Thread::CreateThread();
m_eventServiceThread->Create(Player::EventServiceThreadFunc, this);
m_context->catalog->StartTimer();
delete[] name;
delete[] musicBrowserName;
delete[] downloadName;
#ifdef WIN32
delete[] toolbarName;
#endif
}
void
Player::
EventServiceThreadFunc(void *pPlayer)
{
Player *pP = (Player *) pPlayer;
Event *pC;
int32 rtnVal = 0x0;
while (rtnVal == 0)
{ // serviceEvent will return 1 if error or time
if (pP->m_eventQueue->Peek() == NULL)
pP->m_eventSem->Wait();
pC = pP->m_eventQueue->Read();
if (pC)
{
rtnVal = pP->ServiceEvent(pC);
}
}
}
int32
Player::
RegisterActiveUI(UserInterface * ui)
{
GetUIManipLock();
if (m_uiList && ui)
{
m_uiList->push_back(ui);
ReleaseUIManipLock();
return 0;
}
else
{
ReleaseUIManipLock();
return 255;
}
}
int32
Player::
RegisterLMCs(Registry * registry)
{
int32 result = 0;
m_lmcMutex->Acquire();
if (m_lmcRegistry)
{
Registrar::CleanupRegistry(m_lmcRegistry);
delete m_lmcRegistry;
}
if (m_lmcExtensions) {
map<string, RegistryItem *>::iterator iter = m_lmcExtensions->begin();
for (; iter != m_lmcExtensions->end(); iter++)
delete (*iter).second;
delete m_lmcExtensions;
}
m_lmcExtensions = new map<string, RegistryItem *>;
m_lmcRegistry = registry;
RegistryItem *lmc_item;
LogicalMediaConverter *lmc;
int iItems = registry->CountItems();
for (int iLoop = 0; iLoop < iItems; iLoop++)
{
RegistryItem* temp = registry->GetItem(iLoop);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -