Пример #1
0
BOOL PathMakePathA(LPCSTR path, LPSECURITY_ATTRIBUTES lpAttributes)
{
#if defined(_UWP)
	return FALSE;
#elif defined(_WIN32)
	return (SHCreateDirectoryExA(NULL, path, lpAttributes) == ERROR_SUCCESS);
#else
	const char delim = PathGetSeparatorA(PATH_STYLE_NATIVE);
	char* dup;
	char* p;

	/* we only operate on a non-null, absolute path */
	if (!path || *path != delim)
		return FALSE;

	if (!(dup = _strdup(path)))
		return FALSE;

	for (p = dup; p;)
	{
		if ((p = strchr(p + 1, delim)))
			* p = '\0';

		if (mkdir(dup, 0777) != 0)
			if (errno != EEXIST)
				break;

		if (p)
			*p = delim;
	}

	free(dup);
	return (p == NULL);
#endif
}
Пример #2
0
static BOOL BuildAndSetFolderPath(
    HKEY hKey,
    DWORD dwFlags,
    DWORD csidl,
    LPSTR szPath)
{
    if (dwFlags & CSIDL_MYFLAG_RELATIVE)
    {
        if (!GetWindowsDirectoryA(szPath, MAX_PATH))
            return FALSE;
        PathAddBackslashA(szPath);
    }
#ifdef __APPLE__
    /* On the Apple, user prefs are stored on P:\ which gets
       mapped into the user's preferences folder */
    else if ((dwFlags & (CSIDL_MYFLAG_USERPREFS | CSIDL_MYFLAG_ALLPREFS)) &&
             PathIsDirectoryA ("P:\\"))
    {
        if (dwFlags & CSIDL_MYFLAG_USERPREFS)
            strcpy (szPath, "P:\\User\\");
        else if (dwFlags & CSIDL_MYFLAG_ALLPREFS)
            strcpy (szPath, "P:\\All Users\\");
    }
#endif
    else
    {
        strcpy(szPath, "C:\\");
        if (dwFlags & CSIDL_MYFLAG_USERPREFS)
            strcat (szPath, "Documents and Settings\\User\\");
        else if (dwFlags & CSIDL_MYFLAG_ALLPREFS)
            strcat (szPath, "Documents and Settings\\All Users\\");
    }
    if (CSIDL_Data[csidl].szDefaultPath[0])
        strcat(szPath, CSIDL_Data[csidl].szDefaultPath);
    else
    {
       size_t Len;

       /* Remove trailing backslash, as paths from this set of shell functions
          shouldn't have them */
       Len = strlen (szPath);
       if (szPath[Len - 1] == '\\')
          szPath[Len - 1] = 0;
    }

    if (hKey && RegSetValueExA(hKey,CSIDL_Data[csidl].szValueName,0,REG_SZ,
                               (LPBYTE)szPath,strlen(szPath)+1))
    {
        return FALSE;
    }

    SHCreateDirectoryExA (NULL, szPath, NULL);
    return TRUE;
}
Пример #3
0
int CLAMAPI Scan_Initialize(const wchar_t *pEnginesFolder, const wchar_t *pTempRoot, const wchar_t *pLicenseKey, BOOL bLoadMinDefs) {
    BOOL cant_convert;
    int ret;

    logg("*in Scan_Initialize(pEnginesFolder = %S, pTempRoot = %S)\n", pEnginesFolder, pTempRoot);
    if(!pEnginesFolder)
	FAIL(CL_ENULLARG, "pEnginesFolder is NULL");
    if(!pTempRoot)
	FAIL(CL_ENULLARG, "pTempRoot is NULL");
    if(lock_engine())
	FAIL(CL_ELOCK, "failed to lock engine");
    if(engine) {
	unlock_engine();
	FAIL(CL_ESTATE, "Already initialized");
    }

    if(!(engine = cl_engine_new())) {
	unlock_engine();
	FAIL(CL_EMEM, "Not enough memory for a new engine");
    }
    cl_engine_set_clcb_pre_cache(engine, filetype_cb);
    cl_engine_set_clcb_pre_scan(engine, prescan_cb);
    cl_engine_set_clcb_post_scan(engine, postscan_cb);
    
    minimal_definitions = bLoadMinDefs;
    if(bLoadMinDefs)
	logg("^MINIMAL DEFINITIONS MODE ON!\n");

    if(!WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, pTempRoot, -1, tmpdir, sizeof(tmpdir), NULL, &cant_convert) || cant_convert) {
	free_engine_and_unlock();
	FAIL(CL_EARG, "Can't translate pTempRoot");
    }
    ret = strlen(tmpdir);
    while(ret>0 && tmpdir[--ret] == '\\')
	tmpdir[ret] = '\0';
    if(!ret || ret + 8 + 1 >= sizeof(tmpdir)) {
	free_engine_and_unlock();
	FAIL(CL_EARG, "Bad or too long pTempRoot '%s'", tmpdir);
    }
    memcpy(&tmpdir[ret+1], "\\clamtmp", 9);
    cli_rmdirs(tmpdir);
    if((ret = SHCreateDirectoryExA(NULL, tmpdir, NULL) != ERROR_SUCCESS) && ret != ERROR_ALREADY_EXISTS) {
	free_engine_and_unlock();
	FAIL(CL_ETMPDIR, "Cannot create pTempRoot '%s': error %d", tmpdir, ret);
    }
    if((ret = cl_engine_set_str(engine, CL_ENGINE_TMPDIR, tmpdir))) {
	free_engine_and_unlock();
	FAIL(ret, "Failed to set engine tempdir to '%s': %s", tmpdir, cl_strerror(ret));
    }
    if(!WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, pEnginesFolder, -1, dbdir, sizeof(dbdir), NULL, &cant_convert) || cant_convert) {
	free_engine_and_unlock();
	FAIL(CL_EARG, "Can't translate pEnginesFolder");
    }
    ret = load_db();
    unlock_engine();

    if(!ret) {
	ResetEvent(monitor_event);
	if(!(monitor_hdl = CreateThread(NULL, 0, monitor_thread, NULL, 0, NULL)))
	    logg("^Failed to start db monitoring thread\n");
    }

    logg("*Scan_Initialize: returning %d\n", ret);
    return ret;
}
void DumpRawFiles()
{
	if (Cmd_Argc() != 2)
	{
		return;
	}

	rawFileNames[0] = Cmd_Argv(1);
	currentRawFile = 1;

	for (int i = 0; i < currentRawFile; i++)
	{
		const char* name = rawFileNames[i];
		memset(rawFileBuffer, 0, RAWFILE_BUFSIZE);

		if (LoadRawFile(name, rawFileBuffer, RAWFILE_BUFSIZE))
		{
			char filename[512];
			char dir[512];
			size_t length = strlen(rawFileBuffer);
			sprintf(filename, "%s/%s", "maw", name);

			GetCurrentDirectoryA(sizeof(dir), dir);
			strcat(dir, "/");
			strcat(dir, filename);
			*(strrchr(dir, '/')) = '\0';

			size_t strl = strlen(dir);

			for (size_t i = 0; i < strl; i++)
			{
				if (dir[i] == '/') dir[i] = '\\';
			}

			SHCreateDirectoryExA(NULL, dir, NULL);

			FILE* file = fopen(filename, "wb");

			if (file)
			{
				fwrite(rawFileBuffer, 1, length, file);
				fclose(file);
			}
		}
	}

	currentRawFile = 0;

	return;

	for (int i = 0; i < currentSTable; i++)
	{
		const char* name = sTableNames[i];
		stringTable_t* stringTable;

		if (stringTable = (stringTable_t*)DB_FindXAssetHeader(37, name))
		{
			char filename[512];
			char dir[512];
			sprintf(filename, "%s/%s", "raw", name);

			GetCurrentDirectoryA(sizeof(dir), dir);
			strcat(dir, "/");
			strcat(dir, filename);
			*(strrchr(dir, '/')) = '\0';

			size_t strl = strlen(dir);

			for (size_t i = 0; i < strl; i++)
			{
				if (dir[i] == '/') dir[i] = '\\';
			}

			SHCreateDirectoryExA(NULL, dir, NULL);

			FILE* file = fopen(filename, "w");

			if (file)
			{
				int currentColumn = 0;
				int currentRow = 0;
				int total = stringTable->columns * stringTable->rows;

				for (int i = 0; i < total; i++) {
					char* current = stringTable->data[i * 2];

					fprintf(file, "%s", current);

					bool isNext = ((i + 1) % stringTable->columns) == 0;

					if (isNext) {
						fprintf(file, "\n");
					} else {
						fprintf(file, ",");
					}

					fflush(file);
				}

				fclose(file);
			}
		}
	}

	currentSTable = 0;
}
Пример #5
0
void CMyService::Run()
{
	char szFilePath[_MAX_PATH] = {NULL};
	::GetModuleFileName(NULL, szFilePath, sizeof(szFilePath));

	strcpy_s(szFilePath+strlen(szFilePath)-3,4,"log");

	HANDLE hLogFile = CreateFile(szFilePath,GENERIC_WRITE | GENERIC_READ,FILE_SHARE_WRITE|FILE_SHARE_READ,NULL,OPEN_ALWAYS,0,NULL);

	strcpy_s(szFilePath+strlen(szFilePath)-3,4,"ini");

	CServer server;
	CIni ini;
	ini.SetPathName(szFilePath);

	char szImagePath[MAX_PATH] = {NULL};
	char szRecordPath[MAX_PATH] = {NULL};
	char szPackagePath[MAX_PATH] = {NULL};
	char szCustomLogPath[MAX_PATH] = {NULL};
	char szIpAddress[256] = {NULL};
	int nPort = 7788;

	ini.GetString(_T("PathSetting"),_T("ImagePath"),szImagePath,MAX_PATH);
	ini.GetString(_T("PathSetting"),_T("RecordPath"),szRecordPath,MAX_PATH);
	ini.GetString(_T("PathSetting"),_T("PackagePath"),szPackagePath,MAX_PATH);
	ini.GetString(_T("PathSetting"),_T("UserLogPath"),szCustomLogPath,MAX_PATH);

	if (!PathFileExistsA(szImagePath))
	{
		SHCreateDirectoryExA(NULL,szImagePath,NULL);
	}

	if (!PathFileExistsA(szRecordPath))
	{
		SHCreateDirectoryExA(NULL,szRecordPath,NULL);
	}

	if (!PathFileExistsA(szPackagePath))
	{
		SHCreateDirectoryExA(NULL,szPackagePath,NULL);
	}

	if (!PathFileExistsA(szCustomLogPath))
	{
		SHCreateDirectoryExA(NULL,szCustomLogPath,NULL);
	}

	server.SetPath(hLogFile,szImagePath,szRecordPath);
	server.SetOtherPath(szPackagePath,szCustomLogPath);

	system("cls");
	printf("%s Version %d.%02d\n",m_szServiceName, m_iMajorVersion, m_iMinorVersion);
	server.WriteLogFile(FALSE,"\r\n%s Version %d.%02d",m_szServiceName, m_iMajorVersion, m_iMinorVersion);

	ini.GetString(_T("ServerSetting"),_T("ServerIP"),szIpAddress,256);
	nPort = ini.GetInt(_T("ServerSetting"),_T("ListenPort"),7788);

	BOOL bRet = server.Start(szIpAddress,nPort);

	while (!bRet && m_bIsRunning)
	{
		printf("Start server(%s:%d) failed ! Please check the ip address and the listen port is right.\n"
			,szIpAddress,nPort);

		printf("Wait 60s to retry......\n");

		server.WriteLogFile(TRUE,"Start server(%s:%d) failed ! Please check the ip address and the listen port is right."
			,szIpAddress,nPort);
		server.WriteLogFile(TRUE,"Wait 60s to retry......");

		Sleep(60000);

		ini.GetString(_T("ServerSetting"),_T("ServerIP"),szIpAddress,256);
		nPort = ini.GetInt(_T("ServerSetting"),_T("ListenPort"),7788);

		bRet = server.Start(szIpAddress,nPort);
	}

	printf("Start server(%s:%d) success...\n",szIpAddress,nPort);
	server.WriteLogFile(TRUE,"Start server(%s:%d) success...",szIpAddress,nPort);

	while (m_bIsRunning)
	{
		Sleep(1000);
	}

	server.Shutdown();

	printf("The server(%s:%d) closed.\n",szIpAddress,nPort);
	server.WriteLogFile(TRUE,"The server(%s:%d) closed.",szIpAddress,nPort);

	CloseHandle(hLogFile);
	
}
Пример #6
0
std::string GetPiUserDir(const std::string &subdir)
{

#if defined(_WIN32)

	char appdata_path[MAX_PATH];
	if (SHGetFolderPathA(0, CSIDL_PERSONAL, 0, SHGFP_TYPE_CURRENT, appdata_path) != S_OK) {
		fprintf(stderr, "Couldn't get user documents folder path\n");
		exit(-1);
	}

	std::string path(appdata_path);
	path += "/Pioneer";

	if (!PathFileExistsA(path.c_str())) {
		if (SHCreateDirectoryExA(0, path.c_str(), 0) != ERROR_SUCCESS) {
			fprintf(stderr, "Couldn't create user game folder '%s'", path.c_str());
			exit(-1);
		}
	}

	if (subdir.length() > 0) {
		path += "/" + subdir;
		if (!PathFileExistsA(path.c_str())) {
			if (SHCreateDirectoryExA(0, path.c_str(), 0) != ERROR_SUCCESS) {
				fprintf(stderr, "Couldn't create user game folder '%s'", path.c_str());
				exit(-1);
			}
		}
	}

	return path + "/";

#else

	std::string path = getenv("HOME");

#ifdef __APPLE__
	path += "/Library/Application Support/Pioneer";
#else
	path += "/.pioneer";
#endif

	struct stat st;
	if (stat(path.c_str(), &st) < 0 && mkdir(path.c_str(), S_IRWXU|S_IRWXG|S_IRWXO) < 0) {
		fprintf(stderr, "Couldn't create user dir '%s': %s\n", path.c_str(), strerror(errno));
		exit(-1);
	}

	if (subdir.length() > 0) {
		path += "/" + subdir;
		if (stat(path.c_str(), &st) < 0 && mkdir(path.c_str(), S_IRWXU|S_IRWXG|S_IRWXO) < 0) {
			fprintf(stderr, "Couldn't create user dir '%s': %s\n", path.c_str(), strerror(errno));
			exit(-1);
		}
	}

	return path + "/";

#endif

}