Esempio n. 1
0
static int OnMakeDirectoryClick(HWND hDlg)
{
    OBJECT_ATTRIBUTES ObjAttr;
    IO_STATUS_BLOCK IoStatus = {0, 0};
    UNICODE_STRING FileName;
    TFileTestData * pData = GetDialogData(hDlg);
    NTSTATUS Status = STATUS_SUCCESS;
    LPTSTR szDirectory = pData->szDirName;
    LPTSTR szPathPart = pData->szDirName;
    LPTSTR szTemp;
    USHORT SaveLength;

    // Get the values from dialog controls to the dialog data
    if(SaveDialog(hDlg) != ERROR_SUCCESS)
        return FALSE;

    // Initialize object attributes and the unicode string
    InitializeObjectAttributes(&ObjAttr, &FileName, OBJ_CASE_INSENSITIVE, NULL, NULL);
    RtlInitUnicodeString(&FileName, pData->szDirName);
    SaveLength = FileName.Length;

    // Now parse the directory as-is, create every sub-directory
    if(szDirectory[0] != 0)
    {
        // Now find the begin of the first directory part
        szPathPart = FindDirectoryPathPart(szDirectory);
        if(szPathPart != NULL)
        {
            while(szPathPart[0] != 0)
            {
                // Find either next backslash or end of string
                szTemp = FindNextPathSeparator(szPathPart);
                
                // Create the directory part
                FileName.Length = (USHORT)((szTemp - szDirectory) * sizeof(WCHAR));
                Status = MyCreateDirectory(pData, &ObjAttr, &IoStatus);
                if(!NT_SUCCESS(Status))
                    break;

                // Go to the next part of the path
                FileName.Length = SaveLength;
                szPathPart = szTemp;
            }
        }
        else
        {
            Status = MyCreateDirectory(pData, &ObjAttr, &IoStatus);
        }
    }
    else
    {
        Status = MyCreateDirectory(pData, &ObjAttr, &IoStatus);
    }

    SetResultInfo(hDlg, Status, NULL, IoStatus.Information);
    return TRUE;
}
Esempio n. 2
0
static int OnMakeDirectoryClick(HWND hDlg)
{
    TFileTestData * pData = GetDialogData(hDlg);
    LPTSTR szDirectory = pData->szDirName;
    LPTSTR szPathPart = pData->szDirName;
    LPTSTR szTemp;
    TCHAR chSaveChar;
    int nError = ERROR_SUCCESS;

    // Get the values from dialog controls to the dialog data
    if(SaveDialog(hDlg) != ERROR_SUCCESS)
        return FALSE;

    // Now parse the directory as-is, create every sub-directory
    if(szDirectory[0] != 0)
    {
        // Now find the begin of the first directory part
        szPathPart = FindDirectoryPathPart(szDirectory);
        if(szPathPart != NULL)
        {
            while(szPathPart[0] != 0)
            {
                // Find either next backslash or end of string
                szTemp = FindNextPathSeparator(szPathPart);
                
                // Create the directory part
                chSaveChar = szTemp[0];
                szTemp[0] = 0;
                nError = MyCreateDirectory(pData, szDirectory);
                if(nError != ERROR_SUCCESS)
                    break;

                // Go to the next part of the path
                szPathPart = szTemp;
                szTemp[0] = chSaveChar;
            }
        }
        else
        {
            nError = MyCreateDirectory(pData, szDirectory);
        }
    }
    else
    {
        nError = MyCreateDirectory(pData, szDirectory);
    }

    SetResultInfo(hDlg, nError, pData->hFile);
    return TRUE;
}
Esempio n. 3
0
// =====================================================================================================================
// =======================================================================================================================
CDateFileLogWriter::CDateFileLogWriter()
{
	//~~~~~~~~~
	time_t ltime;
	//~~~~~~~~~

	time(&ltime);

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	struct tm *newtime = localtime(&ltime);
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

	char path[256] = {0};
	snprintf(path, sizeof(path), "%s/%s", GetDocumentPath(), "debug");

	MyCreateDirectory(path);

	//~~~~~~~~~~~~~~~~~~~~~
	char szLogName[256] = "";
	//~~~~~~~~~~~~~~~~~~~~~

	snprintf(szLogName, sizeof(szLogName) - 1, "%s/%u_%u_%u.log", path, newtime->tm_year + 1900, newtime->tm_mon + 1,
			  newtime->tm_mday);
	szLogName[sizeof(szLogName) - 1] = 0;
	m_strFileName = szLogName;
	m_fp = fopen(m_strFileName.c_str(), "a+");
}
Esempio n. 4
0
BOOL SetDownSavePath(const char * lpSavePath)
{
    strncpy(g_downSavingPath, lpSavePath, sizeof(g_downSavingPath) - 1);
    if (access(g_downSavingPath, 0) != 0) {
        MyCreateDirectory(g_downSavingPath);
    }
    return 1;
}
Esempio n. 5
0
static bool CreateTempFile(CFSTR prefix, bool addRandom, FString &path, NIO::COutFile *outFile)
{
  UInt32 d = (GetTickCount() << 12) ^ (GetCurrentThreadId() << 14) ^ GetCurrentProcessId();
  for (unsigned i = 0; i < 100; i++)
  {
    path = prefix;
    if (addRandom)
    {
      FChar s[16];
      UInt32 value = d;
      unsigned k;
      for (k = 0; k < 8; k++)
      {
        unsigned t = value & 0xF;
        value >>= 4;
        s[k] = (char)((t < 10) ? ('0' + t) : ('A' + (t - 10)));
      }
      s[k] = '\0';
      if (outFile)
        path += FChar('.');
      path += s;
      UInt32 step = GetTickCount() + 2;
      if (step == 0)
        step = 1;
      d += step;
    }
    addRandom = true;
    if (outFile)
      path += FTEXT(".tmp");
    if (NFind::DoesFileOrDirExist(path))
    {
      SetLastError(ERROR_ALREADY_EXISTS);
      continue;
    }
    if (outFile)
    {
      if (outFile->Create(path, false))
        return true;
    }
    else
    {
      if (MyCreateDirectory(path))
        return true;
    }
    DWORD error = GetLastError();
    if (error != ERROR_FILE_EXISTS &&
        error != ERROR_ALREADY_EXISTS)
      break;
  }
  path.Empty();
  return false;
}
Esempio n. 6
0
// =====================================================================================================================
//   str为要打开的文件名(包含路径) 例如 debug1/debug2/debug3/debug.log
// =====================================================================================================================
CFileLogWriter::CFileLogWriter(const std::string &str)
{
	// 先创建文件夹
	size_t pos = str.find('/');
	std::string strTemp;
	while (pos != std::string::npos) {
		strTemp = str.substr(0, pos);
		MyCreateDirectory(strTemp.c_str());
		pos = str.find('/', pos + 1);
	}

	m_fp = MyFileOpen(str.c_str(), "a+");
}
Esempio n. 7
0
// В asDir могут быть переменные окружения.
wchar_t* CConEmuUpdate::CreateTempFile(LPCWSTR asDir, LPCWSTR asFileNameTempl, HANDLE& hFile)
{
	wchar_t szFile[MAX_PATH*2+2];
	wchar_t szName[128];

	if (!asDir || !*asDir)
		asDir = L"%TEMP%\\ConEmu";
	if (!asFileNameTempl || !*asFileNameTempl)
		asFileNameTempl = L"ConEmu.tmp";

	if (wcschr(asDir, L'%'))
	{
		DWORD nExp = ExpandEnvironmentStrings(asDir, szFile, MAX_PATH);
		if (!nExp || (nExp >= MAX_PATH))
		{
			ReportError(L"CreateTempFile.ExpandEnvironmentStrings(%s) failed, code=%u", asDir, GetLastError());
			return NULL;
		}
	}
	else
	{
		lstrcpyn(szFile, asDir, MAX_PATH);
	}

	// Checking %TEMP% for valid path
	LPCWSTR pszColon1, pszColon2;
	if ((pszColon1 = wcschr(szFile, L':')) != NULL)
	{
		if ((pszColon2 = wcschr(pszColon1+1, L':')) != NULL)
		{
			ReportError(L"Invalid download path (%%TEMP%% variable?)\n%s", szFile, 0);
			return NULL;
		}
	}

	int nLen = lstrlen(szFile);
	if (nLen <= 0)
	{
		ReportError(L"CreateTempFile.asDir(%s) failed, path is null", asDir, 0);
		return NULL;
	}
	if (szFile[nLen-1] != L'\\')
	{
		szFile[nLen++] = L'\\'; szFile[nLen] = 0;
	}
	wchar_t* pszFilePart = szFile + nLen;

	wchar_t* pszDirectory = lstrdup(szFile);


	LPCWSTR pszName = PointToName(asFileNameTempl);
	_ASSERTE(pszName == asFileNameTempl);
	if (!pszName || !*pszName || (*pszName == L'.'))
	{
		_ASSERTE(pszName && *pszName && (*pszName != L'.'));
		pszName = L"ConEmu";
	}

	LPCWSTR pszExt = PointToExt(pszName);
	if (pszExt == NULL)
	{
		_ASSERTE(pszExt != NULL);
		pszExt = L".tmp";
	}

	lstrcpyn(szName, pszName, countof(szName)-16);
	wchar_t* psz = wcsrchr(szName, L'.');
	if (psz)
		*psz = 0;

	wchar_t* pszResult = NULL;
	DWORD dwErr = 0;

	for (UINT i = 0; i <= 9999; i++)
	{
		_wcscpy_c(pszFilePart, MAX_PATH, szName);
		if (i)
			_wsprintf(pszFilePart+_tcslen(pszFilePart), SKIPLEN(16) L"(%u)", i);
		_wcscat_c(pszFilePart, MAX_PATH, pszExt);

		hFile = CreateFile(szFile, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL|FILE_ATTRIBUTE_TEMPORARY, NULL);
		//ERROR_PATH_NOT_FOUND?
		if (!hFile || (hFile == INVALID_HANDLE_VALUE))
		{
			dwErr = GetLastError();
			// на первом обломе - попытаться создать директорию, может ее просто нет?
			if ((dwErr == ERROR_PATH_NOT_FOUND) && (i == 0))
			{
				if (!MyCreateDirectory(pszDirectory))
				{
					ReportError(L"CreateTempFile.asDir(%s) failed", asDir, 0);
					goto wrap;
				}
			}
		}

		if (hFile && hFile != INVALID_HANDLE_VALUE)
		{
			psz = lstrdup(szFile);
			if (!psz)
			{
				CloseHandle(hFile); hFile = NULL;
				ReportError(L"Can't allocate memory (%i bytes)", lstrlen(szFile));
			}
			pszResult = psz;
			goto wrap;
		}
	}

	ReportError(L"Can't create temp file(%s), code=%u", szFile, dwErr);
	hFile = NULL;
wrap:
	SafeFree(pszDirectory);
	return pszResult;
}