Ejemplo n.º 1
0
MIR_CORE_DLL(HANDLE) mir_createLog(const char* pszName, const TCHAR *ptszDescr, const TCHAR *ptszFile, unsigned options)
{
	if (ptszFile == NULL)
		return NULL;

	Logger *result = new Logger(pszName, ptszDescr, ptszFile, options);
	if (result == NULL)
		return NULL;

	int idx = arLoggers.getIndex(result);
	if (idx != -1) {
		delete result;
		return &arLoggers[idx];
	}

	FILE *fp = _tfopen(ptszFile, _T("ab"));
	if (fp == NULL) {
		TCHAR tszPath[MAX_PATH];
		_tcsncpy_s(tszPath, ptszFile, _TRUNCATE);
		CreatePathToFileT(tszPath);
	}
	else fclose(fp);

	DeleteFile(ptszFile);
	arLoggers.insert(result);
	return result;
}
Ejemplo n.º 2
0
// called by the UI, return 1 on success, use link to create profile, set error if any
int makeDatabase(TCHAR * profile, DATABASELINK * link, HWND hwndDlg)
{
	TCHAR buf[256];
	int err=0;
	// check if the file already exists
	TCHAR * file = _tcsrchr(profile, '\\');
	if (file) file++;
	if (_taccess(profile, 0) == 0) {
		// file already exists!
		mir_sntprintf(buf, SIZEOF(buf), TranslateTS( _T("The profile '%s' already exists. Do you want to move it to the ")
			_T("Recycle Bin? \n\nWARNING: The profile will be deleted if Recycle Bin is disabled.\n")
			_T("WARNING: A profile may contain confidential information and should be properly deleted.")), file );
		if ( MessageBox(hwndDlg, buf, TranslateT("The profile already exists"), MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2) != IDYES )
			return 0;

		// move the file
		SHFILEOPSTRUCT sf = {0};
		sf.wFunc = FO_DELETE;
		sf.pFrom = buf;
		sf.fFlags = FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_SILENT | FOF_ALLOWUNDO;
		mir_sntprintf(buf, SIZEOF(buf), _T("%s\0"), profile);
		if ( SHFileOperation(&sf) != 0 ) {
			mir_sntprintf(buf, SIZEOF(buf),TranslateT("Couldn't move '%s' to the Recycle Bin, Please select another profile name."),file);
			MessageBox(0,buf,TranslateT("Problem moving profile"),MB_ICONINFORMATION|MB_OK);
			return 0;
		}
		// now the file should be gone!
	}
	// ask the database to create the profile
	CreatePathToFileT(profile);
	char *prf = makeFileName(profile);
	if (link->makeDatabase(prf, &err)) {
		mir_sntprintf(buf, SIZEOF(buf),TranslateT("Unable to create the profile '%s', the error was %x"),file, err);
		MessageBox(hwndDlg,buf,TranslateT("Problem creating profile"),MB_ICONERROR|MB_OK);
		mir_free(prf);
		return 0;
	}
	dbCreated = true;
	// the profile has been created! woot
	mir_free(prf);
	return 1;
}
Ejemplo n.º 3
0
// enumerate all plugins that had valid DatabasePluginInfo()
static int FindDbPluginAutoCreate(const char*, DATABASELINK * dblink, LPARAM lParam)
{
	TCHAR* tszProfile = ( TCHAR* )lParam;

	int res = DBPE_CONT;
	if (dblink && dblink->cbSize == sizeof(DATABASELINK)) {
		CreatePathToFileT( tszProfile );

		int err;
		char *szProfile = makeFileName( tszProfile );
		if (dblink->makeDatabase(szProfile, &err) == 0) {
			dbCreated = true;
			if ( !dblink->Load(szProfile, &pluginCoreLink)) {
				fillProfileName( tszProfile );
				res = DBPE_DONE;
			}
			else res = DBPE_HALT;
		}
		mir_free(szProfile);
	}
	return res;
}
Ejemplo n.º 4
0
// enumerate all plugins that had valid DatabasePluginInfo()
static int tryCreateDatabase(const TCHAR* ptszProfile)
{
	TCHAR* tszProfile = NEWTSTR_ALLOCA(ptszProfile);
	CreatePathToFileT(tszProfile);

	for (int i=0; i < arDbPlugins.getCount(); i++) {
		DATABASELINK* p = arDbPlugins[i];

		int err = p->makeDatabase(tszProfile);
		if (err == ERROR_SUCCESS) {
			g_bDbCreated = true;
			MIDatabase *pDb = p->Load(tszProfile);
			if (pDb != NULL) {
				fillProfileName(tszProfile);
				currDblink = p;
				db_setCurrent(currDb = pDb);
				return 0;
			}
			return 1;
		}
	}
	return 1;
}