AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

MyDrfrag script - comments please

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Oxalid



Joined: 07 Dec 2005
Posts: 5

PostPosted: Thu Jan 12, 2006 7:23 am    Post subject: MyDrfrag script - comments please Reply with quote

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). Wink

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. Wink

Thanks in advance to anyone who comments on it, and thanks to everyone I took ideas from in the forums.
Back to top
View user's profile Send private message
toralf



Joined: 31 Jan 2005
Posts: 3841
Location: Bremen, Germany

PostPosted: Thu Jan 12, 2006 9:23 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
jballi



Joined: 01 Oct 2005
Posts: 385
Location: Texas, USA

PostPosted: Thu Jan 12, 2006 11:38 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
toralf



Joined: 31 Jan 2005
Posts: 3841
Location: Bremen, Germany

PostPosted: Fri Jan 13, 2006 8:56 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
jballi



Joined: 01 Oct 2005
Posts: 385
Location: Texas, USA

PostPosted: Fri Jan 13, 2006 11:12 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
quatermass



Joined: 14 Dec 2005
Posts: 135

PostPosted: Tue Jan 31, 2006 2:41 pm    Post subject: Reply with quote

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
View user's profile Send private message
shekel2000



Joined: 06 Aug 2005
Posts: 3

PostPosted: Fri Apr 21, 2006 4:02 pm    Post subject: Scheduling Reply with quote

Now only if you add scheduling options this would be perfect...
Back to top
View user's profile Send private message Send e-mail
PhiLho



Joined: 27 Dec 2005
Posts: 6721
Location: France (near Paris)

PostPosted: Fri Apr 21, 2006 4:12 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group