ReactOS 0.4.15-dev-7834-g00c4b3d
Unfrag.cpp File Reference
#include "Unfrag.h"
#include "DriveVolume.h"
#include "Defragment.h"
#include <process.h>
Include dependency graph for Unfrag.cpp:

Go to the source code of this file.

Functions

bool CheckWinVer (void)
 
wchar_tAddCommas (wchar_t *Result, uint64 Number)
 
void PrintBanner (void)
 
void FraggerHelp (void)
 
void __cdecl DefragThread (LPVOID parm)
 
DefragmentStartDefragThread (wstring Drive, DefragType Method, HANDLE &Handle)
 

Variables

bool QuietMode = false
 
bool VerboseMode = false
 

Function Documentation

◆ AddCommas()

wchar_t * AddCommas ( wchar_t Result,
uint64  Number 
)

Definition at line 48 of file Unfrag.cpp.

49{
50 wchar_t Temp[128];
51 int TempLen;
52 //wchar_t *p = NULL;
53 int AddCommas = 0;
54 wchar_t *StrPosResult = NULL;
55 wchar_t *StrPosOrig = NULL;
56
57 // we get the string form of the number, then we count down w/ AddCommas
58 // while copying the string from Temp1 to Result. when AddCommas % 3 == 1,
59 // slap in a commas as well, before the #.
60 swprintf (Temp, L"%I64u", Number);
61 AddCommas = TempLen = wcslen (Temp);
62 StrPosOrig = Temp;
63 StrPosResult = Result;
64 while (AddCommas)
65 {
66 if ((AddCommas % 3) == 0 && AddCommas != TempLen) // avoid stuff like ",345"
67 {
68 *StrPosResult = L',';
69 StrPosResult++;
70 }
71
72 *StrPosResult = *StrPosOrig;
73 StrPosResult++;
74 StrPosOrig++;
75
76 *StrPosResult = 0;
77
78 AddCommas--;
79 }
80
81 return (Result);
82}
wchar_t * AddCommas(wchar_t *Result, uint64 Number)
Definition: Unfrag.cpp:48
#define NULL
Definition: types.h:112
#define swprintf
Definition: precomp.h:40
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
_In_opt_ PENTER_STATE_SYSTEM_HANDLER _In_opt_ PVOID _In_ LONG _In_opt_ LONG volatile * Number
Definition: ntpoapi.h:207
#define L(x)
Definition: ntvdm.h:50
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:409

Referenced by AddCommas(), and SetReportInfo().

◆ CheckWinVer()

bool CheckWinVer ( void  )

Definition at line 19 of file Unfrag.cpp.

