Пример #1
0
// Populate file info for the specified file in the callee heap-allocated memory location
// and return the pointer to this location to the caller.
BOOL CreateFileInfo(_In_ PCWSTR pszFullpathToFile, _In_ BOOL fComputeHash, _Out_ PFILEINFO* ppFileInfo)
{
    SB_ASSERT(pszFullpathToFile);
    SB_ASSERT(ppFileInfo);

    PFILEINFO pFileInfo;
    pFileInfo = (PFILEINFO)malloc(sizeof(FILEINFO));
    if (pFileInfo == NULL)
    {
        goto error_return;
    }

    if (!CreateFileInfo(pszFullpathToFile, fComputeHash, pFileInfo))
    {
        goto error_return;
    }

    *ppFileInfo = pFileInfo;
    return TRUE;

error_return:
    if (pFileInfo != NULL)
    {
        free(pFileInfo);
    }

    *ppFileInfo = NULL;
    return FALSE;
}
Пример #2
0
void TCPClient::DownloadFile(string fileName)
{
	auto file = new fstream();
	OpenFile(file, GetLocalFileName(fileName));
	fpos_t currentProgress = file->tellp();
	fpos_t fileSize = 0;

	auto done = false;
	cout << "Download started." << endl;
	while (!done)
	{
		try {
			SendMessage(this->_tcp_socket, CreateFileInfo(fileName, currentProgress));
			fileSize = ReceiveFileSize();
			ReceiveFile(file, currentProgress, fileSize);
			done = true;
		}
		catch (ConnectionInterrupted e) {
			currentProgress = e.GetProgress();
			Reconnect();
		}
		catch (ServerError) {
			file->close();
			throw;
		}
		catch (runtime_error e) {
			cout << e.what() << endl;
			Reconnect();
		}
	}
	file->close();
	cout << "Done." << endl;
}
Пример #3
0
void * TConfiguration::GetFileApplicationInfo(const UnicodeString & AFileName) const
{
  void * Result;
  if (AFileName.IsEmpty())
  {
    if (!FApplicationInfo)
    {
      FApplicationInfo = CreateFileInfo(ModuleFileName());
    }
    Result = FApplicationInfo;
  }
  else
  {
    Result = CreateFileInfo(AFileName);
  }
  return Result;
}
Пример #4
0
JNIEXPORT jobject JNICALL Java_com_intellij_openapi_vfs_impl_win32_IdeaWin32_getInfo(JNIEnv *env, jobject method, jstring path) {
    WIN32_FIND_DATA data;
    HANDLE h = FindFileInner(env, path, &data);
    if (h == INVALID_HANDLE_VALUE) {
        return NULL;
    }
    FindClose(h);	
    jclass infoClass = env->FindClass("com/intellij/openapi/vfs/impl/win32/FileInfo");
    return CreateFileInfo(env, path, false, &data, infoClass);
}
Пример #5
0
JNIEXPORT jobjectArray JNICALL Java_com_intellij_openapi_util_io_win32_IdeaWin32_listChildren0(JNIEnv *env, jobject method, jstring path) {
    WIN32_FIND_DATA data;
    HANDLE h = FindFileInner(env, path, &data);
    if (h == INVALID_HANDLE_VALUE) {
        return NULL;
    }

    jclass fileInfoClass = getFileInfoClass(env);
    if (fileInfoClass == NULL) {
        return NULL;
    }

    jobjectArray rv, old;
    int len = 0, maxlen = 16;
    rv = env->NewObjectArray(maxlen, fileInfoClass, NULL);
    if (rv == NULL) {
        goto error;
    }

    do {
        if (len == maxlen) {
            old = rv;
            rv = env->NewObjectArray(maxlen <<= 1, fileInfoClass, NULL);
            if (rv == NULL || !CopyObjectArray(env, rv, old, len)) {
                goto error;
            }
            env->DeleteLocalRef(old);
        }
        jobject o = CreateFileInfo(env, path, true, &data, fileInfoClass);
        env->SetObjectArrayElement(rv, len++, o);
        env->DeleteLocalRef(o);
    }
    while (FindNextFile(h, &data));

    FindClose(h);	

    old = rv;
    rv = env->NewObjectArray(len, fileInfoClass, NULL);
    if (rv == NULL || !CopyObjectArray(env, rv, old, len)) {
        goto error;
    }
    return rv;

error:
    FindClose(h);	
    return NULL;
}
Пример #6
0
UnicodeString TConfiguration::GetFileVersion(const UnicodeString & FileName)
{
  UnicodeString Result;
  void * FileInfo = CreateFileInfo(FileName);
  try__finally
  {
    SCOPE_EXIT
    {
      FreeFileInfo(FileInfo);
    };
    Result = GetFileVersion(GetFixedFileInfo(FileInfo));
  }
  __finally
  {
    FreeFileInfo(FileInfo);
  };
  return Result;
}
Пример #7
0
JNIEXPORT jobject JNICALL Java_com_intellij_openapi_util_io_win32_IdeaWin32_getInfo0(JNIEnv *env, jobject method, jstring path) {
    bool isDrive = false;
    if (env->GetStringLength(path) == 2) {
        const jchar* str = env->GetStringChars(path, NULL);
        isDrive = (str[1] == ':');
        env->ReleaseStringChars(path, str);
    }

    WIN32_FIND_DATA data;
    HANDLE h = INVALID_HANDLE_VALUE;

    if (!isDrive) {
        h = FindFileInner(env, path, &data);
        if (h == INVALID_HANDLE_VALUE && GetLastError() != ERROR_ACCESS_DENIED) {
            return NULL;
        }
    }

    if (h == INVALID_HANDLE_VALUE) {
        WIN32_FILE_ATTRIBUTE_DATA attrData;
        const jchar* str = env->GetStringChars(path, 0);
        BOOL res = GetFileAttributesEx((LPCWSTR)str, GetFileExInfoStandard, &attrData);
        env->ReleaseStringChars(path, str);
        if (!res) {
            return NULL;
        }

        data.dwFileAttributes = attrData.dwFileAttributes;
        data.dwReserved0 = 0;
        data.ftLastWriteTime = attrData.ftLastWriteTime;
        data.nFileSizeLow = attrData.nFileSizeLow;
        data.nFileSizeHigh = attrData.nFileSizeHigh;
    }
    else {
        FindClose(h);
    }

    jclass fileInfoClass = getFileInfoClass(env);
    if (fileInfoClass == NULL) {
        return NULL;
    }

    return CreateFileInfo(env, path, false, &data, fileInfoClass);
}
Пример #8
0
JNIEXPORT jobject JNICALL Java_com_intellij_openapi_util_io_win32_IdeaWin32_getInfo0(JNIEnv *env, jobject method, jstring path) {
    WIN32_FILE_ATTRIBUTE_DATA attrData;
    const jchar* str = env->GetStringChars(path, 0);
    BOOL res = GetFileAttributesEx((LPCWSTR)str, GetFileExInfoStandard, &attrData);
    env->ReleaseStringChars(path, str);
    if (!res) {
        return NULL;
    }

    WIN32_FIND_DATA data;
    data.dwFileAttributes = attrData.dwFileAttributes;
    data.dwReserved0 = 0;
    data.ftLastWriteTime = attrData.ftLastWriteTime;
    data.nFileSizeLow = attrData.nFileSizeLow;
    data.nFileSizeHigh = attrData.nFileSizeHigh;

    if (IS_SET(attrData.dwFileAttributes, FILE_ATTRIBUTE_REPARSE_POINT)) {
        WIN32_FIND_DATA findData;
        HANDLE h = FindFileInner(env, path, &findData);
        if (h != INVALID_HANDLE_VALUE) {
            FindClose(h);
            data.dwFileAttributes = findData.dwFileAttributes;
            data.dwReserved0 = findData.dwReserved0;
            data.ftLastWriteTime = findData.ftLastWriteTime;
            data.nFileSizeLow = findData.nFileSizeLow;
            data.nFileSizeHigh = findData.nFileSizeHigh;
        }
    }

    jclass fileInfoClass = getFileInfoClass(env);
    if (fileInfoClass == NULL) {
        return NULL;
    }

    return CreateFileInfo(env, path, false, &data, fileInfoClass);
}
Пример #9
0
// Build the list of files in the given folder.
BOOL BuildFilesInDir_NoHash(
    _In_ PCWSTR pszFolderpath,
    _In_opt_ PCHL_QUEUE pqDirsToTraverse,
    _Inout_ PDIRINFO* ppDirInfo)
{
    SB_ASSERT(pszFolderpath);
    SB_ASSERT(ppDirInfo);

    HANDLE hFindFile = NULL;

    loginfo(L"Building dir: %s", pszFolderpath);
    if (*ppDirInfo == NULL && FAILED(_Init(pszFolderpath, (pqDirsToTraverse != NULL), ppDirInfo)))
    {
        logerr(L"Init failed for dir: %s", pszFolderpath);
        goto error_return;
    }

    // Derefernce just to make it easier to code
    PDIRINFO pCurDirInfo = *ppDirInfo;

    // In order to list all files within the specified directory,
    // path sent to FindFirstFile must end with a "\\*"
    WCHAR szSearchpath[MAX_PATH] = L"";
    wcscpy_s(szSearchpath, ARRAYSIZE(szSearchpath), pszFolderpath);

    int nLen = wcsnlen(pszFolderpath, MAX_PATH);
    if (nLen > 2 && wcsncmp(pszFolderpath + nLen - 2, L"\\*", MAX_PATH) != 0)
    {
        PathCchCombine(szSearchpath, ARRAYSIZE(szSearchpath), pszFolderpath, L"*");
    }

    // Initialize search for files in folder
    WIN32_FIND_DATA findData;
    hFindFile = FindFirstFile(szSearchpath, &findData);
    if (hFindFile == INVALID_HANDLE_VALUE && GetLastError() == ERROR_FILE_NOT_FOUND)
    {
        // No files found under the folder. Just return.
        return TRUE;
    }

    if (hFindFile == INVALID_HANDLE_VALUE)
    {
        logerr(L"FindFirstFile().");
        goto error_return;
    }

    do
    {
        // Skip banned files and folders
        if (IsFileFolderBanned(findData.cFileName, ARRAYSIZE(findData.cFileName)))
        {
            continue;
        }

        szSearchpath[0] = 0;
        if (FAILED(PathCchCombine(szSearchpath, ARRAYSIZE(szSearchpath), pszFolderpath, findData.cFileName) == NULL))
        {
            logerr(L"PathCchCombine() failed for %s and %s", pszFolderpath, findData.cFileName);
            goto error_return;
        }

        PFILEINFO pFileInfo;
        if (!CreateFileInfo(szSearchpath, FALSE, &pFileInfo))
        {
            // Treat as warning and move on.
            logwarn(L"Unable to get file info for: %s", szSearchpath);
            continue;
        }

        if (pFileInfo->fIsDirectory && pqDirsToTraverse)
        {
            // If pqDirsToTraverse is not null, it means caller wants recursive directory traversal
            PDIRINFO pSubDir;
            if (FAILED(_Init(szSearchpath, TRUE, &pSubDir)))
            {
                logwarn(L"Unable to init dir info for: %s", szSearchpath);
                free(pFileInfo);
                continue;
            }

            // Insert pSubDir into the queue so that it will be traversed later
            if (FAILED(pqDirsToTraverse->Insert(pqDirsToTraverse, pSubDir, sizeof pSubDir)))
            {
                logwarn(L"Unable to add sub dir [%s] to traversal queue, cur dir: %s", findData.cFileName, pszFolderpath);
                free(pFileInfo);
                continue;
            }
            ++(pCurDirInfo->nDirs);
        }
        else
        {
            // Either this is a file or a directory but the folder must be considered as a file
            // because recursion is not enabled and we want to enable comparison of some attributes of a folder.
            // If the current file's name is already inserted, then add it to the dup within list
            BOOL fFileAdded;
            if (SUCCEEDED(CHL_DsFindHT(pCurDirInfo->phtFiles, findData.cFileName,
                StringSizeBytes(findData.cFileName), NULL, NULL, TRUE)))
            {
                fFileAdded = AddToDupWithinList(&pCurDirInfo->stDupFilesInTree, pFileInfo);
            }
            else
            {
                fFileAdded = SUCCEEDED(CHL_DsInsertHT(pCurDirInfo->phtFiles, findData.cFileName,
                    StringSizeBytes(findData.cFileName), pFileInfo, sizeof pFileInfo));
            }

            if (!fFileAdded)
            {
                logerr(L"Cannot add %s to file list: %s", (pFileInfo->fIsDirectory ? L"dir" : L"file"), findData.cFileName);
                free(pFileInfo);
            }
            else
            {
                pFileInfo->fIsDirectory ? ++(pCurDirInfo->nDirs) : ++(pCurDirInfo->nFiles);
                logdbg(L"Added %s: %s", (pFileInfo->fIsDirectory ? L"dir" : L"file"), findData.cFileName);
            }
        }
    } while (FindNextFile(hFindFile, &findData));

    if (GetLastError() != ERROR_NO_MORE_FILES)
    {
        logerr(L"Failed in enumerating files in directory: %s", pszFolderpath);
        goto error_return;
    }

    FindClose(hFindFile);
    return TRUE;

error_return:
    if (hFindFile != INVALID_HANDLE_VALUE)
    {
        FindClose(hFindFile);
    }

    if (*ppDirInfo != NULL)
    {
        DestroyDirInfo_NoHash(*ppDirInfo);
        *ppDirInfo = NULL;
    }

    return FALSE;
}