示例#1
0
void *BtdThread::Entry()
{
    itrace("boot registration tracking started");

    HKEY hKey = NULL; HANDLE hEvent = NULL;
    if(::RegOpenKeyExW(HKEY_LOCAL_MACHINE,
      L"SYSTEM\\CurrentControlSet\\Control\\Session Manager",
      0,KEY_NOTIFY,&hKey) != ERROR_SUCCESS){
        letrace("cannot open SMSS key");
        goto done;
    }

    hEvent = ::CreateEvent(NULL,FALSE,FALSE,NULL);
    if(hEvent == NULL){
        letrace("cannot create event for SMSS key tracking");
        goto done;
    }

    while(!g_mainFrame->CheckForTermination(1)){
        LONG error = ::RegNotifyChangeKeyValue(hKey,FALSE,
            REG_NOTIFY_CHANGE_LAST_SET,hEvent,TRUE);
        if(error != ERROR_SUCCESS){
            ::SetLastError(error);
            letrace("RegNotifyChangeKeyValue failed");
            break;
        }
        while(!g_mainFrame->CheckForTermination(1)){
            if(::WaitForSingleObject(hEvent,100) == WAIT_OBJECT_0){
                int result = ::winx_bootex_check(L"defrag_native");
                if(result >= 0){
                    itrace("boot time defragmenter %hs",
                        result > 0 ? "enabled" : "disabled");
                    wxCommandEvent event(wxEVT_COMMAND_MENU_SELECTED,ID_BootChange);
                    event.SetInt(result > 0 ? true : false);
                    wxPostEvent(g_mainFrame,event);
                }
                break;
            }
        }
    }

done:
    if(hEvent) ::CloseHandle(hEvent);
    if(hKey) ::RegCloseKey(hKey);
    itrace("boot registration tracking stopped");
    return NULL;
}
示例#2
0
/**
 * @brief Returns true if the program
 * is going to be terminated.
 * @param[in] time timeout interval,
 * in milliseconds.
 */
bool MainFrame::CheckForTermination(int time)
{
    DWORD result = ::WaitForSingleObject(g_synchEvent,(DWORD)time);
    if(result == WAIT_FAILED){
        letrace("synchronization failed");
        return true;
    }
    return result == WAIT_OBJECT_0 ? true : false;
}
示例#3
0
ClusterMap::ClusterMap(wxWindow* parent) : wxWindow(parent,wxID_ANY)
{
    HDC hdc = GetDC((HWND)GetHandle());
    m_cacheDC = ::CreateCompatibleDC(hdc);
    if(!m_cacheDC) letrace("cannot create cache dc");
    m_cacheBmp = ::CreateCompatibleBitmap(hdc,
                                          wxGetDisplaySize().GetWidth(),
                                          wxGetDisplaySize().GetHeight()
                                         );
    if(!m_cacheBmp) letrace("cannot create cache bitmap");
    ::SelectObject(m_cacheDC,m_cacheBmp);
    ::SetBkMode(m_cacheDC,TRANSPARENT);
    ::ReleaseDC((HWND)GetHandle(),hdc);

    for(int i = 0; i < SPACE_STATES; i++)
        m_brushes[i] = ::CreateSolidBrush(g_colors[i]);

    m_width = m_height = 0;
}
示例#4
0
int __cdecl main(int argc,char **argv)
{
    int i, now = 0;

    for(i = 1; i < argc; i++){
        if(!_stricmp(argv[i],"now"))
            now = 1;
    }

    if(now == 0){
        show_help();
        return EXIT_SUCCESS;
    }

    printf("Hibernate for Windows - a command line tool for Windows hibernation.\n");
    printf("Copyright (c) UltraDefrag Development Team, 2009-2013.\n\n");
    
    if(winx_init_library() < 0){
        fprintf(stderr,"Initialization failed!\n");
        return EXIT_FAILURE;
    }

    if(winx_enable_privilege(SE_SHUTDOWN_PRIVILEGE) < 0){
        fprintf(stderr,"Cannot enable shutdown privilege!\n"
            "Use DbgView program to get more information.\n");
        return EXIT_FAILURE;
    }

    /* hibernate, request permission from apps and drivers */
    if(!SetSuspendState(TRUE,FALSE,FALSE)){
        letrace("cannot hibernate the computer");
        fprintf(stderr,"Cannot hibernate the computer!\n"
            "Use DbgView program to get more information.\n");
        return EXIT_FAILURE;
    }
    return EXIT_SUCCESS;
}
示例#5
0
/**
 * @brief Initializes the application.
 */
