Forgotten French translation for Fraginator lost on my HD
[reactos.git] / rosapps / applications / fraginator / ReportDialog.cpp
1 #include "ReportDialog.h"
2 #include "Unfrag.h"
3 #include "Fraginator.h"
4 #include "DriveVolume.h"
5 #include "Defragment.h"
6 #include "resource.h"
7
8
9 void SetReportInfo (HWND Dlg, DefragReport &Report, uint32 BytesDivisor, wchar_t *BytesUnits, bool Fractional)
10 {
11 wchar_t Text[1000];
12 wchar_t Text2[1000];
13 wchar_t Text3[1000];
14
15 memset (Text, 0, sizeof (Text));
16
17 // Volume name
18 SetDlgItemText (Dlg, IDC_DRIVELETTER, Report.RootPath.c_str());
19
20 // Volume label
21 SetDlgItemText (Dlg, IDC_VOLUMELABEL, Defrag->GetVolume().GetVolumeInfo().Name.c_str());
22
23 // Volume Serial
24 SetDlgItemText (Dlg, IDC_VOLUMESERIAL, Defrag->GetVolume().GetVolumeInfo().Serial.c_str());
25
26 // File System
27 SetDlgItemText (Dlg, IDC_FILESYSTEM, Defrag->GetVolume().GetVolumeInfo().FileSystem.c_str());
28
29 // DiskSizeBytes
30 if (Fractional)
31 {
32 swprintf (Text, L"%.2f %s", (double)(signed)(Report.DiskSizeBytes /
33 (BytesDivisor / 1024)) / 1024.0, BytesUnits);
34 }
35 else
36 {
37 AddCommas (Text, Report.DiskSizeBytes / BytesDivisor);
38 wcscat (Text, L" ");
39 wcscat (Text, BytesUnits);
40 }
41
42 SetDlgItemText (Dlg, IDC_DISKSIZEBYTES, Text);
43
44 // DiskFreeBytes
45 if (Fractional)
46 {
47 swprintf (Text, L"%.2f %s", (double)(signed)(Defrag->GetVolume().GetVolumeInfo().FreeBytes /
48 (BytesDivisor / 1024)) / 1024.0, BytesUnits);
49 }
50 else
51 {
52 AddCommas (Text, Defrag->GetVolume().GetVolumeInfo().FreeBytes / BytesDivisor);
53 wcscat (Text, L" ");
54 wcscat (Text, BytesUnits);
55 }
56 SetDlgItemText (Dlg, IDC_DISKFREEBYTES, Text);
57
58 // DiskSizeClusters
59 AddCommas (Text, Defrag->GetVolume().GetVolumeInfo().ClusterCount);
60 wcscat (Text, L" clusters");
61 SetDlgItemText (Dlg, IDC_DISKSIZECLUSTERS, Text);
62
63 // DiskClusterSize
64 swprintf (Text, L"%u bytes", Defrag->GetVolume().GetVolumeInfo().ClusterSize);
65 SetDlgItemText (Dlg, IDC_DISKCLUSTERSIZE, Text);
66
67 // DirsCount
68 AddCommas (Text, Report.DirsCount);
69 SetDlgItemText (Dlg, IDC_DIRSCOUNT, Text);
70
71 // FilesCount
72 AddCommas (Text, Report.FilesCount);
73 SetDlgItemText (Dlg, IDC_FILESCOUNT, Text);
74
75 // FilesFragged
76 swprintf (Text, L"(%.2f%%)", Report.PercentFragged);
77 AddCommas (Text2, Report.FraggedFiles.size());
78 swprintf (Text3, L"%s %s", Text, Text2);
79 SetDlgItemText (Dlg, IDC_FILESFRAGGED, Text3);
80
81 // Average Frags
82 swprintf (Text, L"%.2f", Report.AverageFragments);
83 SetDlgItemText (Dlg, IDC_AVERAGEFRAGS, Text);
84
85 // FilesSizeBytes
86 if (Fractional)
87 {
88 swprintf (Text, L"%.2f %s", (double)(signed)(Report.FilesSizeBytes /
89 (BytesDivisor / 1024)) / 1024.0, BytesUnits);
90 }
91 else
92 {
93 AddCommas (Text, Report.FilesSizeBytes / (uint64)BytesDivisor);
94 wcscat (Text, L" ");
95 wcscat (Text, BytesUnits);
96 }
97 SetDlgItemText (Dlg, IDC_FILESSIZEBYTES, Text);
98
99 // Files SizeOnDisk
100 if (Fractional)
101 {
102 swprintf (Text, L"%.2f %s", (double)(signed)((Report.FilesSizeBytes + Report.FilesSlackBytes) /
103 (BytesDivisor / 1024)) / 1024.0, BytesUnits);
104 }
105 else
106 {
107 AddCommas (Text, (Report.FilesSizeBytes + Report.FilesSlackBytes) / (uint64)BytesDivisor);
108 wcscat (Text, L" ");
109 wcscat (Text, BytesUnits);
110
111 }
112 SetDlgItemText (Dlg, IDC_FILESSIZEONDISK, Text);
113
114 // FilesSlackBytes
115 if (Fractional)
116 {
117 swprintf (Text, L"%.2f %s", (double)(signed)(Report.FilesSlackBytes /
118 (BytesDivisor / 1024)) / 1024.0, BytesUnits);
119 }
120 else
121 {
122 AddCommas (Text, Report.FilesSlackBytes / BytesDivisor);
123 wcscat (Text, L" ");
124 wcscat (Text, BytesUnits);
125 }
126 swprintf (Text2, L"(%.2f%%)", Report.PercentSlack);
127 swprintf (Text3, L"%s %s", Text2, Text);
128 SetDlgItemText (Dlg, IDC_FILESSLACKBYTES, Text3);
129
130 // Recommendation
131 bool PFRec = false; // Recommend based off percent fragged files?
132 bool AFRec = false; // Recommend based off average fragments per file?
133
134 if (Report.PercentFragged >= 5.0f)
135 PFRec = true;
136
137 if (Report.AverageFragments >= 1.1f)
138 AFRec = true;
139
140 wcscpy (Text, L"* ");
141
142 if (PFRec)
143 {
144 swprintf
145 (
146 Text2,
147 L"%.2f%% of the files on this volume are fragmented. ",
148 Report.PercentFragged
149 );
150
151 wcscat (Text, Text2);
152 }
153
154 if (AFRec)
155 {
156 swprintf
157 (
158 Text2,
159 L"The average fragments per file (%.2f) indicates a high degree of fragmentation. ",
160 Report.AverageFragments
161 );
162
163 wcscat (Text, Text2);
164 }
165
166 if (Report.PercentFragged < 5.0f && Report.AverageFragments < 1.1f)
167 swprintf (Text, L"* No defragmentation is necessary at this point.");
168 else
169 if (Report.PercentFragged < 15.0f && Report.AverageFragments < 1.3f)
170 wcscat (Text, L"It is recommended that you perform a Fast Defrag.");
171 else
172 wcscat (Text, L"It is recommended that you perform an Extensive Defrag.");
173
174 // Should we recommend a smaller cluster size?
175 if (Report.PercentSlack >= 10.0f)
176 {
177 swprintf
178 (
179 Text2,
180 L"\n* A large amount of disk space (%.2f%%) is being lost "
181 L"due to a large (%u bytes) cluster size. It is recommended "
182 L"that you use a disk utility such as Partition Magic to "
183 L"reduce the cluster size of this volume.",
184 Report.PercentSlack,
185 Defrag->GetVolume().GetVolumeInfo().ClusterSize
186 );
187
188 wcscat (Text, Text2);
189 }
190
191 SetDlgItemText (Dlg, IDC_RECOMMEND, Text);
192
193 return;
194 }
195
196
197 INT_PTR CALLBACK ReportDialogProc (HWND Dlg, UINT Msg, WPARAM WParam, LPARAM LParam)
198 {
199 switch (Msg)
200 {
201 case WM_INITDIALOG:
202 SetReportInfo (Dlg, Defrag->GetDefragReport (), 1, L"bytes", false);
203 return (1);
204
205 case WM_COMMAND:
206 switch (LOWORD(WParam))
207 {
208 case IDC_REPORTOK:
209 EndDialog (Dlg, 0);
210 return (1);
211
212 case IDC_GIGABYTES:
213 SetReportInfo (Dlg, Defrag->GetDefragReport (), 1024*1024*1024, L"GB", true);
214 return (1);
215
216 case IDC_MEGABYTES:
217 SetReportInfo (Dlg, Defrag->GetDefragReport (), 1024*1024, L"MB", false);
218 return (1);
219
220 case IDC_KILOBYTES:
221 SetReportInfo (Dlg, Defrag->GetDefragReport (), 1024, L"KB", false);
222 return (1);
223
224 case IDC_BYTES:
225 SetReportInfo (Dlg, Defrag->GetDefragReport (), 1, L"bytes", false);
226 return (1);
227 }
228 }
229
230 return (0);
231 }