Пример #1
0
/**
 * @brief Removes all fragmentation reports from the volume.
 */
void remove_fragmentation_report(udefrag_job_parameters *jp)
{
    wchar_t *paths[] = {
        L"\\??\\%c:\\fraglist.luar",
        L"\\??\\%c:\\fraglist.txt",
        L"\\??\\%c:\\fraglist.htm",
        L"\\??\\%c:\\fraglist.html",
        NULL
    };
    wchar_t path[MAX_PATH + 1];
    wchar_t *new_path, *ext_path;
    int i;
    
    winx_dbg_print_header(0,0,I"*");
    
    /* remove old reports from the root directory */
    for(i = 0; paths[i]; i++){
        _snwprintf(path,MAX_PATH,paths[i],jp->volume_letter);
        path[MAX_PATH] = 0;
        (void)winx_delete_file(path);
    }
    
    /* remove reports from the reports directory */
    new_path = get_report_path(jp);
    if(new_path){
        (void)winx_delete_file(new_path);
        winx_path_remove_extension(new_path);
        ext_path = winx_swprintf(L"%ws.txt",new_path);
        if(ext_path == NULL){
            mtrace();
        } else {
            (void)winx_delete_file(ext_path);
            winx_free(ext_path);
        }
        ext_path = winx_swprintf(L"%ws.html",new_path);
        if(ext_path == NULL){
            mtrace();
        } else {
            (void)winx_delete_file(ext_path);
            winx_free(ext_path);
        }
        winx_free(new_path);
    }
}
Пример #2
0
static int save_lua_report(udefrag_job_parameters *jp)
{
    wchar_t *path = NULL;
    WINX_FILE *f;
    wchar_t *cn;
    wchar_t compname[MAX_COMPUTERNAME_LENGTH + 1];
    char utf8_compname[(MAX_COMPUTERNAME_LENGTH + 1) * 4];
    char buffer[512];
    struct prb_traverser t;
    winx_file_info *file;
    char *comment;
    char *status;
    int length;
    winx_time tm;
    
    /* should be enough for any path in UTF-8 encoding */
    #define MAX_UTF8_PATH_LENGTH (256 * 1024)
    char *utf8_path;
    
    utf8_path = winx_tmalloc(MAX_UTF8_PATH_LENGTH);
    if(utf8_path == NULL){
        mtrace();
        return (-1);
    }
    
    path = get_report_path(jp);
    if(path == NULL)
        return UDEFRAG_NO_MEM;
    
    f = winx_fbopen(path,"w",RSB_SIZE);
    if(f == NULL){
        f = winx_fopen(path,"w");
        if(f == NULL){
            winx_free(path);
            winx_free(utf8_path);
            return (-1);
        }
    }

    /* print header */
    cn = winx_getenv(L"COMPUTERNAME");
    if(cn){
        wcsncpy(compname,cn,MAX_COMPUTERNAME_LENGTH + 1);
        compname[MAX_COMPUTERNAME_LENGTH] = 0;
        winx_free(cn);
    } else {
        wcscpy(compname,L"nil");
    }
    winx_to_utf8(utf8_compname,sizeof(utf8_compname),compname);
    memset(&tm,0,sizeof(winx_time));
    (void)winx_get_local_time(&tm);
    (void)_snprintf(buffer,sizeof(buffer),
        "-- UltraDefrag report for disk %c:\r\n\r\n"
        "format_version = 7\r\n\r\n"
        "volume_letter = \"%c\"\r\n"
        "computer_name = \"%hs\"\r\n\r\n"
        "current_time = {\r\n"
        "\tyear = %04i,\r\n"
        "\tmonth = %02i,\r\n"
        "\tday = %02i,\r\n"
        "\thour = %02i,\r\n"
        "\tmin = %02i,\r\n"
        "\tsec = %02i,\r\n"
        "\tisdst = false\r\n"
        "}\r\n\r\n"
        "files = {\r\n",
        jp->volume_letter, jp->volume_letter,utf8_compname,
        (int)tm.year,(int)tm.month,(int)tm.day,
        (int)tm.hour,(int)tm.minute,(int)tm.second
        );
    buffer[sizeof(buffer) - 1] = 0;
    (void)winx_fwrite(buffer,1,strlen(buffer),f);
    
    /* print body */
    prb_t_init(&t,jp->fragmented_files);
    file = prb_t_first(&t,jp->fragmented_files);
    while(file){
        if(is_directory(file))
            comment = "[DIR]";
        else if(is_compressed(file))
            comment = "[CMP]";
        else
            comment = " - ";
        
        /*
        * On change of status strings don't forget
        * also to adjust write_file_status routine
        * in udreportcnv.lua file.
        */
        if(is_locked(file))
            status = "locked";
        else if(is_moving_failed(file))
            status = "move failed";
        else if(is_in_improper_state(file))
            status = "invalid";
        else
            status = " - ";
        
        (void)_snprintf(buffer, sizeof(buffer),
            "\t{fragments = %u,"
            "size = %I64u,"
            "comment = \"%s\","
            "status = \"%s\","
            "path = \"",
            (UINT)file->disp.fragments,
            file->disp.clusters * jp->v_info.bytes_per_cluster,
            comment,
            status
            );
        buffer[sizeof(buffer) - 1] = 0;
        (void)winx_fwrite(buffer,1,strlen(buffer),f);

        if(file->path != NULL){
            /* skip \??\ sequence in the beginning of the path */
            length = (int)wcslen(file->path);
            if(length > 4){
                convert_to_utf8_path(utf8_path,MAX_UTF8_PATH_LENGTH,file->path + 4);
            } else {
                convert_to_utf8_path(utf8_path,MAX_UTF8_PATH_LENGTH,file->path);
            }
            (void)winx_fwrite(utf8_path,1,strlen(utf8_path),f);
        }

        (void)strcpy(buffer,"\"},\r\n");
        (void)winx_fwrite(buffer,1,strlen(buffer),f);

        file = prb_t_next(&t);
    }
    
    /* print footer */
    (void)strcpy(buffer,"}\r\n");
    (void)winx_fwrite(buffer,1,strlen(buffer),f);

    itrace("report saved to %ws",path);
    winx_fclose(f);
    winx_free(path);
    winx_free(utf8_path);
    return 0;
}
Пример #3
0
        // This method creates minidump of the process
        void crash_handler::create_mini_dump(EXCEPTION_POINTERS* pExcPtrs)
        {   
            MINIDUMP_EXCEPTION_INFORMATION mei;
            MINIDUMP_CALLBACK_INFORMATION mci;

            // Load dbghelp.dll
            HMODULE hDbgHelp = LoadLibrary(_T("dbghelp.dll"));
            if(hDbgHelp == NULL)
            {
                // Error - couldn't load dbghelp.dll
                return;
            }

            // create folder if not existed
            if (!CreateDirectory((get_report_path() + std::wstring(L"\\")).c_str(), NULL) &&
                ERROR_ALREADY_EXISTS != GetLastError())
            {
                return;
            }

            create_log_file_for_hockey_app(pExcPtrs);

            // Create the minidump file
            HANDLE handleFile (CreateFile(
                get_report_mini_dump_path().c_str(),
                GENERIC_WRITE,
                0,
                NULL,
                CREATE_ALWAYS,
                FILE_ATTRIBUTE_NORMAL,
                NULL));

            // https://msdn.microsoft.com/ru-ru/library/windows/desktop/5fc6ft2t(v=vs.80).aspx
            if(handleFile==INVALID_HANDLE_VALUE)
            {
                return;
            }

            CHandle hFile(handleFile);

            // Write minidump to the file
            mei.ThreadId = GetCurrentThreadId();
            mei.ExceptionPointers = pExcPtrs;
            mei.ClientPointers = FALSE;
            mci.CallbackRoutine = NULL;
            mci.CallbackParam = NULL;

            typedef BOOL (WINAPI *LPMINIDUMPWRITEDUMP)(
                HANDLE hProcess, 
                DWORD ProcessId, 
                HANDLE hFile, 
                MINIDUMP_TYPE DumpType, 
                CONST PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam, 
                CONST PMINIDUMP_USER_STREAM_INFORMATION UserEncoderParam, 
                CONST PMINIDUMP_CALLBACK_INFORMATION CallbackParam);

            LPMINIDUMPWRITEDUMP pfnMiniDumpWriteDump = 
                (LPMINIDUMPWRITEDUMP)GetProcAddress(hDbgHelp, "MiniDumpWriteDump");
            if(!pfnMiniDumpWriteDump)
            {    
                // Bad MiniDumpWriteDump function
                return;
            }

            HANDLE hProcess = GetCurrentProcess();
            DWORD dwProcessId = GetCurrentProcessId();
            auto dump_type = (_MINIDUMP_TYPE)get_dump_type();
            if (dump_type == -1)
            {
                assert(!"dump_type must be positive");
                dump_type = MiniDumpNormal;
            }

            BOOL bWriteDump = pfnMiniDumpWriteDump(
                hProcess,
                dwProcessId,
                hFile,
                dump_type,
                &mei,
                NULL,
                &mci);

            if(!bWriteDump)
            {    
                // Error writing dump.
                return;
            }

            // Unload dbghelp.dll
            FreeLibrary(hDbgHelp);
        }