bool App::OnInit()
{
    // initialize wxWidgets
    SetAppName(wxT("UltraDefrag"));
    wxInitAllImageHandlers();
    if(!wxApp::OnInit())
        return false;

    // initialize udefrag library
    if(::udefrag_init_library() < 0){
        wxLogError(wxT("Initialization failed!"));
        return false;
    }

    // set out of memory handler
#if !defined(__GNUC__)
    winx_set_killer(out_of_memory_handler);
    _set_new_handler(out_of_memory_handler);
    _set_new_mode(1);
#endif

    // initialize debug log
    wxFileName logpath(wxT(".\\logs\\ultradefrag.log"));
    logpath.Normalize();
    wxSetEnv(wxT("UD_LOG_FILE_PATH"),logpath.GetFullPath());
    ::udefrag_set_log_file_path();

    // initialize logging
    m_log = new Log();

    // use global config object for internal settings
    wxFileConfig *cfg = new wxFileConfig(wxT(""),wxT(""),
        wxT("gui.ini"),wxT(""),wxCONFIG_USE_RELATIVE_PATH);
    wxConfigBase::Set(cfg);

    // enable i18n support
    InitLocale();

    // save report translation on setup
    wxString cmdLine(GetCommandLine());
    if(cmdLine.Find(wxT("--setup")) != wxNOT_FOUND){
        SaveReportTranslation();
        ::winx_flush_dbg_log(0);
        delete m_log;
        return false;
    }

    // start web statistics
    m_statThread = new StatThread();

    // check for administrative rights
    if(!Utils::CheckAdminRights()){
        wxMessageDialog dlg(NULL,
            wxT("Administrative rights are needed to run the program!"),
            wxT("UltraDefrag"),wxOK | wxICON_ERROR
        );
        dlg.ShowModal(); Cleanup();
        return false;
    }

    // create synchronization event
    g_synchEvent = ::CreateEvent(NULL,TRUE,FALSE,NULL);
    if(!g_synchEvent){
        letrace("cannot create synchronization event");
        wxMessageDialog dlg(NULL,
            wxT("Cannot create synchronization event!"),
            wxT("UltraDefrag"),wxOK | wxICON_ERROR
        );
        dlg.ShowModal(); Cleanup();
        return false;
    }

    // keep things DPI-aware
    HDC hdc = ::GetDC(NULL);
    if(hdc){
        g_scaleFactor = (double)::GetDeviceCaps(hdc,LOGPIXELSX) / 96.0f;
        ::ReleaseDC(NULL,hdc);
    }
    g_iconSize = wxSystemSettings::GetMetric(wxSYS_SMALLICON_X);
    if(g_iconSize < 20) g_iconSize = 16;
    else if(g_iconSize < 24) g_iconSize = 20;
    else if(g_iconSize < 32) g_iconSize = 24;
    else g_iconSize = 32;

    // support taskbar icon overlay setup on shell restart
    g_TaskbarIconMsg = ::RegisterWindowMessage(wxT("TaskbarButtonCreated"));
    if(!g_TaskbarIconMsg) letrace("cannot register TaskbarButtonCreated message");

    // create main window
    g_mainFrame = new MainFrame();
    g_mainFrame->Show(true);
    SetTopWindow(g_mainFrame);
    return true;
}