2 Copyright © 2003-2011, The AROS Development Team.
6 #include <exec/types.h>
7 #include <exec/memory.h>
8 #include <libraries/mui.h>
9 #include <utility/tagitem.h>
10 #include <utility/hooks.h>
11 #include <graphics/rastport.h>
12 #include <intuition/screens.h>
13 #include <intuition/intuition.h>
15 #include <proto/alib.h>
16 #include <proto/exec.h>
17 #include <proto/muimaster.h>
18 #include <proto/utility.h>
19 #include <proto/intuition.h>
20 #include <proto/dos.h>
21 #include <proto/graphics.h>
23 #include <aros/debug.h>
26 #include "../FS/packets.h"
27 #include "../FS/query.h"
30 #include "../FS/asmsupport.c"
37 #define APPNAME "SFSdefrag"
38 #define VERSION "sfsdefrag 0.1 (29.11.2005) ©AROS Dev Team"
40 #define MIN(x,y) ((x)<(y)?(x):(y))
41 #define MAX(x,y) ((x)>(y)?(x):(y))
43 const char version
[] = "$VER: " VERSION
"\n";
45 struct DefragmentStep
{
46 ULONG id
; // id of the step ("MOVE", "DONE" or 0)
47 ULONG length
; // length in longwords (can be 0)
48 ULONG data
[0]; // size of this array is determined by length.
59 struct Library
*MUIMasterBase
= NULL
;
60 struct UtilityBase
*UtilityBase
= NULL
;
65 if ((MUIMasterBase
=OpenLibrary("muimaster.library", 0)) != NULL
)
67 if ((UtilityBase
=(struct UtilityBase
*)OpenLibrary("utility.library", 0)) != NULL
)
71 CloseLibrary(MUIMasterBase
);
78 if (UtilityBase
!= NULL
)
79 CloseLibrary((struct Library
*)UtilityBase
);
81 if (MUIMasterBase
!= NULL
)
82 CloseLibrary(MUIMasterBase
);
88 void cleanup(CONST_STRPTR message
)
92 ShowError(NULL
, NULL
, message
, TRUE
);
101 Object
*MakeLabel(STRPTR str
)
103 return (MUI_MakeObject(MUIO_Label
, str
, 0));
106 IPTR
xget(Object
* obj
, ULONG attr
)
114 struct Hook select_hook
;
115 struct Hook start_hook
;
116 struct Hook stop_hook
;
117 struct Hook refresh_hook
;
123 struct DrawInfo
*dri
;
125 ULONG pen1
, pen2
, pen3
;
131 Object
*StartButton
, *StopButton
, *RefreshButton
;
134 void updateBitmap(ULONG first
, ULONG last
)
137 ULONG blck
= blocks_inone
;
139 for (cnt
=first
/blocks_inone
; cnt
<= (last
+blocks_inone
-1)/blocks_inone
; cnt
++)
145 if ((cnt
+1) * blocks_inone
> blocks_total
) blck
= blocks_total
- cnt
*blocks_inone
;
147 if (bmtstz(bitmap
, cnt
*blocks_inone
, blck
))
151 RectFill(rp
, x
, y
, x
+1, y
+1);
153 DoMethod(Bmp
, MUIM_Draw
);
156 void getDeviceData(STRPTR device
)
160 dl
=LockDosList(LDF_DEVICES
|LDF_READ
);
162 if((dl
=FindDosEntry(dl
,device
,LDF_DEVICES
))!=0)
164 struct TagItem tags
[] = {
165 { ASQ_TOTAL_BLOCKS
, 0},
171 UnLockDosList(LDF_DEVICES
|LDF_READ
);
173 if(DoPkt(mp
, ACTION_SFS_QUERY
, (SIPTR
)tags
, 0, 0, 0, 0)!=DOSFALSE
)
175 blocks_total
=tags
[0].ti_Data
;
176 blocks_inone
=(blocks_total
+ 19255)/19256;
177 bug("blocks_total=%d\nblocks_inone=%d\n",blocks_total
,blocks_inone
);
182 if ((bitmap
= AllocVec(blocks_total
/ 8 + 32, MEMF_CLEAR
))!=0)
184 if(DoPkt(mp
, ACTION_SFS_READ_BITMAP
, (SIPTR
)bitmap
, 0, blocks_total
, 0, 0)!=DOSFALSE
)
186 updateBitmap(0, blocks_total
);
192 UnLockDosList(LDF_DEVICES
|LDF_READ
);
195 AROS_UFH3(void, start_function
,
196 AROS_UFHA(struct Hook
*, h
, A0
),
197 AROS_UFHA(Object
*, object
, A2
),
198 AROS_UFHA(APTR
, msg
, A1
))
202 BOOL defragmented
= FALSE
;
204 set(StartButton
, MUIA_Disabled
, TRUE
);
205 set(RefreshButton
, MUIA_Disabled
, TRUE
);
206 set(StopButton
, MUIA_Disabled
, FALSE
);
207 set(DevList
, MUIA_Disabled
, TRUE
);
211 if(DoPkt(mp
, ACTION_SFS_DEFRAGMENT_INIT
, 0, 0, 0, 0, 0)!=DOSFALSE
)
214 ULONG clrlo
=blocks_total
,clrhi
=0;
215 ULONG setlo
=blocks_total
,sethi
=0;
217 if(DoPkt(mp
, ACTION_SFS_DEFRAGMENT_STEP
, (SIPTR
)steps
, 190, 0, 0, 0)!=DOSFALSE
)
219 struct DefragmentStep
*ds
=(struct DefragmentStep
*)steps
;
223 if(ds
->id
==AROS_BE2LONG(MAKE_ID('M','O','V','E')) && ds
->length
==3)
225 bmclr(bitmap
, (blocks_total
+31)/32, ds
->data
[2], ds
->data
[0]);
226 bmset(bitmap
, (blocks_total
+31)/32, ds
->data
[1], ds
->data
[0]);
228 clrlo
= MIN(clrlo
, ds
->data
[2]);
229 clrhi
= MAX(clrhi
, (ds
->data
[2]+ds
->data
[0]));
231 setlo
= MIN(setlo
, ds
->data
[1]);
232 sethi
= MAX(sethi
, (ds
->data
[1]+ds
->data
[0]));
235 else if(ds
->id
==AROS_BE2LONG(MAKE_ID('D','O','N','E')))
240 ds
=(struct DefragmentStep
*)((ULONG
*)ds
+ 2 + ds
->length
);
243 updateBitmap(clrlo
, clrhi
);
244 updateBitmap(setlo
, sethi
);
245 DoMethod(app
, MUIM_Application_NewInput
, (IPTR
)&sigs
);
246 }while(!stop_me
&& !defragmented
);
249 set(StartButton
, MUIA_Disabled
, FALSE
);
250 set(StopButton
, MUIA_Disabled
, TRUE
);
251 set(RefreshButton
, MUIA_Disabled
, FALSE
);
252 set(DevList
, MUIA_Disabled
, FALSE
);
257 AROS_UFH3(void, stop_function
,
258 AROS_UFHA(struct Hook
*, h
, A0
),
259 AROS_UFHA(Object
*, object
, A2
),
260 AROS_UFHA(APTR
, msg
, A1
))
269 AROS_UFH3(void, refresh_function
,
270 AROS_UFHA(struct Hook
*, h
, A0
),
271 AROS_UFHA(Object
*, object
, A2
),
272 AROS_UFHA(APTR
, msg
, A1
))
276 ULONG active
= xget(DevList
, MUIA_List_Active
);
278 if (active
!= MUIV_List_Active_Off
)
280 if(DoPkt(mp
, ACTION_SFS_READ_BITMAP
, (SIPTR
)bitmap
, 0, blocks_total
, 0, 0)!=DOSFALSE
)
282 updateBitmap(0, blocks_total
);
289 AROS_UFH3(void, select_function
,
290 AROS_UFHA(struct Hook
*, h
, A0
),
291 AROS_UFHA(Object
*, object
, A2
),
292 AROS_UFHA(APTR
, msg
, A1
))
296 ULONG active
= xget(object
, MUIA_List_Active
);
298 if (active
!= MUIV_List_Active_Off
)
301 DoMethod(object
, MUIM_List_GetEntry
, active
, (IPTR
)&name
);
306 RectFill(rp
, 0, 0, 497, 347);
308 set(StartButton
, MUIA_Disabled
, FALSE
);
309 set(RefreshButton
, MUIA_Disabled
, FALSE
);
314 set(StartButton
, MUIA_Disabled
, TRUE
);
315 set(RefreshButton
, MUIA_Disabled
, TRUE
);
326 app
= ApplicationObject
,
327 MUIA_Application_Title
, (IPTR
)APPNAME
,
328 MUIA_Application_Version
, (IPTR
)VERSION
,
329 MUIA_Application_Copyright
, (IPTR
)"© 2006, The AROS Development Team",
330 MUIA_Application_Author
, (IPTR
)"Michal Schulz",
331 MUIA_Application_Base
, (IPTR
)APPNAME
,
332 MUIA_Application_Description
, _(MSG_DESCRIPTION
),
334 SubWindow
, MainWindow
= WindowObject
,
335 MUIA_Window_Title
, _(MSG_DESCRIPTION
),
336 // MUIA_Window_Height, MUIV_Window_Height_Visible(50),
337 // MUIA_Window_Width, MUIV_Window_Width_Visible(60),
338 WindowContents
, HGroup
,
339 MUIA_Group_SameWidth
, FALSE
,
340 Child
, VGroup
, GroupFrameT(_(MSG_BITMAP
)),
341 Child
, Bmp
= BitmapObject
,
344 MUIA_Bitmap_Width
, 498,
345 MUIA_Bitmap_Height
, 348,
349 Child
, VGroup
, GroupFrameT(_(MSG_SELECTION
)),
350 Child
, DevList
= ListObject
,
352 // MUIA_List_AdjustWidth, TRUE,
356 Child
, RefreshButton
= MUI_MakeObject(MUIO_Button
, _(MSG_REFRESH
)),
357 Child
, StartButton
= MUI_MakeObject(MUIO_Button
, _(MSG_START
)),
358 Child
, StopButton
= MUI_MakeObject(MUIO_Button
, _(MSG_CANCEL
)),
360 End
, // WindowContents
362 End
; // ApplicationObject
366 /* Quit application if the windowclosegadget or the esc key is pressed. */
367 struct DosList
*dl
,*dll
;
369 dl
= LockDosList(LDF_READ
| LDF_DEVICES
);
371 while((dll
= NextDosEntry(dll
, LDF_DEVICES
)))
373 struct TagItem tags
[] = {
379 if(DoPkt(mp
, ACTION_SFS_QUERY
, (SIPTR
)tags
, 0, 0, 0, 0)!=DOSFALSE
)
382 name
= AROS_BSTR_ADDR(dll
->dol_Name
);
383 if(tags
[0].ti_Data
>= (1<<16) + 83)
384 DoMethod(DevList
, MUIM_List_InsertSingle
, name
, MUIV_List_Insert_Bottom
);
387 UnLockDosList(LDF_READ
| LDF_DEVICES
);
389 DoMethod(StartButton
, MUIM_Notify
, MUIA_Pressed
, FALSE
,
390 (IPTR
)app
, 3, MUIM_CallHook
, (IPTR
)&start_hook
);
392 DoMethod(StopButton
, MUIM_Notify
, MUIA_Pressed
, FALSE
,
393 (IPTR
)app
, 3, MUIM_CallHook
, (IPTR
)&stop_hook
);
395 DoMethod(RefreshButton
, MUIM_Notify
, MUIA_Pressed
, FALSE
,
396 (IPTR
)app
, 3, MUIM_CallHook
, (IPTR
)&refresh_hook
);
398 DoMethod(DevList
, MUIM_Notify
, MUIA_List_Active
, MUIV_EveryTime
,
399 (IPTR
)DevList
, 2, MUIM_CallHook
, (IPTR
)&select_hook
);
401 DoMethod(MainWindow
, MUIM_Notify
, MUIA_Window_CloseRequest
, TRUE
,
403 MUIM_Application_ReturnID
, MUIV_Application_ReturnID_Quit
);
405 set(StartButton
, MUIA_Disabled
, TRUE
);
406 set(StopButton
, MUIA_Disabled
, TRUE
);
407 set(RefreshButton
, MUIA_Disabled
, TRUE
);
418 while((LONG
) DoMethod(app
, MUIM_Application_NewInput
, (IPTR
)&sigs
) != MUIV_Application_ReturnID_Quit
)
427 int main(int argc
, char *argv
[])
429 select_hook
.h_Entry
= (APTR
)select_function
;
430 start_hook
.h_Entry
= (APTR
)start_function
;
431 stop_hook
.h_Entry
= (APTR
)stop_function
;
432 refresh_hook
.h_Entry
= (APTR
)refresh_function
;
440 set(MainWindow
, MUIA_Window_Open
, TRUE
);
442 struct Window
*window
= (struct Window
*)xget(MainWindow
, MUIA_Window_Window
);
444 bm
= AllocBitMap(500, 350,
445 GetBitMapAttr(window
->RPort
->BitMap
, BMA_DEPTH
), BMF_CLEAR
,
446 window
->RPort
->BitMap
);
447 rp
= CreateRastPort();
449 dri
= GetScreenDrawInfo(window
->WScreen
);
450 pen1
= dri
->dri_Pens
[BACKGROUNDPEN
];
451 pen2
= dri
->dri_Pens
[TEXTPEN
];
452 pen3
= dri
->dri_Pens
[SHINEPEN
];
453 FreeScreenDrawInfo(window
->WScreen
, dri
);
456 RectFill(rp
, 0, 0, 499, 349);
458 set(Bmp
, MUIA_Bitmap_Bitmap
, bm
);
459 DoMethod(Bmp
, MUIM_Draw
);
461 if(xget(MainWindow
, MUIA_Window_Open
))
469 set(MainWindow
, MUIA_Window_Open
, FALSE
);
478 Locale_Deinitialize();
481 } /* main(int argc, char *argv[]) */