 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Oxalid
Joined: 07 Dec 2005 Posts: 5
|
Posted: Thu Jan 12, 2006 7:23 am Post subject: MyDrfrag script - comments please |
|
|
Howdy everyone. I'm new to scripting and have my first script at a point where I'm ready to release for comments.
I always wanted a way to defrag my drives and have my computer shut down when finished.
That way I can do more important things while my computer is defraging (like sleeping).
You can download the script here: MyDefrag
This script uses the WinXP command line defrag.exe, so this won't work with older versions (not sure about Win2000).
Also, the script uses the cb.exe utility to retrieve output from the command line, so if you don't have this program you
can get it here: cb.zip
Again, this is my first real attempt at a useful script, so I'm very interested in any constructive feedback.
I know I went overboard with the comments in the script, but that was more for my sake in learning the language,
rather then for the pros who browse these forums.
Thanks in advance to anyone who comments on it, and thanks to everyone I took ideas from in the forums. |
|
| Back to top |
|
 |
toralf
Joined: 31 Jan 2005 Posts: 3841 Location: Bremen, Germany
|
Posted: Thu Jan 12, 2006 9:23 am Post subject: |
|
|
Dear Oxalid,
I'm very impressed:
- The GUI is exellent
- the documentation in the code is fabulous
Very well done.
Here are my remarks:
If you would rewrite this | Code: | If SaveWinPos
{
WinGetPos, Xpos, Ypos,,, %MainTitle%
IniWrite, %Xpos%, %A_ScriptFullPath%, Settings, Xpos
IniWrite, %Ypos%, %A_ScriptFullPath%, Settings, Ypos
}
| to this | Code: | If SaveWinPos
{
WinGetPos, Xpos, Ypos,,, %MainTitle%
IniWrite, x%Xpos% y%Ypos%, %A_ScriptFullPath%, Settings, GuiPos
}
Else
{
IniDelete, %A_ScriptFullPath%, Settings , GuiPos
} | Then you can write for this line | Code: | IniRead, Xpos, %A_ScriptFullPath%, Settings, Xpos , 327
IniRead, Ypos, %A_ScriptFullPath%, Settings, Ypos , 369 | this | Code: | | IniRead, Xpos, %A_ScriptFullPath%, Settings, GuiPos, %A_Space% | and for this | Code: | If SaveWinPos
Gui, Show, x%Xpos% y%Ypos%, %MainTitle%
Else
Gui, Show, Center, %MainTitle%
| this | Code: | Gui, Show, %GuiPos%, %MainTitle%
| Center will be automatic if GuiPos is space
I would suggest to give the buttons of your GUI a v- and g-label. It helps to reas and search in the code and you could use doublicate labels but with different actions (even that it is not needed in this case). And you can make some buttons inactive at start up, e.g. the Defrag button, and activate him when the user has selected a drive.
You could rewrite this | Code: | If AnalyzeAfterDefrag
{
Menu, %A_ThisMenu%, Uncheck, %A_ThisMenuItem%
AnalyzeAfterDefrag := 0
}
Else
{
Menu, %A_ThisMenu%, Check, %A_ThisMenuItem%
AnalyzeAfterDefrag := 1
}
| to this | Code: | If AnalyzeAfterDefrag
Menu, %A_ThisMenu%, Uncheck, %A_ThisMenuItem%
Else
Menu, %A_ThisMenu%, Check, %A_ThisMenuItem%
AnalyzeAfterDefrag := not AnalyzeAfterDefrag
| etc for the other if statements
I would recommend to use a separate ini file instead of the code file itself. Then this script can be compiled to an exe. and you could FileInstall the cb.exe as well.
As a nice addition I would suggest to look for an icon form the shell32.dll and use that as an icon for your app.
That's it for now. A very nice script. _________________ Ciao
toralf  |
|
| Back to top |
|
 |
jballi
Joined: 01 Oct 2005 Posts: 385 Location: Texas, USA
|
Posted: Thu Jan 12, 2006 11:38 pm Post subject: |
|
|
1st of all, good job! A program that I will consider although I really like Sysinternal's contig program because you can defrag all drives at the same time.
2nd, everything toralf said, especially the part about pulling the ini out of the program. Here's the code I use to set the ini file name:
| Code: | StringLeft $ScriptName,A_ScriptName,instr(A_ScriptName,".",N,0)-1
$INIFile=%A_ScriptDir%\%$ScriptName%.ini |
Finally, the program is incorrectly identifying virtual drives (example: drives created via the DOS subst command) to defrag. I'm not sure how to exclude them but the degrag program does issue a "The volume identifier is not valid." message when you run it (analyze and defrag).
Them be my thoughts... |
|
| Back to top |
|
 |
toralf
Joined: 31 Jan 2005 Posts: 3841 Location: Bremen, Germany
|
Posted: Fri Jan 13, 2006 8:56 am Post subject: |
|
|
| jballi wrote: | Here's the code I use to set the ini file name:
| Code: | StringLeft $ScriptName,A_ScriptName,instr(A_ScriptName,".",N,0)-1
$INIFile=%A_ScriptDir%\%$ScriptName%.ini |
| Dear jballi,
I would recommend to use SplitPath, since the file name might have several dots in its name plus the one for the extention.
I generally just add a ".ini" to A_ScriptName. Then it may be myscript.ahk.ini or myscript.exe.ini _________________ Ciao
toralf  |
|
| Back to top |
|
 |
jballi
Joined: 01 Oct 2005 Posts: 385 Location: Texas, USA
|
Posted: Fri Jan 13, 2006 11:12 am Post subject: |
|
|
| toralf wrote: | | I would recommend to use SplitPath, since the file name might have several dots in its name plus the one for the extention. |
You are correct, oh wise one. Since A_ScriptName contains a complete path, SplitPath works just as good in this case. i.e.
| Code: | SplitPath, A_ScriptName,,,,$ScriptName
$INIFile=%A_ScriptDir%\%$ScriptName%.ini |
Since the instr is doing a reverse search for the "." character, it will return the same value in this case. For some reason, I didn't think to use the SplitPath command.
Personally, I like to use the ScriptNameNoExt.INI format when defining a configuration file because it is a bit more standardized (what the heck is standard?) and it allows me to use the same INI file regardless if the script is compiled or not.
Them be my thoughts. |
|
| Back to top |
|
 |
quatermass
Joined: 14 Dec 2005 Posts: 135
|
Posted: Tue Jan 31, 2006 2:41 pm Post subject: |
|
|
Very nice. But it doesn't do anything with Windows 2000....
I guess the defrag commandline options may be different. _________________ Stuart Halliday |
|
| Back to top |
|
 |
shekel2000
Joined: 06 Aug 2005 Posts: 3
|
Posted: Fri Apr 21, 2006 4:02 pm Post subject: Scheduling |
|
|
| Now only if you add scheduling options this would be perfect... |
|
| Back to top |
|
 |
PhiLho
Joined: 27 Dec 2005 Posts: 6721 Location: France (near Paris)
|
Posted: Fri Apr 21, 2006 4:12 pm Post subject: |
|
|
NT-like Windows have Scheduled Tasks in the Control Panel...
Plus you have lot of freewares able to schedule some task. _________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2") |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|