CString CLogActions::GetLogFileName(const char* szLogName)
{
	CString sLogPath=getFileFullName(objSettings.sMessageLogDirectory,TRUE);
	if(!objSettings.SaveMesNotesByDefForUser || strcmp(szLogName,DEFAULT_GENERALLOG)==0){
		// Если нужен общий лог или поюзерного лога нет совсем...
		return sLogPath+DEFAULT_GENERALLOG;
	}
	// Удаляем неверные символы
	CString sGoodLogName=szLogName;
	MakeSafeFileName(sGoodLogName);
	return sLogPath+sGoodLogName+DEFAULT_PERSONLOG;
}
// give the best string we can in the given amount of chars
CString CPathDescriptor::getDisplayPath(int nMaxChars)
{
	int nFullLen = GetLength();
	int nNameLen = getFileFullName().GetLength();
	CString s;

	if(nFullLen <= nMaxChars)
		return getFullPath();

	if(nNameLen>= nMaxChars)	// big file name
	{
		//favor the beginning of the file name
		// this commented out version adds the ellipses at the end to.  the other
		// version, which is better until I get dynamic re-figuring based on
		// column resizing, lets the list ctrl do the ellipsing on the right edge
		//s.Format( "...%s...", getFileFullName().Left(nMaxChars-6));
		s.Format( "...%s", getFileFullName().Left(nMaxChars-3));
		return s;
	}

	int nDir = (nMaxChars-nNameLen) - 3; // 3 for ellipses
	s.Format("...%s%s", m_sDirectory.Right(nDir), getFileFullName());
	return s;
}
Beispiel #3
0
bool UpdateManager::uncompressFile(int index)
{
	VersionInfo vi=downloadInfo[index];
	CCLog("start to uncompressed name %s",vi.getName());
	string outFileName=getFileFullName(vi.getPath());
	if(getFileExtention(vi.getPath())==string("apk"))
	{
		haveApk=true;
		return true;
	}

	// Open the zip file
	unzFile zipfile = unzOpen(outFileName.c_str());
	if (! zipfile)
	{
		CCLog("can not open downloaded zip file %s", outFileName.c_str());
		return false;
	}

	// Get info about the zip file
	unz_global_info global_info;
	if (unzGetGlobalInfo(zipfile, &global_info) != UNZ_OK)
	{
		CCLog("can not read file global info of %s", outFileName.c_str());
		unzClose(zipfile);
		return false;
	}

	// Buffer to hold data read from the zip file
	char readBuffer[BUFFER_SIZE];

	CCLog("start uncompressing");

	// Loop to extract all files.
	uLong i;
	for (i = 0; i < global_info.number_entry; ++i)
	{
		// Get info about current file.
		unz_file_info fileInfo;
		char fileName[MAX_FILENAME];
		if (unzGetCurrentFileInfo(zipfile,
			&fileInfo,
			fileName,
			MAX_FILENAME,
			NULL,
			0,
			NULL,
			0) != UNZ_OK)
		{
			CCLog("can not read file info");
			unzClose(zipfile);
			return false;
		}

		string fullPath = resourcesPath +"/"+ fileName;
		CCLog("uncompressed dir is %s",fullPath.c_str());

		// Check if this entry is a directory or a file.
		const size_t filenameLength = strlen(fileName);
		if (fileName[filenameLength-1] == '/')
		{
			// Entry is a direcotry, so create it.
			// If the directory exists, it will failed scilently.
			if (!createDirectory(fullPath.c_str()))
			{
				CCLog("can not create directory %s", fullPath.c_str());
				unzClose(zipfile);
				return false;
			}
		}
		else
		{
			// Entry is a file, so extract it.

			// Open current file.
			if (unzOpenCurrentFile(zipfile) != UNZ_OK)
			{
				CCLog("can not open file %s", fileName);
				unzClose(zipfile);
				return false;
			}

			// Create a file to store current file.
			FILE *out = fopen(fullPath.c_str(), "wb");
			if (! out)
			{
				CCLog("can not open destination file %s", fullPath.c_str());
				unzCloseCurrentFile(zipfile);
				unzClose(zipfile);
				return false;
			}

			// Write current file content to destinate file.
			int error = UNZ_OK;
			do
			{
				error = unzReadCurrentFile(zipfile, readBuffer, BUFFER_SIZE);
				if (error < 0)
				{
					CCLog("can not read zip file %s, error code is %d", fileName, error);
					unzCloseCurrentFile(zipfile);
					unzClose(zipfile);
					return false;
				}

				if (error > 0)
				{
					fwrite(readBuffer, error, 1, out);
				}
			} while(error > 0);

			fclose(out);
		}

		unzCloseCurrentFile(zipfile);

		// Goto next entry listed in the zip file.
		if ((i+1) < global_info.number_entry)
		{
			if (unzGoToNextFile(zipfile) != UNZ_OK)
			{
				CCLog("can not read next file");
				unzClose(zipfile);
				return false;
			}
		}
	}

	CCLog("end uncompressing");

	return true;
}