Exemplo n.º 1
0
int LoadDatabaseModule(void)
{
	TCHAR szProfile[MAX_PATH];
	PathToAbsoluteT(_T("."), szProfile);
	_tchdir(szProfile);
	szProfile[0] = 0;

	LoadDatabaseServices();

	// find out which profile to load
	if (!getProfile(szProfile, SIZEOF(szProfile)))
		return 1;

	EnsureCheckerLoaded(false); // unload dbchecker

	if (arDbPlugins.getCount() == 0) {
		TCHAR buf[256];
		TCHAR* p = _tcsrchr(szProfile, '\\');
		mir_sntprintf(buf, SIZEOF(buf), TranslateT("Miranda is unable to open '%s' because you do not have any profile plugins installed.\nYou need to install dbx_mmap.dll"), p ? ++p : szProfile);
		MessageBox(0, buf, TranslateT("No profile support installed!"), MB_OK | MB_ICONERROR);
	}

	// find a driver to support the given profile
	bool retry;
	int rc;
	do {
		retry = false;
		if ( _taccess(szProfile, 0) && shouldAutoCreate(szProfile))
			rc = tryCreateDatabase(szProfile);
		else
			rc = tryOpenDatabase(szProfile);

		if (rc > 0) {
			// if there were drivers but they all failed cos the file is locked, try and find the miranda which locked it
			if (fileExist(szProfile)) {
				// file isn't locked, just no driver could open it.
				TCHAR buf[256];
				TCHAR* p = _tcsrchr(szProfile, '\\');
				mir_sntprintf(buf, SIZEOF(buf), TranslateT("Miranda was unable to open '%s', it's in an unknown format.\nThis profile might also be damaged, please run DbChecker which should be installed."), p ? ++p : szProfile);
				MessageBox(0, buf, TranslateT("Miranda can't understand that profile"), MB_OK | MB_ICONERROR);
			}
			else if (!FindMirandaForProfile(szProfile)) {
				TCHAR buf[256];
				TCHAR* p = _tcsrchr(szProfile, '\\');
				mir_sntprintf(buf, SIZEOF(buf), TranslateT("Miranda was unable to open '%s'\nIt's inaccessible or used by other application or Miranda instance"), p ? ++p : szProfile);
				retry = MessageBox(0, buf, TranslateT("Miranda can't open that profile"), MB_RETRYCANCEL | MB_ICONERROR) == IDRETRY;
			}
		}
	}
		while (retry);

	if (rc == ERROR_SUCCESS) {
		InitIni();
		return 0;
	}

	return rc;
}
Exemplo n.º 2
0
int LoadNewPluginsModuleInfos(void)
{
	bModuleInitialized = TRUE;

	hPluginListHeap=HeapCreate(HEAP_NO_SERIALIZE, 0, 0);
	mirandaVersion = (DWORD)CallService(MS_SYSTEM_GETVERSION, 0, 0);
	//
	CreateServiceFunction(MS_PLUGINS_ENUMDBPLUGINS, PluginsEnum);
	CreateServiceFunction(MS_PLUGINS_GETDISABLEDEFAULTARRAY, PluginsGetDefaultArray);
	// make sure plugins can get internal core APIs
	pluginCoreLink.CallService                    = CallService;
	pluginCoreLink.ServiceExists                  = ServiceExists;
	pluginCoreLink.CreateServiceFunction          = CreateServiceFunction;
	pluginCoreLink.CreateServiceFunctionParam     = CreateServiceFunctionParam;
	pluginCoreLink.CreateServiceFunctionObj       = CreateServiceFunctionObj;
	pluginCoreLink.CreateServiceFunctionObjParam  = CreateServiceFunctionObjParam;
	pluginCoreLink.CreateTransientServiceFunction = CreateServiceFunction;
	pluginCoreLink.DestroyServiceFunction         = DestroyServiceFunction;
	pluginCoreLink.CreateHookableEvent            = CreateHookableEvent;
	pluginCoreLink.DestroyHookableEvent           = DestroyHookableEvent;
	pluginCoreLink.HookEvent                      = HookEvent;
	pluginCoreLink.HookEventParam                 = HookEventParam;
	pluginCoreLink.HookEventObj                   = HookEventObj;
	pluginCoreLink.HookEventObjParam              = HookEventObjParam;
	pluginCoreLink.HookEventMessage               = HookEventMessage;
	pluginCoreLink.UnhookEvent                    = UnhookEvent;
	pluginCoreLink.NotifyEventHooks               = NotifyEventHooks;
	pluginCoreLink.SetHookDefaultForHookableEvent = SetHookDefaultForHookableEvent;
	pluginCoreLink.CallServiceSync                = CallServiceSync;
	pluginCoreLink.CallFunctionAsync              = CallFunctionAsync;
	pluginCoreLink.NotifyEventHooksDirect         = CallHookSubscribers;
	pluginCoreLink.CallProtoService               = CallProtoService;
	pluginCoreLink.CallContactService             = CallContactService;
	pluginCoreLink.KillObjectServices             = KillObjectServices;
	pluginCoreLink.KillObjectEventHooks           = KillObjectEventHooks;

	// remember where the mirandaboot.ini goes
	pathToAbsoluteT(_T("mirandaboot.ini"), mirandabootini, NULL);
	// look for all *.dll's
	enumPlugins(scanPluginsDir, 0, 0);
	// the database will select which db plugin to use, or fail if no profile is selected
	if (LoadDatabaseModule()) return 1;
	InitIni();
	//  could validate the plugin entries here but internal modules arent loaded so can't call Load() in one pass
	return 0;
}
Exemplo n.º 3
0
int ParameterAnalysis(int argc,char *argv[],PHGlobal *pglobal,PH_parameter *parameter)
{
	BOOL rin;
	
	if(parameter->bFirstRun)
	{
		if(parameter->bNewIni||parameter->bDaemon||parameter->bAppointIni||parameter->bUser)
		{
			HelpPrint();
			return -1;
		}
		else
		{
			NewIni(parameter->szconfig,pglobal,parameter);
			exit (0);
		}
	}
	if(parameter->bUser)
	{	
#ifndef WIN32
		char command[1024];
		int i = 0;
		memset(command,0,sizeof(command));
		sprintf(command,"su %s -c \"",parameter->szuserName);
		for( i = 0;i < argc; i++ ) {
			if( !strcmp( argv[i], "-u" ) )
				continue;
			else if( i>0 && !strcmp( argv[i-1], "-u"  ) )
				continue;
			sprintf(command,"%s %s",command,argv[i]);
		}
		sprintf(command,"%s \"",command);
		system(command);
/*		ostringstream ostr;
		ostr<<"su "<<userName<<" -c "<<"\""<<argv[0];
		for(m_comIterator=m_comList.begin(); m_comIterator!=m_comList.end();++m_comIterator)
			ostr<<" "<<*m_comIterator;
		ostr<<"\"";
		std::string gstr=ostr.str();
		system(gstr.c_str());*/
#endif
		return -1;
	}  	
	if(parameter->bNewIni)
	{
		memset(parameter->szconfig,0,sizeof(parameter->szconfig));
		if( strlen(parameter->szconfig) == 0 )
#ifndef WIN32
			strcpy(parameter->szconfig,"/etc/phlinux.conf");
#else
			strcpy(parameter->szconfig,"D:\\phlinux.ini");
#endif
		if( NewIni(parameter->szconfig,pglobal,parameter) != 0 )
			return -1;
		BindNic( pglobal,parameter );
	}
	if(parameter->bAppointIni)
	{
		if( LoadFile( pglobal,parameter ) != 0 )
			return -1;
		BindNic( pglobal,parameter );
	}
	if(parameter->bDaemon)
	{
		if(!parameter->bNewIni && !parameter->bAppointIni)
		{
			if( InitIni(pglobal,parameter) != 0 )
				return -1;
			BindNic( pglobal,parameter );
		}
//		LOG(1)(" bNewIni[%d] and bAppointIni[%d] has an unexpected error,please check it.",parameter->bNewIni,parameter->bAppointIni);
//		rin=InDaemon();
//		if(!rin)
//			return -1;	
	}

	return 0;
}
Exemplo n.º 4
0
int checkparameter(int argc,char** argv,PHGlobal *pglobal,PH_parameter *parameter)
{
	int i = 0,repma = 0;

#ifndef WIN32
	strcpy(parameter->szconfig,"/etc/phlinux.conf");
#else
	strcpy(parameter->szconfig,"d:\phlinux.ini");
#endif
	for( i=1;i<argc;i++ ) {
		if(strcmp(argv[i],"-i")==0||strcmp(argv[i],"--interact")==0) {
/*			if(parameter->bAppointIni) {
				if(parameter->bAppointIni)
				{
					HelpPrint();
					return -1;
				}
				parameter->bNewIni=1;
			}*/
			parameter->bNewIni=1;
		}
		else if(strcmp(argv[i],"-d")==0||strcmp(argv[i],"--daemon")==0)
		{
			parameter->bDaemon=1;
		}
		else if(strcmp(argv[i],"-c")==0||strcmp(argv[i],"--config")==0)
		{
			parameter->bAppointIni=1;
			if(++i<argc) {
				if(parameter->bNewIni || strchr(argv[i],'-')!=NULL) {
					HelpPrint();
					return -1;
				}
				memset(parameter->szconfig,0,sizeof(parameter->szconfig));
				strcpy(parameter->szconfig,argv[i]);
			}
			else
			{
				printf("Please appoint configuration file!\n");
				return -1;
			}
		}
		else if(strcmp(argv[i],"-u")==0||strcmp(argv[i],"--user")==0)
		{
			parameter->bUser=1;
			if(++i<argc)
			{
				if(strchr(argv[i],'-')!=NULL)
				{
					HelpPrint();
					return -1;
				}
				strcpy(parameter->szuserName,argv[i]);
			}
			else
			{
				printf("Please appoint user name!\n");
				return -1;
			}
		}
		else if(strcmp(argv[i],"-f")==0||strcmp(argv[i],"--first-run")==0)
		{
			parameter->bFirstRun=1;
		}
		else
		{
			HelpPrint();
			return -1;
		}
	}
	if ( i == 1)
	{
		InitIni(pglobal,parameter);
		BindNic(pglobal,parameter);
	}

	repma = ParameterAnalysis(argc,argv,pglobal,parameter);
	if( repma !=0 )
		return -1;

	return 0;
}