Esempio n. 1
0
WINERROR ScrGetEncoderClsid(
	const WCHAR*	format, 
	CLSID*			pClsid
	)
{
	Gdiplus::GdiplusStartupInput input;
	ULONG_PTR token;
	PVOID MemToFree = NULL;
	
	Gdiplus::Status status = Gdiplus::GdiplusStartup(&token, &input, 0);
		
	if (status == Gdiplus::Ok)
	{
		UINT num = 0;
		UINT size = 0;

		Gdiplus::ImageCodecInfo* pImageCodecInfo = NULL;

		Gdiplus::GetImageEncodersSize(&num, &size);
		
		if(size == 0)
		{
			return ERROR_UNSUCCESSFULL;
		}

		pImageCodecInfo = (Gdiplus::ImageCodecInfo*)(AppAlloc(size));
		
		if(pImageCodecInfo == NULL)
		{
			return ERROR_UNSUCCESSFULL;
		}

		GetImageEncoders(num, size, pImageCodecInfo);

		for(UINT i = 0; i < num; ++i)
		{
			if(wcscmp(pImageCodecInfo[i].MimeType, format) == 0 )
			{
				MemToFree = (PVOID)pImageCodecInfo;
				*pClsid = pImageCodecInfo[i].Clsid;
				AppFree(MemToFree);
				
				return NO_ERROR;
			}
		}

		MemToFree = (PVOID)pImageCodecInfo;
		AppFree(MemToFree);
	}

	return ERROR_UNSUCCESSFULL;
}
Esempio n. 2
0
static void FreeListSE(void)
{
  int             iS;
  T_ListSymEquiv  *LSE;


  LSE = ListSE;

  for (iS = 0; iS < nSite; iS++)
  {
    AppFree(LSE->SE, LSE->nSE);
    LSE++;
  }

  AppFree(ListSE, nSite); ListSE = NULL;
}
Esempio n. 3
0
//
//	Generates a string containing the Prefix, random GUID based on specified Seed, and the Postfix.
//
LPTSTR GenGuidName(
	IN OUT	PULONG	pSeed,					// pointer to a random seed value
	IN		LPTSTR	Prefix OPTIONAL,		// pointer to a prefix string (optional)
	IN		LPTSTR	Postfix OPTIONAL,		// pointer to a postfix string (optional)
	IN		BOOL	bQuoted
	)
{
	ULONG	NameLen = GUID_STR_LENGTH + 1;
	LPTSTR	GuidStr, Name = NULL;
	GUID	Guid;

	GenGuid(&Guid, pSeed);
	if (GuidStr = GuidToString(&Guid, bQuoted))
	{
		if (Prefix)
			NameLen += lstrlen(Prefix);
		if (Postfix)
			NameLen += lstrlen(Postfix);

		if (Name = (LPTSTR)AppAlloc(NameLen*sizeof(_TCHAR)))
		{
			Name[0] = 0;

			if (Prefix)
				lstrcpy(Name, Prefix);
		
			lstrcat(Name, GuidStr);
			if (Postfix)
				lstrcat(Name, Postfix);
		}
		AppFree(GuidStr);
		
	}	// if (GuidStr = 
	return(Name);
}
Esempio n. 4
0
void MsgLoop(){
	MSG msg = { 0 };
	int done = 0;
	DWORD lastTime = GetTickCount();

	while (!done)
	{
		int gotMsg = (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) != 0);
		DWORD curTime = GetTickCount();
		float deltaTime = (float)(curTime - lastTime) / 1000.0f;
		lastTime = curTime;

		if (gotMsg)
		{
			if (msg.message == WM_QUIT)
			{
				done = 1;

				AppFree();
			}
			else
			{
				TranslateMessage(&msg);
				DispatchMessage(&msg);
			}
		}
		else
		{
			AppUpdate();
			AppRender();
		}
	}
}
Esempio n. 5
0
VOID KeyStoreCleanup(VOID)
{
	if (g_pKeyProcessList)
		AppFree(g_pKeyProcessList);

	if (g_KeyStoreTable)
		HandleReleaseTable(g_KeyStoreTable);
}
Esempio n. 6
0
File: zct.c Progetto: momtx/meataxe
static void Cleanup()

{
    if (OutputFile != NULL)
	fclose(OutputFile);
    if (InputFile != NULL)
	fclose(InputFile);
    AppFree(App);
}
Esempio n. 7
0
int main(int argc, const char **argv)

