/** * @internal * @brief get_boot_exec_list helper. */ NTSTATUS NTAPI query_routine(PWSTR ValueName, ULONG ValueType,PVOID ValueData,ULONG ValueLength, PVOID Context,PVOID EntryContext) { struct cmd **list = (struct cmd **)Context; struct cmd *command, *prev_command = NULL; wchar_t *cmd; if(list == NULL){ etrace("list is equal to NULL"); return STATUS_UNSUCCESSFUL; } if(ValueType != REG_SZ){ etrace("invalid %ws value type: 0x%x", ValueName, (UINT)ValueType); return STATUS_UNSUCCESSFUL; } cmd = winx_tmalloc(ValueLength + sizeof(wchar_t)); if(cmd == NULL){ mtrace(); return STATUS_NO_MEMORY; } memset(cmd,0,ValueLength + sizeof(wchar_t)); memcpy(cmd,ValueData,ValueLength); if(*list) prev_command = (*list)->prev; command = (struct cmd *)winx_list_insert( (list_entry **)(void *)list, (list_entry *)prev_command, sizeof(struct cmd)); command->cmd = cmd; return STATUS_SUCCESS; }
/** * @brief Check whether the requested * action is allowed or not. * @return Zero indicates that the * requested operation is allowed, * negative value indicates contrary. */ static int check_requested_action(udefrag_job_parameters *jp) { if(jp->job_type != ANALYSIS_JOB && jp->fs_type == FS_UDF){ etrace("cannot defragment/optimize UDF volumes,"); etrace("because the file system driver does not support FSCTL_MOVE_FILE"); return UDEFRAG_UDF_DEFRAG; } if(jp->is_fat) itrace("FAT directories cannot be moved entirely"); return 0; }
/** * @brief Creates a directory tree. * @param[in] path the native path. * @return Zero for success, * negative value otherwise. */ int winx_create_path(wchar_t *path) { /*wchar_t rootdir[] = L"\\??\\X:\\";*/ winx_volume_information v; wchar_t *p; size_t n; if(path == NULL) return (-1); /* path must contain at least \??\X: */ if(wcsstr(path,L"\\??\\") != path || wcschr(path,':') != (path + 5)){ etrace("native path must be specified"); return (-1); } n = wcslen(L"\\??\\X:\\"); if(wcslen(path) <= n){ /* check for volume existence */ /* rootdir[4] = path[4]; // may fail with access denied status return winx_create_directory(rootdir); */ return winx_get_volume_information((char)path[4],&v); } /* skip \??\X:\ */ p = path + n; /* create directory tree */ while((p = wcschr(p,'\\'))){ *p = 0; if(winx_create_directory(path) < 0){ *p = '\\'; etrace("cannot create %ws",path); return (-1); } *p = '\\'; p ++; } /* create target directory */ if(winx_create_directory(path) < 0){ etrace("cannot create %ws",path); return (-1); } return 0; }
/** * @brief Removes a file block from * the binary tree of all file blocks. * @return Zero for success, * negative value otherwise. */ int remove_block_from_file_blocks_tree(udefrag_job_parameters *jp, winx_blockmap *block) { struct file_block *fb; struct file_block b; if(block == NULL) return (-1); if(jp->file_blocks == NULL) return (-1); b.file = NULL; b.block = block; fb = prb_delete(jp->file_blocks,&b); if(fb == NULL){ /* the following debugging output indicates either a bug, or file system inconsistency */ etrace("failed for %p: VCN = %I64u, LCN = %I64u, LEN = %I64u", block, block->vcn, block->lcn, block->length); /* if block does not exist in tree, we have nothing to cleanup */ return 0; } winx_free(fb); return 0; }
static wchar_t *get_report_path(udefrag_job_parameters *jp) { wchar_t *instdir, *fpath; wchar_t *isportable;//genBTC wchar_t *path = NULL; isportable = winx_getenv(L"UD_IS_PORTABLE");//genBTC if(isportable != NULL){ /* portable version? */ fpath = winx_get_module_filename(); if(fpath == NULL){ etrace("cannot get program\'s path"); } else { winx_path_remove_filename(fpath); path = winx_swprintf(L"\\??\\%ws\\reports",fpath); if(path == NULL){ etrace("not enough memory (case 1)"); } else { (void)winx_create_directory(path); winx_free(path); } path = winx_swprintf(L"\\??\\%ws\\reports\\fraglist_%c.luar", fpath,winx_tolower(jp->volume_letter)); if(path == NULL) etrace("not enough memory (case 2)"); winx_free(fpath); } } else { instdir = winx_getenv(L"UD_INSTALL_DIR"); /* regular installation */ path = winx_swprintf(L"\\??\\%ws\\reports",instdir); if(path == NULL){ etrace("not enough memory (case 3)"); } else { (void)winx_create_directory(path); winx_free(path); } path = winx_swprintf(L"\\??\\%ws\\reports\\fraglist_%c.luar", instdir,winx_tolower(jp->volume_letter)); if(path == NULL) etrace("not enough memory (case 4)"); winx_free(instdir); } return path; }
void MainFrame::SetSystemTrayIcon(const wxString& icon, const wxString& tooltip) { if(CheckOption(wxT("UD_MINIMIZE_TO_SYSTEM_TRAY"))){ wxIcon i = wxIcon(icon,wxBITMAP_TYPE_ICO_RESOURCE,g_iconSize,g_iconSize); if(!m_systemTrayIcon->SetIcon(i,tooltip)){ etrace("system tray icon setup failed"); wxSetEnv(wxT("UD_MINIMIZE_TO_SYSTEM_TRAY"),wxT("0")); } } }
void MainFrame::OnLangOpenFolder(wxCommandEvent& WXUNUSED(event)) { wxString AppPoDir(wxGetCwd() + wxT("/po")); if(!wxDirExists(AppPoDir)){ etrace("po dir not found: %ls",AppPoDir.wc_str()); } else { if(!wxLaunchDefaultBrowser(AppPoDir)) Utils::ShowError(wxT("Cannot open %ls!"),AppPoDir.wc_str()); } }
/** * @brief Retrieves the detailed information * about a disk volume. * @param[in] volume_letter the volume letter. * @param[in,out] v pointer to structure * receiving the volume information. * @return Zero for success, negative * value otherwise. */ int winx_get_volume_information(char volume_letter,winx_volume_information *v) { HANDLE hRoot; /* check input data correctness */ if(v == NULL) return (-1); /* ensure that it will work on w2k */ volume_letter = winx_toupper(volume_letter); /* reset all fields of the structure, except of volume_letter */ memset(v,0,sizeof(winx_volume_information)); v->volume_letter = volume_letter; if(volume_letter < 'A' || volume_letter > 'Z') return (-1); /* open root directory */ hRoot = OpenRootDirectory(volume_letter); if(hRoot == NULL) return (-1); /* get drive geometry */ if(get_drive_geometry(hRoot,v) < 0){ NtClose(hRoot); return (-1); } /* get the name of contained file system */ if(get_filesystem_name(hRoot,v) < 0){ NtClose(hRoot); return (-1); } /* get name of the volume */ get_volume_label(hRoot,v); /* get NTFS data */ memset(&v->ntfs_data,0,sizeof(NTFS_DATA)); if(!strcmp(v->fs_name,"NTFS")){ if(get_ntfs_data(v) < 0){ etrace("NTFS data is unavailable for %c:", volume_letter); } } /* get dirty flag */ get_volume_dirty_flag(v); NtClose(hRoot); return 0; }
BOOL CUIGlobals::InitColorsAndTablesAndObjects(LPDICOLORSET lpDIColorSet) {tracescope(__ts,_T("CUIGlobals::InitColorsAndTablesAndObjects()\n")); // init ui tables if (!InitTables()) { etrace(_T("Could not initialize tables\n")); return FALSE; } // decide whether or not to use the passed colorset if (lpDIColorSet != NULL) { m_ColorSet = *lpDIColorSet; m_bUseColorSet = !IsZeroOrInvalidColorSet(m_ColorSet); } else m_bUseColorSet = FALSE; // use it, or use defaults if (m_bUseColorSet) { // transfer colors from passed colorset SetTableColor(UIC_TEXTFORE, D3DCOLOR2COLORREF(m_ColorSet.cTextFore)); SetTableColor(UIC_TEXTHIGHLIGHT, D3DCOLOR2COLORREF(m_ColorSet.cTextHighlight)); SetTableColor(UIC_CALLOUTLINE, D3DCOLOR2COLORREF(m_ColorSet.cCalloutLine)); SetTableColor(UIC_CALLOUTHIGHLIGHT, D3DCOLOR2COLORREF(m_ColorSet.cCalloutHighlight)); SetTableColor(UIC_BORDER, D3DCOLOR2COLORREF(m_ColorSet.cBorder)); SetTableColor(UIC_CONTROLFILL, D3DCOLOR2COLORREF(m_ColorSet.cControlFill)); SetTableColor(UIC_HIGHLIGHTFILL, D3DCOLOR2COLORREF(m_ColorSet.cHighlightFill)); SetTableColor(UIC_AREAFILL, D3DCOLOR2COLORREF(m_ColorSet.cAreaFill)); } else { // use default colors SetTableColor(UIC_TEXTFORE, RGB(255, 255, 255)); SetTableColor(UIC_TEXTHIGHLIGHT, RGB( 0, 255, 0)); SetTableColor(UIC_CALLOUTLINE, RGB(255, 255, 255)); SetTableColor(UIC_CALLOUTHIGHLIGHT, RGB( 0, 255, 0)); SetTableColor(UIC_BORDER, RGB(255, 255, 0)); SetTableColor(UIC_CONTROLFILL, RGB( 0, 191, 0)); SetTableColor(UIC_HIGHLIGHTFILL, RGB( 0, 0, 0)); SetTableColor(UIC_AREAFILL, RGB( 0, 0, 0)); } // create the table objects CreateObjects(); return TRUE; }
/** * @brief Retrieves free space layout. * @return Zero for success, negative value otherwise. */ static int get_free_space_layout(udefrag_job_parameters *jp) { char buffer[32]; jp->free_regions = winx_get_free_volume_regions(jp->volume_letter, WINX_GVR_ALLOW_PARTIAL_SCAN,process_free_region,(void *)jp); winx_bytes_to_hr(jp->v_info.free_bytes,2,buffer,sizeof(buffer)); itrace("free space amount : %s",buffer); itrace("free regions count: %u",jp->free_regions_count); /* let full disks to pass the analysis successfully */ if(jp->free_regions == NULL || jp->free_regions_count == 0) etrace("disk is full or some error has been encountered"); return 0; }
HRESULT CDeviceUI::Init(const DIDEVICEINSTANCEW &didi, LPDIRECTINPUTDEVICE8W lpDID, HWND hWnd, CDeviceUINotify *pNotify) {tracescope(__ts, _T("CDeviceUI::Init()...\n")); // save the params m_priv_didi = didi; m_priv_lpDID = lpDID; m_pNotify = pNotify; m_hWnd = hWnd; // fail if we don't have lpDID if (m_lpDID == NULL) { etrace(_T("CDeviceUI::Init() was passed a NULL lpDID!\n")); return E_FAIL; } // fill the devobjstruct HRESULT hr = FillDIDeviceObjectStruct(m_priv_os, lpDID); if (FAILED(hr)) { etrace1(_T("FillDIDeviceObjectStruct() failed, returning 0x%08x\n"), hr); return hr; } // view rect needs to be set before populating so the views are // created with the correct dimensions m_ViewRect = g_ViewRect; // populate hr = PopulateAppropriately(*this); if (FAILED(hr)) return hr; // if there are no views, return if (GetNumViews() < 1) { Unpopulate(); return E_FAIL; } // show the first view SetView(0); return hr; }
//better off with a struct to pass any variables we need IN. Such as: // drive_letter. query_type. File Path. (combine/variables set above) void *QueryThread::Entry() { int result; while(!g_mainFrame->CheckForTermination(200)){ if(m_startquery){ result = udefrag_start_query(m_letter,m_qType,m_flags,m_mapSize, reinterpret_cast<udefrag_progress_callback>(ProgressCallback), reinterpret_cast<udefrag_terminator>(Terminator),m_qp,NULL ); if(result < 0 && !g_mainFrame->m_stopped){ etrace("Disk Processing Failure."); g_mainFrame->WxTextCtrl1->AppendText(L"Error executing Query."); } PostCommandEvent(g_mainFrame,ID_QueryCompletion); m_startquery = false; } } return NULL; }
/** * @brief Adds file to the list of fragmented files. * @note Ignores files excluded from the disk processing. */ int expand_fragmented_files_list(winx_file_info *f,udefrag_job_parameters *jp) { void **p; /* don't include filtered out files, for better performance */ //genBTC asks: // Wouldnt this already be filtered out, since this is only called from: // Analyze.C, produce_list_of_fragmented_files() // and // Move.C, move_file() near the very end // and in both functions, they are called from inside this if block: // if(is_fragmented(f) && !is_excluded(f)){ // so they should already be verified by !is_exluded(f) //I guess this was put in for future expansion? //if(!is_excluded(f)){ p = prb_probe(jp->fragmented_files,(void *)f); if(*p != f) etrace("a duplicate found for %ws",f->path); //} return 0; }
/** * @internal * @brief Retrieves the volume dirty flag. * @param[out] pointer to the structure * receiving the volume dirty flag. */ static void get_volume_dirty_flag(winx_volume_information *v) { WINX_FILE *f; ULONG dirty_flag; int result; /* open the volume */ f = winx_vopen(v->volume_letter); if(f == NULL) return; /* get dirty flag */ result = winx_ioctl(f,FSCTL_IS_VOLUME_DIRTY, "get_volume_dirty_flag: dirty flag request", NULL,0,&dirty_flag,sizeof(ULONG),NULL); winx_fclose(f); if(result >= 0 && (dirty_flag & VOLUME_IS_DIRTY)){ etrace("%c: volume is dirty! Run CHKDSK to repair it.", v->volume_letter); v->is_dirty = 1; } }
/** * @brief Adds a file block to * the binary tree of all file blocks. * @return Zero for success, * negative value otherwise. * @note Destroys the tree in case of errors. */ int add_block_to_file_blocks_tree(udefrag_job_parameters *jp, winx_file_info *file, winx_blockmap *block) { struct file_block *fb; void **p; if(file == NULL || block == NULL) return (-1); if(jp->file_blocks == NULL) return (-1); fb = winx_malloc(sizeof *fb); fb->file = file; fb->block = block; p = prb_probe(jp->file_blocks,(void *)fb); /* if a duplicate item exists... */ if(*p != fb){ etrace("a duplicate found"); winx_free(fb); } return 0; }
/** * @brief Searches for the first movable file block * after the specified cluster on the volume. * @param[in] jp job parameters. * @param[in,out] min_lcn pointer to variable containing * minimum LCN - file blocks below it will be ignored. * @param[in] flags one of SKIP_xxx flags defined in udefrag.h * @param[out] first_file pointer to variable receiving information * about the file the first block belongs to. * @return Pointer to the first block. NULL indicates failure. */ winx_blockmap *find_first_block(udefrag_job_parameters *jp, ULONGLONG *min_lcn, int flags, winx_file_info **first_file) { winx_file_info *found_file; winx_blockmap *first_block; winx_blockmap b; struct file_block fb, *item; struct prb_traverser t; int movable_file; ULONGLONG tm = winx_xtime(); if(min_lcn == NULL || first_file == NULL) return NULL; found_file = NULL; first_block = NULL; b.lcn = *min_lcn; fb.block = &b; prb_t_init(&t,jp->file_blocks); item = prb_t_insert(&t,jp->file_blocks,&fb); if(item == &fb){ /* block at min_lcn not found */ item = prb_t_next(&t); if(prb_delete(jp->file_blocks,&fb) == NULL){ etrace("cannot remove block from the tree"); winx_flush_dbg_log(0); /* 'cause error is critical */ } } if(item){ found_file = item->file; first_block = item->block; } while(!jp->termination_router((void *)jp)){ if(found_file == NULL) break; if(flags & SKIP_PARTIALLY_MOVABLE_FILES){ movable_file = can_move_entirely(found_file,jp); } else { movable_file = can_move(found_file,jp); } if(is_file_locked(found_file,jp)) movable_file = 0; if(movable_file){ if(jp->is_fat && is_directory(found_file) && first_block == found_file->disp.blockmap){ /* skip first fragments of FAT directories */ } else { /* desired block found */ *min_lcn = first_block->lcn + 1; /* the current block will be skipped later anyway in this case */ *first_file = found_file; jp->p_counters.searching_time += winx_xtime() - tm; return first_block; } } /* skip current block */ *min_lcn = *min_lcn + 1; /* and go to the next one */ item = prb_t_next(&t); if(item == NULL) break; found_file = item->file; first_block = item->block; } *first_file = NULL; jp->p_counters.searching_time += winx_xtime() - tm; return NULL; }
/** * @brief Initializes main window. */ MainFrame::MainFrame() :wxFrame(NULL,wxID_ANY,wxT("UltraDefrag")) { g_mainFrame = this; m_vList = NULL; m_cMap = NULL; m_currentJob = NULL; m_busy = false; m_paused = false; // set main window icon SetIcons(wxICON(appicon)); // read configuration ReadAppConfiguration(); ProcessCommandEvent(ID_ReadUserPreferences); // set main window title wxString *instdir = new wxString(); //genBTC re-arranged the below, A LOT. wxStandardPaths stdpaths; wxFileName exepath(stdpaths.GetExecutablePath()); wxString cd = exepath.GetPath(); if((wxGetEnv(wxT("UD_INSTALL_DIR"),instdir))&&(cd.CmpNoCase(*instdir) == 0)) { itrace("current directory matches installation location, so it isn't portable"); itrace("installation location: %ls",instdir->wc_str()); m_title = new wxString(wxT(VERSIONINTITLE)); } else { itrace("current directory differs from installation location, so it is portable"); itrace("current directory: %ls",cd.wc_str()); wxSetEnv(wxT("UD_IS_PORTABLE"),wxT("1")); m_title = new wxString(wxT(VERSIONINTITLE_PORTABLE)); } //genBTC re-arranged the above, A LOT. ProcessCommandEvent(ID_SetWindowTitle); delete instdir; // set main window size and position SetSize(m_width,m_height); if(!m_saved){ CenterOnScreen(); GetPosition(&m_x,&m_y); } Move(m_x,m_y); if(m_maximized) Maximize(true); SetMinSize(wxSize(DPI(MAIN_WINDOW_MIN_WIDTH),DPI(MAIN_WINDOW_MIN_HEIGHT))); // create menu, tool and status bars InitMenu(); InitToolbar(); InitStatusBar(); //make sizer1 to hold the the tabbed "notebook". And make the notebook wxBoxSizer* bSizer1; bSizer1 = new wxBoxSizer( wxVERTICAL ); m_notebook1 = new wxNotebook( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 ); //make a panel inside the notebook to hold the m_splitter m_panel1 = new wxPanel( m_notebook1, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL ); // create list of volumes and cluster map (with splitter as parent) m_splitter = new wxSplitterWindow(m_panel1,wxID_ANY, wxDefaultPosition,wxDefaultSize, wxSP_3D | wxCLIP_CHILDREN); m_splitter->SetMinimumPaneSize(DPI(MIN_PANEL_HEIGHT)); m_vList = new DrivesList(m_splitter,wxLC_REPORT | wxLC_NO_SORT_HEADER | wxLC_HRULES | wxLC_VRULES | wxBORDER_NONE); m_cMap = new ClusterMap(m_splitter); m_splitter->SplitHorizontally(m_vList,m_cMap); int height = GetClientSize().GetHeight(); int maxPanelHeight = height - DPI(MIN_PANEL_HEIGHT) - m_splitter->GetSashSize(); if(m_separatorPosition < DPI(MIN_PANEL_HEIGHT)) m_separatorPosition = DPI(MIN_PANEL_HEIGHT); else if(m_separatorPosition > maxPanelHeight) m_separatorPosition = maxPanelHeight; m_splitter->SetSashPosition(m_separatorPosition); // update frame layout so we'll be able to initialize // list of volumes and cluster map properly wxSizeEvent evt(wxSize(m_width,m_height)); ProcessEvent(evt); m_splitter->UpdateSize(); InitVolList(); m_vList->SetFocus(); // populate list of volumes m_listThread = new ListThread(); //make sizer2 to Fit the splitter, and initialize it. wxBoxSizer* bSizer2; bSizer2 = new wxBoxSizer( wxVERTICAL ); bSizer2->Add( m_splitter, 1, wxEXPAND, 1 ); m_panel1->SetSizer( bSizer2 ); //Finish Tab1 - Add the Panel1(Splitter+sizer2) to the notebook. m_notebook1->AddPage( m_panel1, wxT("Drives"), false ); //make a 2nd panel inside the notebook to hold the 2nd page(a grid) m_panel2 = new wxPanel( m_notebook1, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL ); m_filesList = new FilesList(m_panel2,wxLC_REPORT /* | wxLC_SINGLE_SEL | wxLC_NO_SORT_HEADER*/ \ | wxLC_VIRTUAL | wxLC_HRULES | wxLC_VRULES | wxBORDER_NONE); InitFilesList(); //make sizer3 to Fit the page2list, and initialize it. wxBoxSizer* bSizer3; bSizer3 = new wxBoxSizer( wxVERTICAL ); bSizer3->Add( m_filesList, 1, wxEXPAND, 1 ); m_panel2->SetSizer( bSizer3 ); bSizer3->Fit( m_panel2 ); //Finish Tab 2 - Add the Panel2(page2list+sizer3) to the notebook. m_notebook1->AddPage( m_panel2, wxT("Files"), false ); //Finish Notebook & initialize bSizer1->Add( m_notebook1, 1, wxEXPAND, 1 ); this->SetSizer( bSizer1 ); // check the boot time defragmenter presence wxFileName btdFile(wxT("%SystemRoot%\\system32\\defrag_native.exe")); btdFile.Normalize(); bool btd = btdFile.FileExists(); m_menuBar->FindItem(ID_BootEnable)->Enable(btd); m_menuBar->FindItem(ID_BootScript)->Enable(btd); m_toolBar->EnableTool(ID_BootEnable,btd); m_toolBar->EnableTool(ID_BootScript,btd); if(btd && ::winx_bootex_check(L"defrag_native") > 0){ m_menuBar->FindItem(ID_BootEnable)->Check(true); m_toolBar->ToggleTool(ID_BootEnable,true); m_btdEnabled = true; } else { m_btdEnabled = false; } // launch threads for time consuming operations m_btdThread = btd ? new BtdThread() : NULL; m_configThread = new ConfigThread(); m_crashInfoThread = new CrashInfoThread(); wxConfigBase *cfg = wxConfigBase::Get(); int ulevel = (int)cfg->Read(wxT("/Upgrade/Level"),1); wxMenuItem *item = m_menuBar->FindItem(ID_HelpUpgradeNone + ulevel); if(item) item->Check(); m_upgradeThread = new UpgradeThread(ulevel); // set system tray icon m_systemTrayIcon = new SystemTrayIcon(); if(!m_systemTrayIcon->IsOk()){ etrace("system tray icon initialization failed"); wxSetEnv(wxT("UD_MINIMIZE_TO_SYSTEM_TRAY"),wxT("0")); } SetSystemTrayIcon(wxT("tray"),wxT("UltraDefrag")); // set localized text ProcessCommandEvent(ID_LocaleChange + g_locale->GetLanguage()); // allow disk processing m_jobThread = new JobThread(); //create query thread to perform queries without blocking the GUI //(sort of like jobs) - may not be good to have both possibly running at once. //Create Query Tab, Tab #3. InitQueryMenu(); UD_DisableTool(ID_Stop); //change stop icon to be not always enabled. }
/** * @brief A Win32 GetDriveType() native equivalent. * @param[in] letter the volume letter * @return The drive type, negative value indicates failure. */ int winx_get_drive_type(char letter) { wchar_t link_name[] = L"\\??\\A:"; #define MAX_TARGET_LENGTH 256 wchar_t link_target[MAX_TARGET_LENGTH]; PROCESS_DEVICEMAP_INFORMATION pdi; FILE_FS_DEVICE_INFORMATION ffdi; IO_STATUS_BLOCK iosb; NTSTATUS status; int drive_type; HANDLE hRoot; /* The additional checks for DFS were suggested by Stefan Pendl ([email protected]). */ /* DFS shares have DRIVE_NO_ROOT_DIR type though they are actually remote. */ letter = winx_toupper(letter); if(letter < 'A' || letter > 'Z'){ etrace("invalid letter %c",letter); return (-1); } /* check for the drive existence */ link_name[4] = (wchar_t)letter; if(winx_query_symbolic_link(link_name,link_target,MAX_TARGET_LENGTH) < 0) return (-1); /* check for an assignment made by subst command */ if(wcsstr(link_target,L"\\??\\") == (wchar_t *)link_target) return DRIVE_ASSIGNED_BY_SUBST_COMMAND; /* check for classical floppies */ if(wcsstr(link_target,L"Floppy")) return DRIVE_REMOVABLE; /* try to define exactly which type has the specified drive */ RtlZeroMemory(&pdi,sizeof(PROCESS_DEVICEMAP_INFORMATION)); status = NtQueryInformationProcess(NtCurrentProcess(), ProcessDeviceMap,&pdi, sizeof(PROCESS_DEVICEMAP_INFORMATION), NULL); if(NT_SUCCESS(status)){ drive_type = (int)pdi.Query.DriveType[letter - 'A']; /* * Type DRIVE_NO_ROOT_DIR have the following drives: * 1. assigned by subst command * 2. SCSI external drives * 3. RAID volumes * 4. DFS shares * We need additional checks to know exactly. */ if(drive_type != DRIVE_NO_ROOT_DIR) return drive_type; } else { strace(status,"cannot get device map"); return (-1); } /* try to define exactly again which type has the specified drive */ /* note that the drive motor can be powered on during this check */ hRoot = OpenRootDirectory(letter); if(hRoot == NULL) return (-1); RtlZeroMemory(&ffdi,sizeof(FILE_FS_DEVICE_INFORMATION)); status = NtQueryVolumeInformationFile(hRoot,&iosb, &ffdi,sizeof(FILE_FS_DEVICE_INFORMATION), FileFsDeviceInformation); NtClose(hRoot); if(!NT_SUCCESS(status)){ strace(status,"cannot get volume type for \'%c\'",letter); return (-1); } /* detect remote/cd/dvd/unknown drives */ if(ffdi.Characteristics & FILE_REMOTE_DEVICE) return DRIVE_REMOTE; switch(ffdi.DeviceType){ case FILE_DEVICE_CD_ROM: case FILE_DEVICE_CD_ROM_FILE_SYSTEM: case FILE_DEVICE_DVD: return DRIVE_CDROM; case FILE_DEVICE_NETWORK_FILE_SYSTEM: case FILE_DEVICE_NETWORK: /* ? */ case FILE_DEVICE_NETWORK_BROWSER: /* ? */ case FILE_DEVICE_DFS_FILE_SYSTEM: case FILE_DEVICE_DFS_VOLUME: case FILE_DEVICE_DFS: return DRIVE_REMOTE; case FILE_DEVICE_UNKNOWN: return DRIVE_UNKNOWN; } /* detect removable disks */ if(ffdi.Characteristics & FILE_REMOVABLE_MEDIA) return DRIVE_REMOVABLE; /* detect fixed disks */ switch(ffdi.DeviceType){ case FILE_DEVICE_DISK: case FILE_DEVICE_FILE_SYSTEM: /* ? */ /*case FILE_DEVICE_VIRTUAL_DISK:*/ /*case FILE_DEVICE_MASS_STORAGE:*/ case FILE_DEVICE_DISK_FILE_SYSTEM: return DRIVE_FIXED; default: break; } /* nothing detected => drive type is unknown */ return DRIVE_UNKNOWN; }
HRESULT CUIGlobals::Init(UIG_PARAMS_DEFINE) {tracescope(__ts,_T("CUIGlobals::Init(...)\n")); HRESULT hr = S_OK; // get instance handle m_hInst = (HINSTANCE)g_hModule; if (m_hInst == NULL) { etrace(_T("hInst NULL\n")); return E_FAIL; } // create direct input DWORD dwVer = DIRECTINPUT_VERSION; hr = DirectInput8Create(m_hInst, dwVer, IID_IDirectInput8W, (LPVOID *)&m_lpDI, NULL); if (FAILED(hr) || m_lpDI == NULL) { m_lpDI = NULL; etrace2(_T("Could not create DirectInput ver 0x%08x\n -> DirectInputCreateEx() returned 0x%08x\n"), dwVer, hr); return hr; } // save flags m_dwFlags = dwFlags; #ifdef CFGUI__FORCE_NON_NULL_WSZUSERNAMES if (wszUserNames == NULL) wszUserNames = _T("Forced Non-NULL Username"); #endif if (wszUserNames == NULL) { etrace(_T("wszUserNames was passed NULL\n")); return E_FAIL; } // save user names m_wszUserNames = DupSuperString(wszUserNames); if (m_wszUserNames == NULL) { etrace(_T("Could not duplicate user names\n")); return E_FAIL; } // make sure we were passed an action format if (lpAcFor == NULL) { etrace(_T("lpAcFor param NULL\n")); return E_INVALIDARG; } // copy the acfor to the master hr = InitMasterAcForArray(lpAcFor, int(dwNumAcFor)); if (FAILED(hr)) { etrace1(_T("InitMasterAcForArray() failed, returning 0x%08x\n"), hr); return hr; } // get surface if (lpSurface != NULL) { hr = lpSurface->QueryInterface(IID_IDirect3DSurface8, (void **)&m_pSurface3D); if (FAILED(hr) || m_pSurface3D == NULL) { m_pSurface3D = NULL; } hr = lpSurface->QueryInterface(IID_IDirectDrawSurface, (void **)&m_pSurface); if (FAILED(hr) || m_pSurface == NULL) { m_pSurface = NULL; } if (m_pSurface == NULL && m_pSurface3D == NULL) etrace(_T("lpSurface was non-NULL but could not get IDirect3DSurface8 or IID_IDirectDrawSurface from it")); } // save callback and ref data m_lpCallback = lpCallback; m_pvRefData = pvRefData; // see whether or not we're allowing edit layout mode m_bAllowEditLayout = IsEqualGUID(RefMasterAcFor(0).guidActionMap, GUID_DIConfigAppEditLayout); // init a bunch of stuff necessary for painting if (!InitColorsAndTablesAndObjects(lpDIColorSet)) return E_FAIL; // dump info if debug #ifdef DBG Dump(); #endif // return success if we got here return S_OK; }
/** * @brief Removes file from the list of fragmented files. */ void truncate_fragmented_files_list(winx_file_info *f,udefrag_job_parameters *jp) { if(!prb_delete(jp->fragmented_files,(void *)f)) etrace("%ws is not found in the tree",f->path); }
/** * @brief Retrieves all information about the volume. * @return Zero for success, negative value otherwise. * @note Resets statistics and cluster map. */ int get_volume_information(udefrag_job_parameters *jp) { char fs_name[MAX_FS_NAME_LENGTH + 1]; int i; /* reset mft zone disposition */ memset(&jp->mft_zone,0,sizeof(struct _mft_zone)); /* reset v_info structure */ memset(&jp->v_info,0,sizeof(winx_volume_information)); /* reset statistics */ jp->pi.files = 0; jp->pi.directories = 0; jp->pi.compressed = 0; jp->pi.fragmented = 0; jp->pi.fragments = 0; jp->pi.total_space = 0; jp->pi.free_space = 0; jp->pi.mft_size = 0; jp->pi.clusters_to_process = 0; jp->pi.processed_clusters = 0; jp->fs_type = FS_UNKNOWN; jp->is_fat = 0; /* reset file lists */ destroy_lists(jp); /* update global variables holding drive geometry */ if(winx_get_volume_information(jp->volume_letter,&jp->v_info) < 0) return (-1); /* don't touch dirty volumes */ if(jp->v_info.is_dirty) return UDEFRAG_DIRTY_VOLUME; jp->pi.total_space = jp->v_info.total_bytes; jp->pi.free_space = jp->v_info.free_bytes; itrace("total clusters: %I64u",jp->v_info.total_clusters); jp->pi.used_clusters = jp->v_info.total_clusters - (jp->v_info.free_bytes / jp->v_info.bytes_per_cluster); itrace("used clusters : %I64u",jp->pi.used_clusters); itrace("cluster size: %I64u",jp->v_info.bytes_per_cluster); /* validate geometry */ if(!jp->v_info.total_clusters || !jp->v_info.bytes_per_cluster){ etrace("wrong volume geometry detected"); return (-1); } adjust_move_at_once_parameter(jp); /* check partition type */ itrace("%s partition detected",jp->v_info.fs_name); strncpy(fs_name,jp->v_info.fs_name,MAX_FS_NAME_LENGTH); fs_name[MAX_FS_NAME_LENGTH] = 0; _strupr(fs_name); for(i = 0; fs_types[i].name; i++){ if(!strcmp(fs_name,fs_types[i].name)){ jp->fs_type = fs_types[i].type; jp->is_fat = fs_types[i].is_fat; break; } } if(jp->fs_type == FS_UNKNOWN){ etrace("file system type is not recognized"); etrace("type independent routines will be used to defragment it"); } jp->pi.clusters_to_process = jp->v_info.total_clusters; jp->pi.processed_clusters = 0; if(jp->udo.fragment_size_threshold){ if(jp->udo.fragment_size_threshold <= jp->v_info.bytes_per_cluster){ itrace("fragment size threshold is below the cluster size, so it will be ignored"); jp->udo.fragment_size_threshold = 0; } } /* reset cluster map */ reset_cluster_map(jp); return 0; }