예제 #1
0
파일: main.cpp 프로젝트: mayhem/freeamp
int APIENTRY WinMain(HINSTANCE hInstance, 
					 HINSTANCE hPrevInstance,
		 			 LPSTR lpszCmdLine, 
					 int cmdShow)
{
    HANDLE runOnceMutex = NULL;
    bool   allowMultipleInst = false;

    g_hinst = hInstance;

    // should we allow FreeAmp to run?
    struct stat st;
    char path[MAX_PATH];
    char arg0[MAX_PATH];

    getcwd(path, sizeof(path));

    strcpy(arg0, __argv[0]);
    char* slash = strrchr(arg0, '\\');

    if(slash)
    {
        *slash = 0x00;

        if(strcasecmp(path, arg0))
        {
            chdir(arg0);
            strcpy(path, arg0);
        }
    }

    strcat(path, "\\NeedToRebootForUpdate");
    if(!stat(path, &st))
    {
        MessageBox(NULL, kReboot, "You Need To Reboot...", 
                            MB_OK|MB_ICONINFORMATION|MB_SETFOREGROUND);
        return 0;
    }

    FAContext *context = new FAContext;
    context->prefs = new Win32Prefs();
    context->prefs->GetPrefBoolean(kAllowMultipleInstancesPref, &allowMultipleInst);
    context->hInstance = hInstance;

	if (!allowMultipleInst)
    {
	   if(SendCommandLineToRealJukebox())
	   {
           return 0;
	   }

       runOnceMutex = CreateMutex(	NULL,
	    						    TRUE,
		    					    The_BRANDING" Should Only Run One Time!");

       if(GetLastError() == ERROR_ALREADY_EXISTS)
	   { 
           SendCommandLineToHiddenWindow();
        
           CloseHandle(runOnceMutex);
           return 0;
	   }
	}
    // This causes a dynamic link error on some non NT systems, and
    // it didn't seem to help on multiprocessor NT systems, so I'm
    // commenting it.
    //if(IsWinNT() && IsMultiProcessor())
    //    SetProcessAffinityMask(GetCurrentProcess(), 0);

    WSADATA sGawdIHateMicrosoft;
    WSAStartup(0x0002,  &sGawdIHateMicrosoft);


    context->log = new LogFile("freeamp.log");

    // find all the plug-ins we use
    Registrar* registrar;
    Registry* lmc;
    Registry* pmi;
    Registry* pmo;
    Registry*  ui;

    registrar = new Registrar;

    registrar->SetSubDir("plugins");
    registrar->SetSearchString("*.lmc");
    lmc = new Registry;
    registrar->InitializeRegistry(lmc, context->prefs);

    registrar->SetSearchString("*.pmi");
    pmi = new Registry;
    registrar->InitializeRegistry(pmi, context->prefs);

    registrar->SetSearchString("*.pmo");
    pmo = new Registry;
    registrar->InitializeRegistry(pmo, context->prefs);

    registrar->SetSearchString("*.ui");
    ui = new Registry;
    registrar->InitializeRegistry(ui, context->prefs);

    delete registrar;

    bool reclaimFileTypes, askBeforeReclaiming;
    uint32 length = sizeof(path);
    context->prefs->GetPrefBoolean(kReclaimFiletypesPref, &reclaimFileTypes);
    context->prefs->GetPrefBoolean(kAskToReclaimFiletypesPref, &askBeforeReclaiming);
    context->prefs->GetPrefString(kInstallDirPref, path, &length);
    strcat(path, "\\freeamp.exe");

    if(reclaimFileTypes)
        ReclaimFileTypes(path, askBeforeReclaiming);

    // create the player
	Player *player = Player::GetPlayer(context);

    // we are the first instance so create our hidden window
    Thread* thread = Thread::CreateThread();

    thread->Create(CreateHiddenWindow, context);

    // need a way to signal main thread to quit...
    Semaphore *termination = new Semaphore();
    
    // register items... we give up ownership here
    player->SetTerminationSemaphore(termination);
    player->RegisterLMCs(lmc);
    player->RegisterPMIs(pmi);
    player->RegisterPMOs(pmo);
    player->RegisterUIs(ui);

    // Let the player know if there are special requests from the user
    // __argc and __argv are magical variables provided for us
    // in MS's STDLIB.H file. 
    player->SetArgs(__argc, __argv);

    // kick things off... player is now in charge!
    player->Run();

    // sit around and twiddle our thumbs
    termination->Wait();

    // clean up our act
    delete player;
	delete context;
    delete thread;

	if (!allowMultipleInst)
       CloseHandle(runOnceMutex);

	WSACleanup();

	return 0;
}
예제 #2
0
파일: main.cpp 프로젝트: mayhem/freeamp
bool SendCommandLineToRealJukebox()
{
	bool result = false;

	Registrar registrar;
	Registry formatRegistry;
	Win32Prefs prefs;
	vector<DownloadFormatInfo*> formats;

	// init
    registrar.SetSubDir("plugins");
    registrar.SetSearchString("*.dlf");
    registrar.InitializeRegistry(&formatRegistry, &prefs);

    const RegistryItem* module = NULL;
    DownloadFormat* dlf = NULL;
    int32 i = 0;

    while((module = formatRegistry.GetItem(i++)))
    {
        dlf = (DownloadFormat*) module->InitFunction()(NULL);

        if(dlf)
        {
            DownloadFormatInfo dlfi;

            uint32 index = 0;

            // error != kError_NoMoreFormats
            while(IsntError(dlf->GetSupportedFormats(&dlfi, index++)))
            {
                dlfi.SetRef(dlf);
                formats.push_back(new DownloadFormatInfo(dlfi));
            }
        }
    }

	vector<DownloadFormatInfo*>::iterator dlfIter;

	if(__argc > 1)
    {
        char* extension;

		extension = strrchr(__argv[1], '.');

		if(extension)
        {
			extension++;

			for(dlfIter = formats.begin(); 
				dlfIter != formats.end(); 
				dlfIter++)
			{
				if(!strcasecmp(extension, (*dlfIter)->GetExtension()))
                {
					vector<DownloadItem*> items;
					char url[MAX_PATH + 7];
					uint32 size = sizeof(url);
					Error err;

					err = FilePathToURL(__argv[1], url, &size);

					if(IsntError(err))
					{
						(*dlfIter)->GetRef()->ReadDownloadFile(url, 
															   &items);

						vector<DownloadItem*>::iterator dliIter;

						for(dliIter = items.begin(); 
							dliIter != items.end(); 
							dliIter++)
						{
							MetaData metadata = (*dliIter)->GetMetaData();

							if(	strcasecmp("mp3", metadata.FormatExtension().c_str()) &&
								strcasecmp("mp2", metadata.FormatExtension().c_str()) &&
								strcasecmp("mp1", metadata.FormatExtension().c_str()) &&
								strcasecmp("m3u", metadata.FormatExtension().c_str()) &&
								strcasecmp("pls", metadata.FormatExtension().c_str()) )
							{
                                bool rjFound = false;

								result = true;

								LONG regErr;
								HKEY key;

                                regErr = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
													  "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\realjbox.exe",
													  0, 
													  KEY_WRITE|KEY_READ,
													  &key);

                                if(regErr == ERROR_SUCCESS)
                                {
                                    char buf[MAX_PATH*2];
                                    DWORD len = sizeof(buf);
                                    DWORD type;

                                    regErr = RegQueryValueEx(key,
                                                             NULL, 
                                                             NULL, 
                                                             &type, 
                                                             (LPBYTE)buf, 
                                                             &len);

                                    if(regErr == ERROR_SUCCESS)
                                    {
                                        rjFound = true;

                                        strcat(buf, " /m application/vnd.rn-rn_music_package ");
                                        strcat(buf, __argv[1]);

                                        WinExec(buf, SW_NORMAL);
                                    }
                                }

                                if(!rjFound)
                                {
                                    MessageBox(NULL, The_BRANDING" does not support the formats "
                                                     "contained in this Music Package.  The download "
                                                     "will be aborted.", "Unsupported Formats", MB_OK);

                                    DeleteFile(__argv[1]);
                                }
							}
						}
					}

                    break;
                }
			}

		}
    }

	// clean up
	for(dlfIter = formats.begin(); 
		dlfIter != formats.end(); 
		dlfIter++)
	{
		delete (*dlfIter)->GetRef();
		delete (*dlfIter);
	}

	return result;
}