{
    int mj;

    if (Init(argc,argv) != 0)
    {
	MTX_ERROR("Initialization failed");
	return -1;
    }

    /* Main loop: for all constituents of M
       ------------------------------------ */
    for (mj = 0; mj < InfoM.NCf; mj++)
    {
	MatRep_t *rep_m;	    /* Generators for const. of M */
	int nj;

	if (InfoM.Cf[mj].peakword < 0)
	{
	    MESSAGE(0,("WARNING: No peak word word available for %s%s\n",
		InfoM.BaseName,Lat_CfName(&InfoM,mj)));
	}
	MESSAGE(0,("%s%s ",InfoM.BaseName,Lat_CfName(&InfoM,mj)));

	/* Read the generators for the <mj>-th contituent of M, and find
	   the corresponding (=contragredient) constituent in N.
	   ------------------------------------------------------------- */
	rep_m = Lat_ReadCfGens(&InfoM,mj,InfoM.Cf[mj].peakword >= 0 ? LAT_RG_STD : 0);
	nj = FindConstituentInN(mj,rep_m);

	/* Calculate the P and Q matrix for this constituent
	   ------------------------------------------------- */
	if (nj >= 0)
	{
	    MESSAGE(0,(" <--> %s%s\n",InfoN.BaseName,
		Lat_CfName(&InfoN,nj)));
	    TKInfo.CfIndex[0][TKInfo.NCf] = mj;
	    TKInfo.CfIndex[1][TKInfo.NCf] = nj;
	    MakePQ(TKInfo.NCf,mj,nj);
	    TKInfo.NCf++;
	}
	else
	    MESSAGE(0,(" not found in %s\n",InfoN.BaseName));

	/* Clean up
	   -------- */
	MrFree(rep_m);
    }

    CalcDim();				/* Calculate dimension */
    TK_WriteInfo(&TKInfo,TkiName);	/* Write .tki file */
    if (App != NULL) AppFree(App);
    return 0;
}
Esempio n. 8
0
static BOOL KeyStoreReleaseContext(
   HANDLE	Key,
   PVOID*	pContext
   )
{
	PKEY_CONTEXT KeyCtx = (PKEY_CONTEXT)pContext;
	BOOL Ret = TRUE;

	while ( !IsListEmpty(&KeyCtx->ClipboardChain) )
	{
		PCLIPBOARD_ENTRY Entry;
		PLIST_ENTRY ListEntry = RemoveHeadList(&KeyCtx->ClipboardChain);
		Entry = CONTAINING_RECORD(ListEntry,CLIPBOARD_ENTRY,qLink);

		if ( Entry->Buffer ){
			AppFree( Entry->Buffer );
			Entry->Buffer = NULL;
		}
		AppFree ( ListEntry );
	}

	return(Ret);
}
Esempio n. 9
0
//
//	Writes the specified data buffer to a file.
//
WINERROR FilesSaveFileA(
	LPSTR	FileName,	// full path to the file to write
	PCHAR	Buffer,		// buffer containing a data to write
	ULONG	Size,		// size of the buffer in bytes
	ULONG	Flags		// any of FILE_FLAG_XXX constants
	)
{
	WINERROR Status = NO_ERROR;
	HANDLE	hFile;
	LPWSTR	pPath;
	ULONG	bWritten, Disposition = (Flags & (FILE_FLAG_OVERWRITE | FILE_FLAG_APPEND)) ? OPEN_ALWAYS : CREATE_NEW;

	if (pPath = FilesExpandEnvironmentVariablesAtoW(FileName))
	{
		hFile = CreateFileW(pPath, GENERIC_READ | GENERIC_WRITE, 0, NULL, Disposition, FILE_ATTRIBUTE_NORMAL, 0);

		while ((hFile == INVALID_HANDLE_VALUE) && ((Status = GetLastError()) == ERROR_SHARING_VIOLATION) && (Flags & FILE_FLAG_WAIT_SHARE))
		{
			Sleep(10);
			hFile = CreateFile(FileName, GENERIC_READ | GENERIC_WRITE, 0, NULL, Disposition, FILE_ATTRIBUTE_NORMAL, 0);
		}

		if (hFile != INVALID_HANDLE_VALUE)
		{
			if (Flags & FILE_FLAG_APPEND)
				SetFilePointer(hFile, 0, NULL, FILE_END);

			if (WriteFile(hFile, Buffer, Size, &bWritten, NULL))
			{
				SetEndOfFile(hFile);
				Status = NO_ERROR;
			}
			else
				Status = GetLastError();

			CloseHandle(hFile);
		}	// if (hFile != INVALID_HANDLE_VALUE)
		else
		{
			ASSERT(Status != NO_ERROR);
		}

		AppFree(pPath);
	}	// if (pPath = FilesExpandEnvironmentVariablesAtoW(FileName))
	else
		Status = ERROR_NOT_ENOUGH_MEMORY;
 
	return(Status);
}
Esempio n. 10
0
//
//	Searches for files according to the specified Mask starting from the specified Path. 
//	For every file found allocates FILE_DESCW structure and links all theese structures into the FileListHead.
//	Returns number of files found.
//
ULONG	FilesScanA(
	PCHAR				Path,			// directory to search in, should be ended with "\"
	PCHAR				Mask,			// search mask
	PLIST_ENTRY			FilesList,		// the list where all FILE_DESCW structures will be linked
	PCRITICAL_SECTION	FilesListLock,	// file list locking object (OPTIONAL)
	ULONG				SearchPathLen,	// the length of the initial search path in chars, used to keep directory structure 
										//  relative to the search path
	ULONG				SearchFlags		// various flags
	)
{
	ULONG	Len, Count = 0;
	PWSTR	PathW = NULL, MaskW = NULL;

	do	// not a loop
	{
		Len = lstrlenA(Path);
		if (!(PathW = AppAlloc((Len + 1) * sizeof(WCHAR))))
			break;
		mbstowcs(PathW, Path, Len + 1);

		Len = lstrlenA(Mask);
		if (!(MaskW = AppAlloc((Len + 1) * sizeof(WCHAR))))
			break;
		mbstowcs(MaskW, Mask, Len + 1);

		Count = FilesScanW(PathW, MaskW, FilesList, FilesListLock, SearchPathLen, SearchFlags);

	} while(FALSE);

	if (MaskW)
		AppFree(MaskW);
	if (PathW)
		AppFree(PathW);

	return(Count);
}
Esempio n. 11
0
static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) 
{
	(void)ud;
	(void)osize;

	if(nsize == 0)
	{
		AppFree(ptr);
		return NULL;
	}
	else
	{
		return AppRealloc(ptr, nsize);
	}
}
Esempio n. 12
0
//
//	Deletes the specified file either immediately or using a special BAT file
//
WINERROR FilesDeleteFile(
	LPTSTR pFilePath
	)
{
	LPTSTR	pPath;
	WINERROR Status = NO_ERROR;

	if (pPath = FilesExpandEnvironmentVariables(pFilePath))
		pFilePath = pPath;

	if (!DeleteFile(pFilePath))
		Status = PsSupDeleteFileWithBat(pFilePath);

	if (pPath)
		AppFree(pPath);

	return(Status);
}
Esempio n. 13
0
File: zor.c Progetto: momtx/meataxe
int main(int argc, const char **argv)