20{
21 OSVERSIONINFO OSVersion;
22
23 ZeroMemory (&OSVersion, sizeof (OSVersion));
24 OSVersion.dwOSVersionInfoSize = sizeof (OSVersion);
25 GetVersionEx (&OSVersion);
26
27 // Need Windows 2000!
28
29 // Check for NT first
30 // Actually what we do is check that weLL're not on Win31+Win32s and that we're
31 // not in Windows 9x. It's possible that there could be more Windows "platforms"
32 // in the future and there's no sense in claiming incompatibility.
33 if (OSVersion.dwPlatformId == VER_PLATFORM_WIN32s ||
35 {
36 return (false);
37 }
38
39 // Ok weLL're in Windows NT, now make sure we're in 2000
40 if (OSVersion.dwMajorVersion < 5)
41 return (false);
42
43 // Kew, we're in at least Windows 2000 ("NT 5.0")
44 return (true);
45}
#define VER_PLATFORM_WIN32_WINDOWS
Definition: rtltypes.h:237
#define VER_PLATFORM_WIN32s
Definition: rtltypes.h:236
ULONG dwPlatformId
Definition: rtltypes.h:241
ULONG dwOSVersionInfoSize
Definition: rtltypes.h:237
ULONG dwMajorVersion
Definition: rtltypes.h:238
#define ZeroMemory
Definition: winbase.h:1712
#define GetVersionEx
Definition: winbase.h:3787

Referenced by FraggerHelp(), and wWinMain().

◆ DefragThread()

void __cdecl DefragThread ( LPVOID  parm)

Definition at line 120 of file Unfrag.cpp.

121{
123
124 Defrag = (Defragment *) parm;
125 Defrag->Start ();
126
127 _endthread ();
128 return;
129}
Defragment * Defrag
Definition: Fraginator.cpp:20
void Start(void)
Definition: Defragment.cpp:157
_CRTIMP void __cdecl _endthread(void)
Definition: thread.c:95

Referenced by StartDefragThread().

◆ FraggerHelp()

void FraggerHelp ( void  )

Definition at line 95 of file Unfrag.cpp.

96{
97 wprintf (L"Usage: unfrag drive: [...] <-f | -e>\n");
98 wprintf (L"\n");
99 wprintf (L"drive: : The drive to defrag. Should be two characters long, ie 'c:' or 'd:'.\n");
100 wprintf (L" Multiple drives may be given, and all will be simultaneously\n");
101 wprintf (L" defragmented using the same options.\n");
102 wprintf (L"-f : Do a fast defragmentation. Files that are not fragmented will not be\n");
103 wprintf (L" moved. Only one pass is made over the file list. Using this option\n");
104 wprintf (L" may result in not all files being defragmented, depending on\n");
105 wprintf (L" available disk space.\n");
106 wprintf (L"-e : Do an extensive defragmention. Files will be moved in an attempt to\n");
107 wprintf (L" defragment both files and free space.\n");
108
109 if (!CheckWinVer())
110 {
111 wprintf (L"\n");
112 wprintf (L"NOTE: This program requires Windows 2000, which is not presently running on\n");
113 wprintf (L"this system.\n");
114 }
115
116 return;
117}
bool CheckWinVer(void)
Definition: Unfrag.cpp:19
#define wprintf(...)
Definition: whoami.c:18

◆ PrintBanner()

void PrintBanner ( void  )

Definition at line 85 of file Unfrag.cpp.

86{
87 wprintf (L"%s v%s\n", APPNAME_CLI, APPVER_STR);
88 wprintf (L"%s\n", APPCOPYRIGHT);
89 wprintf (L"\n");
90
91 return;
92}
#define APPVER_STR
Definition: Unfrag.h:40
#define APPCOPYRIGHT
Definition: Unfrag.h:43
#define APPNAME_CLI
Definition: Unfrag.h:38

Referenced by PrintLicense(), and PrintSynopsys().

◆ StartDefragThread()

Defragment * StartDefragThread ( wstring  Drive,
DefragType  Method,
HANDLE Handle 
)

Definition at line 132 of file Unfrag.cpp.

133{
134 Defragment *Defragger;
135 unsigned long Thread;
136
137 Defragger = new Defragment (Drive, Method);
138 //Thread = /*CreateThread*/ _beginthreadex (NULL, 0, DefragThread, Defragger, 0, &ThreadID);
139 Thread = _beginthread (DefragThread, 0, Defragger);
140 Handle = *((HANDLE *)&Thread);
141 return (Defragger);
142}
void __cdecl DefragThread(LPVOID parm)
Definition: Unfrag.cpp:120
PWCHAR Drive
Definition: chkdsk.c:73
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
ULONG Handle
Definition: gdb_input.c:15
_CRTIMP uintptr_t __cdecl _beginthread(_In_ void(__cdecl *_StartAddress)(void *), _In_ unsigned _StackSize, _In_opt_ void *_ArgList)

Referenced by MainDialogProc().

Variable Documentation

◆ QuietMode

bool QuietMode = false

Definition at line 14 of file Unfrag.cpp.

◆ VerboseMode

bool VerboseMode = false

Definition at line 15 of file Unfrag.cpp.