Пример #1
0
PWSTR NewStr(PWSTR str)
{
	PWSTR newStr = (PWSTR)NewMem(((str ? wcslen(str) : 0) + 1) * sizeof(WCHAR));

	if(str)
		wcscpy(newStr, str);

	return newStr;
}
Пример #2
0
void *DeprecatedSysMemAlloc(Int s)
{
	Int size = s + sizeof(Int);
	void *mem = (size > 0) ? NewMem(UChar, size) : nullptr;			// NC is equivalent to HeapAlloc( , 0, )
	if (!mem)
		return nullptr;
	*((Int*)mem)=s;													// ###REMOVE: there's no need to store the size anymore, call GeGetAllocSize()
	return (UChar*)mem+sizeof(Int);
}
Пример #3
0
PSTR NewStr(PSTR str)
{
	PSTR newStr = NewMem((str ? lstrlen(str) : 0) + 1);

	if(str)
		lstrcpy(newStr, str);

	return newStr;
}
Пример #4
0
PSTR NewStrAsAnsi(PWSTR str)
{
	int newStrSize = ((str ? wcslen(str) : 0) + 1) * sizeof(WCHAR);
	PSTR newStr = NewMem(newStrSize);

	if(str)
		wcstombs(newStr, str, newStrSize);

	return newStr;
}
Пример #5
0
PWSTR NewStrAsWide(PSTR str)
{
	int newStrSize = ((str ? lstrlen(str) : 0) + 1) * sizeof(WCHAR);
	PWSTR newStr = (PWSTR)NewMem(newStrSize);

	if(str)
		MultiByteToWideChar(CP_ACP, 0, str, -1, newStr, newStrSize);

	return newStr;
}
Пример #6
0
void UpdateCRC(Crc32 &crc, const String &str)
{
	Int32 lLen = str.GetCStringLen();
	Char* pchString = NewMem(Char,lLen + 2);
	if (!pchString)
		return;
	str.GetCString(pchString, lLen + 1);
	crc.Update(pchString, lLen);
	DeleteMem(pchString);
}
Пример #7
0
PSTR W2S(PWSTR wStr, int strLen)
{
  if(!wStr)
    return NULL;

  PSTR str = NULL;
  int len = strLen == -1 ? wcslen(wStr) + 1 : strLen;

  WCTMB(wStr, str = (PSTR)NewMem(len), len);

  return str;
}
Пример #8
0
PWSTR S2W(PSTR str, int strLen)
{
  if(!str)
    return NULL;

  PWSTR wStr = NULL;
  int len = strLen == -1 ? strlen(str) + 1 : strLen;

  MBTWC(str, wStr = (PWSTR)NewMem(sizeof(WCHAR) * len), len);

  return wStr;
}
Пример #9
0
PWSTR NewZeroStr(PWSTR str)
{
	for(DWORD size = 0; (str + size) && *(str + size); )
		size += wcslen(str + size) + 1;

	PWSTR newStr = (PWSTR)NewMem(++size * sizeof(WCHAR));

	if(str)
		CopyMemory(newStr, str, size * sizeof(WCHAR));

	return newStr;
}
Пример #10
0
PSTR NewZeroStr(PSTR str)
{
	for(DWORD size = 0; (str + size) && *(str + size); )
		size += lstrlen(str + size) + 1;

	PSTR newStr = NewMem(++size);

	if(str)
		CopyMemory(newStr, str, size);

	return newStr;
}
Пример #11
0
Bool CDynamicSortLongSet::WriteElements(HyperFile* pFile, const Int32* pElements, Int32 lCount) const
{
#if (defined __MAC && __BIG_ENDIAN__)
	if (lCount == 0)
		return false;
	void* pData = NewMem(Int32, lCount);
	if (!pData)
		return false;
	CopyMem(pElements, pData, lCount * sizeof(Int32));
	lIntel(pData, lCount);
	if (!pFile->WriteMemory(pData, sizeof(Int32) * lCount))
		return false;
#else
	if (!pFile->WriteMemory(pElements, sizeof(Int32) * lCount))
		return false;
#endif
	return true;
}
Пример #12
0
void MemStatDialog::CheckMaxMemory(Int32 mbblocks)
{
	maxon::BaseArray<void*> blocks;
	Int32 i;

	for (i = 0; true; i++)
	{
		void* block = nullptr;
		if (mbblocks > 0)
			block = NewMem(UChar, mbblocks * 1024 * 1024);
		if (!block)
			break;
		InitValues();
		if (!blocks.Append(block))
		{
			DeleteMem(block);
			break;
		}
		InitValues();
	}

	BaseContainer stat;
	GeGetMemoryStat(stat);

	for (i = 0; i < blocks.GetCount(); i++)
	{
		void* block = blocks[i];
		if (block)
			DeleteMem(block);
	}

	InitValues();

	String memstr = String::MemoryToString(stat.GetInt64(C4D_MEMORY_STAT_MEMORY_INUSE));

	switch (mbblocks)
	{
		case 1:			SetString(IDC_MEMORY_TEST_1MB_RES, memstr); break;
		case 10:		SetString(IDC_MEMORY_TEST_10MB_RES, memstr); break;
		case 100:		SetString(IDC_MEMORY_TEST_100MB_RES, memstr); break;
	}

	GeOutString("Max memory allocation: " + memstr, GEMB_OK);
}
Пример #13
0
Bool PaintUndoTile::Init(PaintLayerBmp *pBitmap, Int x, Int y)
{
	m_pDestBitmap->SetLink(pBitmap);
	if (!pBitmap)
	{
		return false;
	}

	m_xTile = (int)(x * PAINTTILEINV);
	m_yTile = (int)(y * PAINTTILEINV);

	m_x = m_xTile * PAINTTILESIZE;
	m_y = m_yTile * PAINTTILESIZE;

	int bitdepth, numChannels;
	if (!GetChannelInfo(pBitmap, bitdepth, numChannels))
		return false;

	if (m_pData)
	{
		DeleteMem(m_pData);
		m_dataSize = 0;
	}

	COLORMODE colorMode = (COLORMODE)pBitmap->GetColorMode();
	Int32 bitsPerPixel = (bitdepth / 8) * numChannels;
	m_dataSize = PAINTTILESIZE * PAINTTILESIZE * bitsPerPixel;
	m_pData = NewMem(UChar, m_dataSize);

	if (!m_pData)
		return false;

	//Copy the data across;
	UChar *pos = m_pData;
	for (Int32 yy = 0; yy < PAINTTILESIZE; yy++)
	{
		pBitmap->GetPixelCnt((Int32)m_x, (Int32)m_y + yy, (Int32)PAINTTILESIZE, &pos[yy*PAINTTILESIZE*bitsPerPixel], colorMode, PIXELCNT_0);
	}

	return true;
}
Пример #14
0
void StringReplace::Replace(String &str)
{
	// test for environment variables
	Int32 lStart, lEnd, lStartSearch = 0;
	Int32 lStringLen;
	String strExpr;
	char* pchEnvVar;
	char pszVar[1000];
	BaseContainer bc;

	while (str.FindFirst("($", &lStart, lStartSearch))
	{
		if (!str.FindFirst("$)", &lEnd, lStart))
			return;
		lStartSearch = lStart + 1;

		strExpr = str.SubStr(lStart + 2, lEnd - lStart - 2);
		lStringLen = strExpr.GetCStringLen(STRINGENCODING_8BIT);
		Char* pchString = NewMem(Char,lStringLen + 2);
		if (!pchString)
			return;
		strExpr.GetCString(pchString, lStringLen + 1, STRINGENCODING_8BIT);
		pchEnvVar = GetOSEnvironmentVariable(pchString, pszVar, 1000);
		DeleteMem(pchString);
		if (pchEnvVar)
			str = str.SubStr(0, lStart) + String(pchEnvVar) + str.SubStr(lEnd + 2, str.GetLength() - lEnd - 2);
	}

	FindAndReplace(str, String("($CINEMA_4D_ROOT$)"), m_strStartupPath);
	FindAndReplace(str, String("($CINEMA_4D_PLUGIN$)"), m_strPluginPath);
	FindAndReplace(str, String("($CINEMA_4D_VERSION$)"), m_strCurrentVersion);
	FindAndReplace(str, String("($CURRENT_DATE$)"), m_strDate);
	FindAndReplace(str, String("($CURRENT_TIME$)"), m_strTime);
	FindAndReplace(str, String("($CURRENT_DATE_TIME$)"), m_strDateTime);
	FindAndReplace(str, String("($BUILD_VERSION$)"), m_strBuildVersion);
	FindAndReplace(str, String("($RELEASE_LINE$)"), m_strReleaseLine);
	FindAndReplace(str, String("($BUILD_ID$)"), m_strBuildID);
}
Пример #15
0
Bool DiffZipFiles(const CDynamicFilenameSet &arFiles, const Filename &fnNew, const Filename &fnDestZip, const char* pchPassword)
{
	AutoAlloc <ZipFile> pOldZip, pNewZip, pDiffZip;
	ZipArray arStrings;
	ZipFileInfo info;
	String strName;
	Bool bExisted;
	Bool bOK = false;
	Int32 l, lCount;
	ZipArrayEntry* pEntry;
	void* pchData = nullptr;
	UInt32 lMaxDataLen = 0;
	ZipWriteInfo writeinfo;
	Bool bAppFolderChanged = false;

	if (!pOldZip || !pNewZip || !pDiffZip)
		return false;

	if (!pNewZip->Open(fnNew, true) || !pDiffZip->Open(fnDestZip, false))
		return false;

	// first, add all files of the new zip file into our array
	if (pNewZip->GoToFirstFile())
	{
		do
		{
			if (!pNewZip->GetCurrentFileInfo(info) ||
					!pNewZip->GetCurrentFileInfo(&strName))
				GOTO_ERROR;

			ZipArrayEntry* pEntry = arStrings.SearchObject(&strName);
			if (!pEntry)
			{
				pEntry = NewObjClear(ZipArrayEntry);
				if (!pEntry)
					GOTO_ERROR;
				pEntry->strName = strName;
				pEntry->bInNew = true;
				pEntry->bInOld = false;
				pEntry->ulCRCNew = info.lCRC32;
				pEntry->lNewSize = info.lUncompressedSize;
				pEntry->bChanged = false;
				pEntry->bInAppFolder = strName.FindFirst(".app/", nullptr);
				arStrings.InsertObject(pEntry, bExisted);
				DebugAssert(!bExisted);
			}
			else
			{
				// exists twice?!
				DebugAssert(false);
			}
		} while (pNewZip->GoToNextFile());
	}

	// browse through the array and check if something has changed
	for (l = 0; l < arFiles.GetElementCount(); l++)
	{
		if (!pOldZip->Open(*arFiles[l], true))
			GOTO_ERROR;
		if (pOldZip->GoToFirstFile())
		{
			do
			{
				if (!pOldZip->GetCurrentFileInfo(info) ||
						!pOldZip->GetCurrentFileInfo(&strName))
					GOTO_ERROR;

				ZipArrayEntry* pEntry = arStrings.SearchObject(&strName);
				if (!pEntry)
				{
					// file has been deleted
					pEntry = NewObjClear(ZipArrayEntry);
					if (!pEntry)
						GOTO_ERROR;
						pEntry->strName = strName;
					pEntry->bInNew = false;
					pEntry->bInOld = true;
					arStrings.InsertObject(pEntry, bExisted);
					DebugAssert(!bExisted);
				}
				else
				{
					// check for size and CRC
					pEntry->bInOld++;
					if ((pEntry->lNewSize != info.lUncompressedSize || pEntry->ulCRCNew != info.lCRC32) && pEntry->bInNew)
					{
						pEntry->bChanged = true;
						if (pEntry->bInAppFolder)
							bAppFolderChanged = true;
					}
				}
			} while (pOldZip->GoToNextFile());
		}
		pOldZip->Close();
	}

	lCount = arFiles.GetElementCount();
	for (l = 0; l < arStrings.GetElementCount(); l++)
	{
		if (arStrings[l]->bInNew)
			// we want to add it - mark as old if it exists in all old archives
			arStrings[l]->bInOld = (arStrings[l]->bInOld == lCount);
		else
			// old if it exists in at least one archive
			arStrings[l]->bInOld = (arStrings[l]->bInOld > 0);
	}

	lCount = arStrings.GetElementCount();
	if (!bAppFolderChanged)
	{
		// check if a new file as been added
		for (l = 0; l < lCount; l++)
		{
			pEntry = arStrings.GetObjectAt(l);
			if (!pEntry)
			{
				DebugAssert(false);
				continue;
			}
			if (pEntry->bInAppFolder && pEntry->bInNew && !pEntry->bInOld)
			{
				bAppFolderChanged = true;
				break;
			}
		}
	}

	for (l = 0; l < lCount; l++)
	{
		pEntry = arStrings.GetObjectAt(l);
		if (!pEntry)
		{
			DebugAssert(false);
			continue;
		}
		if (pEntry->bChanged || (pEntry->bInNew && !pEntry->bInOld) || (bAppFolderChanged && pEntry->bInAppFolder))
		{
			// the file has changed or was added, copy it from the new distri to the diff
			if (!pNewZip->LocateFile(pEntry->strName))
				GOTO_ERROR;
			if (!pNewZip->GetCurrentFileInfo(info))
				GOTO_ERROR;
			if (!pchData || lMaxDataLen < pEntry->lNewSize)
			{
				DeleteMem(pchData);
				pchData = NewMem(UChar, pEntry->lNewSize + 1);
				if (!pchData)
					GOTO_ERROR;
				lMaxDataLen = pEntry->lNewSize;
			}

			if (!pNewZip->OpenCurrentFile(pchPassword))
				GOTO_ERROR;

			if (pNewZip->ReadCurrentFile(pchData, pEntry->lNewSize) != pEntry->lNewSize)
				GOTO_ERROR;

			pNewZip->CloseCurrentFile();

			writeinfo.ti = info.t;
			if (pEntry->strName[pEntry->strName.GetLength() - 1] == '/')
			{
				writeinfo.lExternalAttr = ZIP_FLAG_DIRECTORY;
				writeinfo.lInternalAttr = 0;
				if (!pDiffZip->CreateFileInZip(pEntry->strName, &writeinfo, nullptr, 0, nullptr, 0, nullptr, ZipMethodStore, 0, pchPassword, 0))
					GOTO_ERROR;
				if (!pDiffZip->CloseFileInZip())
					GOTO_ERROR;
			}
			else
			{
				writeinfo.lExternalAttr = info.lExternalAttr;
				writeinfo.lInternalAttr = info.lInternalAttr;
				if (!pDiffZip->CreateFileInZip(pEntry->strName, &writeinfo, nullptr, 0, nullptr, 0, nullptr, ZipMethodDeflate, 9, nullptr, 0))
					GOTO_ERROR;
				if (!pDiffZip->WriteInFileInZip(pchData, pEntry->lNewSize))
					GOTO_ERROR;
				if (!pDiffZip->CloseFileInZip())
					GOTO_ERROR;
			}
		}
		else if (!pEntry->bInNew && pEntry->bInOld)
		{
			if (pEntry->strName[pEntry->strName.GetLength() - 1] == '/')
			{
				writeinfo.lExternalAttr = ZIP_FLAG_DIRECTORY;
				writeinfo.lInternalAttr = 0;
				if (!pDiffZip->CreateFileInZip("----" + pEntry->strName, &writeinfo, nullptr, 0, nullptr, 0, nullptr, ZipMethodStore, 0, pchPassword, 0))
					GOTO_ERROR;
				if (!pDiffZip->CloseFileInZip())
					GOTO_ERROR;
			}
			else
			{
				writeinfo.lExternalAttr = 0;
				writeinfo.lInternalAttr = 0;
				if (!pDiffZip->CreateFileInZip("----" + pEntry->strName, &writeinfo, nullptr, 0, nullptr, 0, nullptr, ZipMethodStore, 9, nullptr, 0))
					GOTO_ERROR;
				if (!pDiffZip->CloseFileInZip())
					GOTO_ERROR;
			}
		}
	}

	bOK = true;
error:
	pOldZip->Close();
	pNewZip->Close();
	pDiffZip->Close();

	arStrings.Free();
	DeleteMem(pchData);
	return bOK;
}
Пример #16
0
void RunCommand(const char *command, const char *dir, bool hide, bool synch)
{
#ifdef WIN32
	int fmHigh = 0;
	int fmWide = 0;
	int fmLeft = 0;
	int fmTop = 0;

	ExitType = 3;

	startInfo = (LPSTARTUPINFO) NewMem(sizeof(STARTUPINFO));
	if (startInfo == NULL)
		return;

	startInfo->cb = sizeof(STARTUPINFO);
	startInfo->dwFlags = STARTF_USESHOWWINDOW;
	startInfo->wShowWindow = hide ? SW_HIDE : SW_SHOWNORMAL;

#if 0
	if (sized) {
		fmHigh = F_ApiGetInt(0, FV_SessionId, FP_ScreenHeight);
		fmWide = F_ApiGetInt(0, FV_SessionId, FP_ScreenWidth);
		fmLeft = F_ApiGetInt(0, FV_SessionId, FP_ScreenX);
		fmTop = F_ApiGetInt(0, FV_SessionId, FP_ScreenY);

		startInfo->dwXSize = (fmWide < 540) ? fmWide : 540;
		startInfo->dwYSize = (fmHigh < 400) ? fmHigh : 400;
		startInfo->dwX = (fmLeft > 100) ? fmLeft - 100 : fmLeft + 100;
		startInfo->dwY = (fmTop < 80) ? fmTop + 80 : fmTop - 80;
		startInfo->dwFlags |= (STARTF_USESIZE | STARTF_USEPOSITION);
	}
#endif

	procInfo = (PROCESS_INFORMATION *) NewMem(sizeof(PROCESS_INFORMATION));
	if (procInfo == NULL) {
		DeleteMem(startInfo);
		return;
	}

	ExitType = 0;

	if (!dir) {
		PathBuf[0] = '\0';
		dir = _getcwd(PathBuf, MAXPATH);
	}

	StopCommand = false;

	if (CreateProcess(NULL, (char *) command, NULL, NULL, TRUE, 0,
										NULL, dir, startInfo, procInfo)) {
		CurrProc = procInfo->hProcess;
		if (synch)
			WaitForCurrProcess();
		//WaitForSingleObject(procInfo->hProcess, INFINITE);
	}
	else {
		ExitType = 1;
		LocalExitCode = GetLastError();
		DeleteMem(startInfo);
		DeleteMem(procInfo);
	}

#else

	/* for Mac and UNIX */
	ExitType = 0;
	if ((ExitCode = system(command)) != 0)
		ExitType = 4;

#endif
}