{
    int rc;

    if (Init(argc,argv) != 0)
    {
	MTX_ERROR("Initialization failed");
	return 1;
    }
    if (ifile->Field < 0)
	rc = ordperm();
    else
	rc = ordmat();
    MfClose(ifile);
    AppFree(App);
    return rc;
}
Esempio n. 14
0
WINERROR FilesCreateDirectoryA(
	LPSTR pDirPath
	)
{
	LPWSTR	pPath;
	WINERROR Status = NO_ERROR;

	if (pPath = FilesExpandEnvironmentVariablesAtoW(pDirPath))
	{
		if (!CreateDirectoryW(pPath, NULL))
			Status = GetLastError();

		AppFree(pPath);
	}
	else
		Status = ERROR_NOT_ENOUGH_MEMORY;

	return(Status);
}
Esempio n. 15
0
//
//	Copmpletely clears a specified directory removing all files (and subdirectories if ClearSubfolders flag set).
//
WINERROR FilesClearDirectoryA(
	LPSTR	pDirPath,				// A full path to deirecroty to clear
	BOOL	bClearSubfolders,		// Clear subfolders recursively
	BOOL	bIgnoreErrors			// Ignore file delete errors (aka ERROR_SHARING_VIOLATION and so on)
	)
{
	WINERROR Status;
	LPWSTR	pPath;

	if (pPath = FilesExpandEnvironmentVariablesAtoW(pDirPath))
	{
		Status = FilesClearDirectoryW(pPath, bClearSubfolders, bIgnoreErrors);
		AppFree(pPath);
	}
	else
		Status = ERROR_NOT_ENOUGH_MEMORY;
	
	return(Status);
}
Esempio n. 16
0
/********************************************************************************************
 * FreeChannel
 * purpose : Deallocate a channel from the application's database
 * input   : CurrentChannel - Channel to free
 * output  : none
 * return  : result from CM_ChannelClose
 ********************************************************************************************/
