Ejemplo n.º 1
0
bool ZipPlatform::ForceDirectory(LPCTSTR lpDirectory)
{
    ASSERT(lpDirectory);
    CZipString szDirectory = lpDirectory;
    szDirectory.TrimRight(CZipPathComponent::m_cSeparator);
    CZipPathComponent zpc(szDirectory);
    if ((zpc.GetFilePath() == (LPCTSTR)szDirectory) ||
            (FileExists(szDirectory) == -1))
        return true;
    if (!ForceDirectory(zpc.GetFilePath()))
        return false;
    if (!CreateDirectory(szDirectory))
        return false;
    return true;
}
Ejemplo n.º 2
0
void FillFromFile(FILELIST& l, LPCTSTR lpszFile, bool bCheck)
{
	FILE* f;
#if _MSC_VER >= 1400
	if (fopen_s(&f, lpszFile, "rt") != 0)
		f = NULL;
#else
	f = fopen(lpszFile, "rt");
#endif
	
	if (!f)
	{
		printf ("File %s could not be opened\n", lpszFile);
		return;
	}
	fseek(f, 0, SEEK_END);
	int iSize = ftell(f);
	fseek(f, 0, SEEK_SET);
	CZipAutoBuffer buf(iSize + 1);
	iSize = fread(buf, 1, iSize, f);
	fclose(f);
	char* sEnd = buf + iSize;
	char* sBeg = buf;
	for (char* pos = buf; ; pos++)
	{
		bool bEnd = pos == sEnd; // there may be no newline at the end
		if (strncmp(pos, "\n", 1) == 0 || bEnd)
		{
			*pos = '\0';
			CZipString s = sBeg;
			s.TrimLeft(" ");
			s.TrimRight(" ");
			if (!s.IsEmpty() && (!bCheck || ZipPlatform::FileExists(s) != 0))
				l.push_back(s);
			if (bEnd)
				break;
			sBeg = pos + 1;			
		}
	}
}