Beispiel #1
0
/* This function is used to delete a file or directory specified by the
 * 'name' variable.  The type of 'name' is figured out.  If the recurse
 * option is TRUE, directories will be recursively emptied then deleted.
 * If force is TRUE, file attributes will be changed to allow the program
 * to delete the file.  The verbose option will cause non-fatal error messages
 * to print to stderr.  The quiet option will supress all but fatal
 * error messages
 */
BOOL del(wchar_t* name, BOOL recurse, BOOL force, BOOL verbose, BOOL quiet) {
    BOOL rv = TRUE;
    DWORD fileAttr = GetFileAttributesW(name);
    if (fileAttr == INVALID_FILE_ATTRIBUTES){
        rv = FALSE;
        if (!quiet) {
            fwprintf(stderr, L"Invalid file attributes for \"%ws\"\n", name);
        }
    } else if (fileAttr & FILE_ATTRIBUTE_DIRECTORY) {
        if (recurse){
            if (!empty_directory(name, force, verbose, quiet)){
                rv = FALSE;
            }
        } else {
            if (!del_directory(name, force, verbose, quiet)){
                rv = FALSE;
            }
        }
    } else {
        if (!del_file(name, force, verbose, quiet)){
            rv = FALSE;
        }
    }
    return rv;
}
static GdkPixbuf *
skin_get_preview(const gchar * path)
{
    GdkPixbuf *preview = NULL;
    gchar *dec_path, *preview_path;
    gboolean is_archive = FALSE;
    gint i = 0;
    gchar buf[60];			/* gives us lots of room */

    if (file_is_archive(path))
    {
        if (!(dec_path = archive_decompress(path)))
            return NULL;

        is_archive = TRUE;
    }
    else
    {
        dec_path = g_strdup(path);
    }

    for (i = 0; i < EXTENSION_TARGETS; i++)
    {
        sprintf(buf, "main.%s", ext_targets[i]);

        if ((preview_path = find_file_case_path (dec_path, buf)) != NULL)
            break;
    }

    if (preview_path)
    {
        preview = gdk_pixbuf_new_from_file(preview_path, NULL);
        g_free(preview_path);
    }

    if (is_archive)
        del_directory(dec_path);

    g_free(dec_path);

    return preview;
}
Beispiel #3
0
/* This function will recursively remove all files in a directory
 * then the directory itself.
 */
BOOL empty_directory(wchar_t* name, BOOL force, BOOL verbose, BOOL quiet){
    BOOL rv = TRUE;
    DWORD ffStatus;
    WIN32_FIND_DATAW findFileData;
    // TODO: Don't waste so much memory!
    wchar_t dir[MAX_PATH];
    HANDLE hFind = INVALID_HANDLE_VALUE;
	// Used while disabling Wow64 FS Redirection
	//Unused for now PVOID* wow64value = NULL;

    /* without a trailing \*, the listing for "c:\windows" would show info
     * for "c:\windows", not files *inside* of "c:\windows"
     */
    StringCchCopyW(dir, MAX_PATH, name); // TODO: Check return
    StringCchCatW(dir, MAX_PATH, L"\\*");

    /* We don't know what's going on, but Wow64 redirection
     * is not working quite right.  Since nothing we have should
     * be in a location that needs Wow64, we should be fine to
     * ignore it
     */
    //Wow64DisableWow64FsRedirection(wow64value);

    hFind = FindFirstFileW(dir, &findFileData);

    if (hFind == INVALID_HANDLE_VALUE) {
        rv = FALSE;
        if (!quiet) {
            print_error(GetLastError(), name, stderr);
        }
        return rv;
    }

    do {
        wchar_t fullName[MAX_PATH];
        StringCchCopyW(fullName, MAX_PATH, name);
        StringCchCatW(fullName, MAX_PATH, L"\\");
        StringCchCatW(fullName, MAX_PATH, findFileData.cFileName);
        if (findFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
            if (wcscmp(L".", findFileData.cFileName) != 0 && wcscmp(L"..", findFileData.cFileName) != 0){
                if (!empty_directory(fullName, force, verbose, quiet)){
                    rv = FALSE;
                }
            }
        } else {
            if (!del_file(fullName, force, verbose, quiet)) {
                rv = FALSE;
            }
        }
    } while (FindNextFileW(hFind, &findFileData) != 0);

    /* if (!Wow64RevertWow64FsRedirection(wow64value)) {
     *    if (!quiet) {
     *        fwprintf(stderr, L"Error restoring Wow64 FS Redirection\n");
     *    }
     *    return FALSE;
     * }
     */

    ffStatus = GetLastError();
    if (ffStatus != ERROR_NO_MORE_FILES) {
        print_error(ffStatus, findFileData.cFileName, stderr);
        rv = FALSE;
    }

    FindClose(hFind);

    del_directory(name, force, verbose, quiet);

    return rv;

}