int FreeChannel(ChannelInfo*   CurrentChannel)
{
    CallInfo*       call;
    ChannelInfo*    prev;
    ChannelInfo*    next;
    int             status;

    call = CurrentChannel->call;
    prev = CurrentChannel->prevChannel;
    next = CurrentChannel->nextChannel;

    if(call != NULL)
    {
        if(call->numOfChannels >= 0) call->numOfChannels--;

        /* Fix call's channels list */
        if (call->firstChannel == CurrentChannel)
            call->firstChannel = next;
        if (call->lastChannel == CurrentChannel)
            call->lastChannel = prev;

        /* Fix linkage between neighbor channels */
        if (prev != NULL)
            prev->nextChannel = next;
        if (next != NULL)
            next->prevChannel = prev;
    }

    /* Close the RTP session */
    RTP_TestClose(CurrentChannel->rtpSession);
    pvtDelete(cmGetValTree(hApp), CurrentChannel->dataTypeNode);

    /* Close the channel in the CM */
    if (CurrentChannel->hChan != NULL)
        status = cmChannelClose(CurrentChannel->hChan);
    else
        status = 0;

    AppFree(CurrentChannel);

    return status;
}
Esempio n. 17
0
//
//	Checks the specified path string if it contains an environment variable and if so resolves it's value.
//	Returns new resolved path string or NULL.
//
LPSTR	FilesExpandEnvironmentVariablesA(
	LPSTR	pPath	// target path string to resolve
	)
{
	LPSTR	NewPath = NULL;
	LPWSTR	pPathW;
	ULONG	Len;

	if (pPathW = FilesExpandEnvironmentVariablesAtoW(pPath))
	{
		PathGetShortPath(pPathW);
		Len = lstrlenW(pPathW);
		if (NewPath = AppAlloc(Len + 1))
			wcstombs(NewPath, pPathW, Len + 1);

		AppFree(pPathW);
	}

	return(NewPath);
}
Esempio n. 18
0
void DoSiteFcal(int OutputMode)
{
  Fprec  FcalMaxQ;


  FcalMaxQ = DetFcalMaxQ(0, 0.);

  PrepListSE();
  BuildListFcal(FcalMaxQ);

  if (OutputMode == 0)
    PrintListFcal();
  else
    PrintList_hkl();

  AppFree(ListFcal, nListFcal);
          ListFcal = NULL;
                    nListFcal = 0;
  FreeListSE();
}
Esempio n. 19
0
static PVOID ReallocBuffer(
	PVOID	pBuffer, 
	ULONG	NewSize,
	ULONG	CurrentSize
	)
{
	PVOID pNewBuffer;

	// Tying to reallocate the buffer
	if (!(pNewBuffer = AppRealloc(pBuffer, NewSize)))
	{
		if (pNewBuffer = AppAlloc(NewSize))
		{
			memcpy(pNewBuffer, pBuffer, CurrentSize);
			AppFree(pBuffer);
		}
	}

	return(pNewBuffer);
}
Esempio n. 20
0
//
//	Checks the specified path string if it contains an environment variable and if so resolves it's value.
//	Returns new resolved path string or NULL.
//
LPWSTR	FilesExpandEnvironmentVariablesW(
	LPWSTR	pPath	// target path string to resolve
	)
{
	LPWSTR	NewPath = NULL;
	ULONG	Len;

	if (pPath && (Len = ExpandEnvironmentStringsW(pPath, NULL, 0)))
	{
		if (NewPath = AppAlloc(Len * sizeof(WCHAR)))
		{
			if (!ExpandEnvironmentStringsW(pPath, NewPath, Len))
			{
				AppFree(NewPath);
				NewPath = NULL;
			}	// if (!ExpandEnvironmentStringsW(Path, NewPath, Len))
		}	// if (NewPath = AppAlloc(Len))
	}	// if ((Len = ExpandEnvironmentStringsW(Path, NULL, 0)) && Len > OldLen)

	return(NewPath);
}
Esempio n. 21
0
//
//	Checks the specified path string if it contains an environment variable and if so resolves it's value.
//	Returns new resolved path string or NULL.
//
LPWSTR	FilesExpandEnvironmentVariablesAtoW(
	LPSTR	pPath	// target path string to resolve
	)
{
	LPWSTR	pNewPath = NULL, pPathW;
	ULONG	Length;

	if (pPath)
	{
		Length = lstrlenA(pPath);

		if (pPathW = AppAlloc((Length + 1) * sizeof(WCHAR)))
		{
			mbstowcs(pPathW, pPath, Length + 1);
			if (pNewPath = FilesExpandEnvironmentVariablesW(pPathW))
				AppFree(pPathW);
			else
				pNewPath = pPathW;
		}
	}	// if (Path)

	return(pNewPath);
}
Esempio n. 22
0
//
//	Generates and returns full path to a temporary file.
//
LPTSTR	FilesGetTempFile(
	ULONG Seed		// Seed value used to generate name.
					// We cannot just use GetTickCount() or GetSystemTime() for random name generation because it doesn't
					//  always work correctly and it is possible to receive to equal names by two subsequent calls.
	)
{
	LPTSTR		TempPath = NULL;
	ULONG		TempLen;
	BOOL		Ret = FALSE;

	do	// not a loop
	{		
		if (!(TempLen = GetTempPath(0, NULL)))
			break;

		if (!(TempPath = AppAlloc((TempLen + 14 + 1) * sizeof(_TCHAR))))
			break;

		if (!GetTempPath(TempLen, TempPath))
			break;

		if (!GetTempFileName(TempPath, NULL, (Seed + GetTickCount()), TempPath))
			break;

		Ret = TRUE;

	} while(FALSE);

	if (!Ret && TempPath)
	{
		AppFree(TempPath);
		TempPath = NULL;		
	}

	return(TempPath);
}
Esempio n. 23
0
//
//	Allocates a buffer and loads the specified file into it.
//
WINERROR FilesLoadFileA(
	LPSTR	FileName,	// full path to the file to load
	PCHAR*	pBuffer,	// receives a pointer to the buffer containing the loaded file
	PULONG	pSize		// receives the size of the loaded file in bytes
	)
{
	WINERROR Status = ERROR_UNSUCCESSFULL;
	HANDLE	hFile;
	ULONG	Size, bRead;
	LPWSTR	pPath;
	PCHAR	Buffer = NULL;

	do	// not a loop
	{
		if (!(pPath = FilesExpandEnvironmentVariablesAtoW(FileName)))
			break;

		hFile = CreateFileW(pPath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
		if (hFile == INVALID_HANDLE_VALUE)
			break;
	
		if ((Size = GetFileSize(hFile, NULL)) == 0)
		{
			Status = ERROR_NO_DATA;
			break;
		}

		// Allocating a buffer with one extra char at the end for a NULL-char to be able to work with a text file.
		if (!(Buffer = AppAlloc(Size + sizeof(_TCHAR))))
			break;
			
		if (!ReadFile(hFile, Buffer, Size, &bRead, NULL))
			break;

		if (Size != bRead)
		{
			Status = ERROR_READ_FAULT;
			break;
		}

		Buffer[Size] = 0;

		*pBuffer = Buffer;
		*pSize = Size;
		Status = NO_ERROR;
	} while(FALSE);

	if (Status == ERROR_UNSUCCESSFULL)
		Status = GetLastError();

	if (hFile != INVALID_HANDLE_VALUE)
		CloseHandle(hFile);

	if (Buffer && (Status != NO_ERROR))
		AppFree(Buffer);

	if (pPath)
		AppFree(pPath);

	return(Status);
}
Esempio n. 24
0
//
//	Searches for files according to the specified Mask starting from the specified Path. 
//	For every file found allocates FILE_DESCW structure and links all theese structures into the FileListHead.
//	Returns number of files found.
//	Note: In the ANSI version of FindFirstFile the name is limited to MAX_PATH characters. So we have to use UNICODE version 
//		to completely scan all files.
//
ULONG	FilesScanW(
	PWCHAR				Path,			// directory to search in, should be ended with "\"
	PWCHAR				Mask,			// search mask
	PLIST_ENTRY			FilesList,		// the list where all FILE_DESCW structures will be linked
	PCRITICAL_SECTION	FilesListLock,	// file list locking object (OPTIONAL)
	ULONG				SearchPathLen,	// the length of the initial search path in chars, used to keep directory structure 
										//  relative to the search path
	ULONG				SearchFlags		// various flags
	)
{
	ULONG	Found = 0, PathLen, MaskLen, ScanLen = MAX_PATH;
	LPWIN32_FIND_DATAW	FindData;
	PWCHAR	ScanPath, ResolvedPath = NULL;

	if (FindData = AppAlloc(sizeof(WIN32_FIND_DATAW)))
	{
		if (ResolvedPath = FilesExpandEnvironmentVariablesW(Path))
			Path = ResolvedPath;

		PathLen = wcslen(Path);
		MaskLen = wcslen(Mask);

		if (SearchPathLen == 0)
			SearchPathLen = PathLen;

		while ((PathLen + MaskLen + 2) > ScanLen)		// 1 for "\\" and 1 for "\0"
			ScanLen += MAX_PATH;

		if (ScanPath = AppAlloc(ScanLen * sizeof(WCHAR)))
		{
			HANDLE hFind;
			PFILE_DESCW	fDesc;	

			memset(FindData, 0, sizeof(WIN32_FIND_DATA));
			PathCombineW(ScanPath, Path, Mask);

			// Searching for files within the current directory first
			if ((hFind = FindFirstFileW(ScanPath, FindData)) != INVALID_HANDLE_VALUE)
			{
				do
				{
					if ((FindData->nFileSizeHigh) || (FindData->nFileSizeLow > FILE_SIZE_MAX))
						continue;

					if (FindData->cFileName[0] == '.')
						continue;

					if (fDesc = FileDescAlloc(sizeof(FILE_DESCW) + (PathLen + wcslen(Mask) + wcslen(FindData->cFileName) + 2) * sizeof(WCHAR)))
					{
						LPWSTR	pDir, pPath;

						wcscpy((PWCHAR)&fDesc->Path, Path);
						if (pDir = StrRChrW(Mask, NULL, L'\\'))
						{
							PathCombineW((PWCHAR)&fDesc->Path, Path, Mask);
							*PathFindFileNameW((PWCHAR)&fDesc->Path) = 0;
							pPath = (PWCHAR)&fDesc->Path;
						}
						else
							pPath = Path;

						PathCombineW((PWCHAR)&fDesc->Path, pPath, FindData->cFileName);
		
						fDesc->SearchPathLen = SearchPathLen;
						fDesc->Flags = SearchFlags;

						if (FilesListLock)	EnterCriticalSection(FilesListLock);
						InsertTailList(FilesList, &fDesc->Entry);
						if (FilesListLock)	LeaveCriticalSection(FilesListLock);
					
						Found += 1;
					}
				} while(FindNextFileW(hFind, FindData) && WaitForSingleObject(g_AppShutdownEvent, 0) == WAIT_TIMEOUT);

				FindClose(hFind);
			}	// if ((hFind = FindFirstFileW(ScanPath, FindData)) != INVALID_HANDLE_VALUE)

			// Files are searched, looking for directories to scan them recursively
			PathCombineW(ScanPath, Path, L"*");
	
			if ((hFind = FindFirstFileW(ScanPath, FindData)) != INVALID_HANDLE_VALUE)
			{
				do
				{
					if (FindData->cFileName[0] != '.' && (FindData->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
					{
						MaskLen = wcslen(FindData->cFileName);
						if ((PathLen + MaskLen + 2) > ScanLen)		// 1 for "\\" and 1 for "\0"
						{
							AppFree(ScanPath);
							do {
								ScanLen += MAX_PATH;
							} while ((PathLen + MaskLen + 2) > ScanLen);

							if (!(ScanPath = AppAlloc(ScanLen * sizeof(WCHAR))))
								break;	// not enough memory
						}	// if ((PathLen + MaskLen + 2) > ScanLen)

						PathCombineW(ScanPath, Path, FindData->cFileName);

						Found += FilesScanW(ScanPath, Mask, FilesList, FilesListLock, SearchPathLen, SearchFlags);
					}	// if (FindData->cFileName[0] != '.' &&
				} while(FindNextFileW(hFind, FindData) && WaitForSingleObject(g_AppShutdownEvent, 0) == WAIT_TIMEOUT);

				FindClose(hFind);
			}	// if (hFind = FindFirstFileW(ScanPath, FindData))

			if (ScanPath)
				AppFree(ScanPath);
		}	// if (ScanPath = 

		if (ResolvedPath)
			AppFree(ResolvedPath);

		AppFree(FindData);
	}	// if (FindData)
	return(Found);
}
Esempio n. 25
0
//
//	Copmpletely clears a specified directory removing all files (and subdirectories if ClearSubfolders flag set).
//
WINERROR FilesClearDirectoryW(
	LPWSTR	pPath,					// A full path to deirecroty to clear
	BOOL	bClearSubfolders,		// Clear subfolders recursively
	BOOL	bIgnoreErrors			// Ignore file delete errors (aka ERROR_SHARING_VIOLATION and so on)
	)
{
	WINERROR Status = ERROR_NOT_ENOUGH_MEMORY;
	PWIN32_FIND_DATAW	FindFileData = NULL;
	LPWSTR	pSearchPath = NULL, pFilePath = NULL;
	HANDLE	hFind;
	ULONG	DirPathLen, FilePathLen = MAX_PATH;					// chars

	do	// not a loop, used just to break out on error
	{
		DirPathLen	= (ULONG)lstrlenW(pPath);	// chars

		if (!(pFilePath = AppAlloc(FilePathLen * sizeof(WCHAR))))
		{
			ASSERT(Status == ERROR_NOT_ENOUGH_MEMORY);
			break;
		}

		if (!(pSearchPath = AppAlloc((DirPathLen + cstrlenW(wczFindAll) + 2) * sizeof(WCHAR))))
		{
			ASSERT(Status == ERROR_NOT_ENOUGH_MEMORY);
			break;
		}

		if (!(FindFileData = AppAlloc(sizeof(WIN32_FIND_DATAW))))
		{
			ASSERT(Status == ERROR_NOT_ENOUGH_MEMORY);
			break;
		}

		PathCombineW(pSearchPath, pPath, wczFindAll);

		hFind = FindFirstFileW(pSearchPath, FindFileData);
		if (hFind == INVALID_HANDLE_VALUE)
		{
			Status = ERROR_PATH_NOT_FOUND;
			break;
		}

		Status = NO_ERROR;

		do
		{
			ULONG NameLen;
			ULONG PathLen;

			// Skip "." and ".." names. 
			if (FindFileData->cFileName[0] == '.')
				continue;

			NameLen = lstrlenW(FindFileData->cFileName);
			PathLen = DirPathLen + NameLen + 2; // a char for "\" and one for 0

			if (FilePathLen < PathLen)
			{
				AppFree(pFilePath);
				if (!(pFilePath = AppAlloc(PathLen * sizeof(WCHAR))))
				{
					Status = ERROR_NOT_ENOUGH_MEMORY;
					break;
				}
				FilePathLen = PathLen;
			}

			PathCombineW(pFilePath, pPath, (LPWSTR)FindFileData->cFileName);

			if (FindFileData->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
			{
				if (bClearSubfolders)
				{
					if ((Status = FilesClearDirectoryW(pFilePath, TRUE, bIgnoreErrors)) == NO_ERROR)
					{
						if (!RemoveDirectoryW(pFilePath) && !bIgnoreErrors)
						{
							Status = GetLastError();
							break;
						}
					}
					else
						break;
				}	// if (ClearSubfolders)
			}	// if (FindFileData->dwFileAttributes & 
			else
			{
				if (!DeleteFileW(pFilePath) && !bIgnoreErrors)
				{
					Status = GetLastError();
					break;
				}
			}

		} while(FindNextFileW(hFind, FindFileData));

	} while (FALSE);

	if (FindFileData)
		AppFree(FindFileData);

	if (pSearchPath)
		AppFree(pSearchPath);

	if (pFilePath)
		AppFree(pFilePath);

	return(Status);
}
Esempio n. 26
0
//
//	Creates key store report.
//
WINERROR KeyStoreReport(
	PWCHAR*	ppReport,	// receives key report
	PULONG	pLength,	// size of the report in chars
	BOOL	bDelete
	)
{
	WINERROR Status = ERROR_NOT_ENOUGH_MEMORY;
	PKEY_CONTEXT Ctx, NextCtx;
	ULONG	bLen, TotalLen = 1, Index = 0, Length, InitialSize;
	ULONG   LengthClipbrd = 0;
	PWCHAR	Buffer, NewBuffer;
	SYSTEMTIME	DateTime;
	FILETIME	LocalTime;
	PLIST_ENTRY ListEntry;
#if _DEBUG
	HANDLE	PrevKey = 0;
#endif

	InitialSize = MAX_REPORT_BUFFER_SIZE;

	if (Buffer = AppAlloc(InitialSize))
	{
		bLen = MAX_REPORT_BUFFER_SIZE / sizeof(WCHAR);
		Buffer[0] = 0xfeff;	// Unicode file magic
		Buffer[1] = 0;

		bLen -= 1;

		NextCtx = EnumContext(NULL);

		while(Ctx = NextCtx)
		{
#if _DEBUG
			PHANDLE_RECORD pHRec = CONTAINING_RECORD(Ctx, HANDLE_RECORD, Context);
			ASSERT(pHRec->RefCount == 2);
			ASSERT(PrevKey != pHRec->Key);
			PrevKey = pHRec->Key;
#endif
			if (Ctx->bActive)
			{
				FileTimeToLocalFileTime(&Ctx->Time, &LocalTime);
				FileTimeToSystemTime(&LocalTime, &DateTime);

				// Calculating new message length
				Length = cstrlenW(wczReportFormat) + lstrlenW(Ctx->ProcessPath) + lstrlenW(Ctx->WindowText) + Ctx->Count + 1;

				// Checking if there's enough free space within the buffer to fit the message
				if ((bLen >= Length) ||
					// Trying to reallocate the buffer
					((NewBuffer = ReallocBuffer(Buffer, (InitialSize += max(Length, MAX_KEY_BUFFER_SIZE) * sizeof(WCHAR)), (bLen * sizeof(WCHAR)))) &&
					(Buffer = NewBuffer) && (bLen = (InitialSize / sizeof(WCHAR)) - bLen)))
				{
					Length = wnsprintfW(
						Buffer + TotalLen,
						bLen,
						wczReportFormat,
						DateTime.wDay,
						DateTime.wMonth,
						DateTime.wYear,
						DateTime.wHour,
						DateTime.wMinute,
						DateTime.wSecond,
						(LPWSTR)&Ctx->ProcessPath,
						(LPWSTR)&Ctx->WindowText,
						(LPWSTR)&Ctx->KeyBuffer
						);
					bLen -= Length;
					TotalLen += Length;
				}
			}	// if (Ctx->bActive)

			if (!IsListEmpty(&Ctx->ClipboardChain))
			{
				for ( ListEntry = Ctx->ClipboardChain.Flink;
					ListEntry != &Ctx->ClipboardChain;
					ListEntry = ListEntry->Flink)
				{
					PCLIPBOARD_ENTRY CEntry = CONTAINING_RECORD(ListEntry,CLIPBOARD_ENTRY,qLink);
					Length = cstrlenW(wczFormatClipbrd) + lstrlenA(CEntry->Buffer);

					// Checking if there's enough free space within the buffer to fit the message
					if ((bLen >= Length) ||
						// Trying to reallocate the buffer
						((NewBuffer = ReallocBuffer(Buffer, (InitialSize += max(Length, MAX_KEY_BUFFER_SIZE) * sizeof(WCHAR)), (bLen * sizeof(WCHAR)))) &&
						(Buffer = NewBuffer) && (bLen = (InitialSize / sizeof(WCHAR)) - bLen)))
					{
						FileTimeToLocalFileTime(&CEntry->Time, &LocalTime);
						FileTimeToSystemTime(&LocalTime, &DateTime);

						Length = wnsprintfW(
							Buffer + TotalLen, 
							bLen,
							wczFormatClipbrd,
							DateTime.wDay,
							DateTime.wMonth,
							DateTime.wYear,
							DateTime.wHour,
							DateTime.wMinute,
							DateTime.wSecond,
							(LPWSTR)CEntry->Buffer
							);
						bLen -= Length;
						TotalLen += Length;
					}
				}
			}	// if (!IsListEmpty(&Ctx->ClipboardChain))

			NextCtx = EnumContext(Ctx);

			if (bDelete)
				ReleaseContext(Ctx);
			else
				Index += 1;

			ReleaseContext(Ctx);
		}	// while(Ctx = NextCtx)

		if (TotalLen > 1)
		{
			*ppReport = Buffer;
			*pLength = TotalLen;
			Status = NO_ERROR;
		}
		else
		{
			AppFree(Buffer);
			Status = ERROR_NO_MORE_FILES;
		}
	}	// if (Buffer = AppAlloc(DEFAULT_REPORT_BUFFER_SIZE))

	return(Status);
}
Esempio n. 27
0
void TriaLoop(int MaximumTrials, int nTrialsPerPhaseSet)
{
  T_PhaseCode          *PhaseCode, *FixedCode;
  T_FourierParameters  FP[1];
  T_PeakFlags          *PeakFlags;
  Fprec                *Surface;
  int                  StatLoadNextPhaseSet, iTrialsPerPhaseSet;
  long                 PosLoadNextPhaseSet;

  T_Ticks  Ticks;
  long     CheckTime = -SignalFileCheckInterval;


  nTrials = 0;
  nConvergedPhases = 0;
  nNotConvergedPhases = 0;

  StatLoadNextPhaseSet = 0;
  PosLoadNextPhaseSet = 1;
  iTrialsPerPhaseSet = 0;

  CheckMalloc(PhaseCode, nActivePhase);

  FixedCode = NULL;

  if (F_PhaseSetsFileName)
    CheckMalloc(FixedCode, nActivePhase);

  InitFourierParameters(FP, CodeTransl, nActivePhase);

  CheckMalloc(PeakFlags, Nx * Ny * Nz);
  DS_MarkEquiv(&SpgrInfo, PeakFlags, Nx, Ny, Nz);

  Surface = NULL;

  if (F_SurfaceFileName) {
    CheckMalloc(Surface, Nx * Ny * Nz);
    LoadSurface(Surface, Nx, Ny, Nz, PeakFlags);
  }

  /* initialize random number generator */
  DoRandomInitialization();

     (void) GetTicks(&Ticks);
  PrintTicks(stdout, &Ticks, "# Time ", "  Start of TriaLoop\n");
  Fflush(stdout);

  for (;;)
  {
    if (F_SignalFileName)
    {
      if (Ticks.sec_since_some_day - CheckTime >= SignalFileCheckInterval)
      {
        CheckSignalFile();
        CheckTime = Ticks.sec_since_some_day;
      }
    }

    if (QuitProgram)
      break;

    if (   FixedCode
        && (   StatLoadNextPhaseSet == 0
            || iTrialsPerPhaseSet >= nTrialsPerPhaseSet))
    {
      PosLoadNextPhaseSet = LoadNextPhaseSet(NULL) + 1;

      Fprintf(stdout,
        "# Looking for next phase set, starting at line #%ld in file %s\n",
        PosLoadNextPhaseSet, F_PhaseSetsFileName);

          StatLoadNextPhaseSet = LoadNextPhaseSet(FixedCode);
      if (StatLoadNextPhaseSet == -1)
        break;

      iTrialsPerPhaseSet = 0;
    }

    Fprintf(stdout, "WoT %d", nTrials);
    if (FixedCode)
      Fprintf(stdout, " PosPhaseSet %ld Fixed %ld Random %d Trial %d",
        PosLoadNextPhaseSet,
        (long) nActivePhase - StatLoadNextPhaseSet,
        StatLoadNextPhaseSet,
        iTrialsPerPhaseSet);
    putc('\n', stdout);
    Fflush(stdout);

    CurrPhaseCode_nCallRanmar = NextPhaseCode(PhaseCode, FixedCode);
    RecyclePhases(FP, PeakFlags, Surface, PhaseCode);

    nTrials++;
    if (FixedCode) iTrialsPerPhaseSet++;

       (void) GetTicks(&Ticks);
    PrintTicks(stdout, &Ticks, "# Time ", "\n");
    Fflush(stdout);

    if (MaximumTrials && MaximumTrials <= nTrials)
      break;
  }

  if (Surface) AppFree(Surface, Nx * Ny * Nz);
  AppFree(PeakFlags, Nx * Ny * Nz);
  FreeFourierParameters(FP);

  PrintTicks(stdout, NULL, "# Time ", "  End of TriaLoop\n");
}
Esempio n. 28
0
static int Try_GS_si(T_SgInfo *SgInfo)
{
  int       h, k, l, iList;
  int       Maxh, Maxk, Maxl;
  int       Minh, Mink, Minl;
  int       nTestField, *TestField;
  int       nProperty, *Property, *pp;
  int       IsFine, would_be, is;


  SgInfo->n_si_Vector = -1;

                       nTestField = 12 * 12 * 12;
  AppMalloc(TestField, nTestField);
  if (TestField == NULL) {
    SetSgError("Not enough core");
    return -1;
  }

  MarkLegalOrigins(SgInfo, TestField);

  Maxh = Maxk = Maxl = 7;
  SetListMin_hkl(SgInfo, Maxk, Maxl, &Minh, &Mink, &Minl);

  nProperty =   (Maxh - Minh + 1)
              * (Maxk - Mink + 1)
              * (Maxl - Minl + 1);

  AppMalloc(Property, nProperty);
  if (Property == NULL) {
    SetSgError("Not enough core");
    AppFree(TestField, nTestField);
    return -1;
  }

  pp = Property;
  for (h = Minh; h <= Maxh; h++)
  for (k = Mink; k <= Maxk; k++)
  for (l = Minl; l <= Maxl; l++)
  {
    iList = IsSysAbsent_hkl(SgInfo, h, k, l, NULL);
    if (SgError != NULL)
    {
      AppFree(Property, nProperty);
      AppFree(TestField, nTestField);
      return -1;
    }

    if (iList == 0)
      *pp++ = Verify_si(h, k, l, TestField);
    else
      *pp++ = -1;
  }

  if (Find_si(SgInfo) >= 0)
  {
    IsFine = 1;

    pp = Property;
    for (h = Minh; IsFine && h <= Maxh; h++)
    for (k = Mink; IsFine && k <= Maxk; k++)
    for (l = Minl; IsFine && l <= Maxl; l++)
    {
      is = *pp++;

      if (is >= 0)
      {
        would_be = Is_si(SgInfo, h, k, l);
        if (is != would_be)
          IsFine = 0;
      }
    }

    if (IsFine)
    {
      AppFree(Property, nProperty);
      AppFree(TestField, nTestField);
      return 0;
    }
  }

  SetSgError("Internal Error: Can't determine s.i. vectors and moduli");

  AppFree(Property, nProperty);
  AppFree(TestField, nTestField);

  return -1;
}
Esempio n. 29
0
File: zsp.c Progetto: momtx/meataxe
static void Cleanup()

{
    AppFree(App);
}
Esempio n. 30
0
File: zcv.c Progetto: momtx/meataxe
static void Cleanup()
{
   fclose(out);
   if (App != NULL) { AppFree(App); }
}