Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 08/04/2012 in all areas

  1. abberration

    RAID Calculator

    I was using some online RAID calculators yesterday and thought it would be fun to program one in AutoIt. I did not find anyone else who created such a thing in the Example Scripts sections, this is my addition. I know there are more RAID classes, but I didn't want to muddy up the appearance with obsolete versions. I contemplated on leaving out RAID 6, but ultimately left it in. I have always struggled to understand how Return in a function worked, but I figured it out while writing this script. I compared the accuracy with the online calcs and this one seems to be spot on. Enjoy! #include <GUIConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> #include <GuiScrollBars.au3> ; Create main Gui $mainGui = GUICreate("RAID Calculator", 313, 215) $MenuItem1 = GUICtrlCreateMenu("File") $MenuItem2 = GUICtrlCreateMenuItem("Exit", $MenuItem1) $MenuItem3 = GUICtrlCreateMenu("Information") $MenuItem4 = GUICtrlCreateMenuItem("Learn About RAID", $MenuItem3) $MenuItem5 = GUICtrlCreateMenuItem("About", $MenuItem3) GUIStartGroup() $Label1 = GUICtrlCreateLabel("RAID Level", 16, 16, 87, 17) GUICtrlSetTip(-1, "Learn more about various RAID configurations in the Information menu.") $Radio1 = GUICtrlCreateRadio("RAID 0", 16, 40, 81, 17) $Radio2 = GUICtrlCreateRadio("RAID 1", 16, 64, 81, 17) $Radio3 = GUICtrlCreateRadio("RAID 5", 16, 88, 81, 17) GUICtrlSetState(-1, $GUI_CHECKED) $Radio4 = GUICtrlCreateRadio("RAID 6", 16, 112, 81, 17) $Radio5 = GUICtrlCreateRadio("RAID 10", 16, 136, 81, 17) $Radio6 = GUICtrlCreateRadio("RAID 50", 16, 160, 81, 17) $Label2 = GUICtrlCreateLabel("# Of Disks", 120, 16, 54, 17) GUICtrlSetTip(-1, "Must be 2 or greater." & @CRLF & "Some configurations " & @CRLF & "require more than 2.") $Input1 = GUICtrlCreateInput("", 120, 40, 57, 21) GUICtrlSetTip(-1, "Must be 2 or greater." & @CRLF & "Some configurations " & @CRLF & "require more than 2.") $Label3 = GUICtrlCreateLabel("Disk Size", 192, 16, 48, 17) GUICtrlSetTip(-1, "Use whole numbers such as:" & @CRLF & "500 GB, or 2 TB.") $Input2 = GUICtrlCreateInput("", 192, 40, 57, 21) GUICtrlSetTip(-1, "Use whole numbers such as:" & @CRLF & "500 GB or 2 TB.") GUIStartGroup() $Radio7 = GUICtrlCreateRadio("GB", 256, 16, 41, 17) $Radio8 = GUICtrlCreateRadio("TB", 256, 40, 41, 17) GUICtrlSetState(-1, $GUI_CHECKED) $Button1 = GUICtrlCreateButton("Calculate!", 216, 80, 75, 25, 0) $Label4 = GUICtrlCreateLabel("Your array will be:", 120, 112, 95, 17) $Label5 = GUICtrlCreateLabel("", 120, 136, 300, 17) $Label6 = GUICtrlCreateLabel("", 120, 160, 176, 17) GUISetState(@SW_SHOW) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 ; If Caclulate button is pressed, read all controls and pass values to the CalcSize function If GUICtrlRead($Radio1) = 1 Then $raidLevel = "0" ElseIf GUICtrlRead($Radio2) = 1 Then $raidLevel = "1" ElseIf GUICtrlRead($Radio3) = 1 Then $raidLevel = "5" ElseIf GUICtrlRead($Radio4) = 1 Then $raidLevel = "6" ElseIf GUICtrlRead($Radio5) = 1 Then $raidLevel = "10" Else $raidLevel = "50" EndIf If GUICtrlRead($Radio7) = 1 Then $GBTB = 0 Else $GBTB = 1 EndIf $numDisks = GUICtrlRead($Input1) $diskSize = GUICtrlRead($Input2) CalcSize($raidLevel, $GBTB, $numDisks, $diskSize) Case $MenuItem2 ; From the menu, exit the program Exit Case $MenuItem4 ; From the menu, open the Learn More About RAID tutorial LearnAboutRAID() Case $MenuItem5 ; From the menu, open the About Raid Calculator dialog box AboutRAIDCalc() EndSwitch WEnd Func CalcSize($raidLevel, $GBTB, $numDisks, $diskSize) ; The function that crunches the numbers Local $error ErrorCheck($raidLevel, $numDisks, $diskSize) ; Function to check for bad values If ErrorCheck($raidLevel, $numDisks, $diskSize) = 0 Then $1GB = 1073741824 ; The number necessary to convert whole disk size numbers into formatted disk sizes. Ex: 1 TB = .93 TB formatted. If $GBTB = 0 Then ; $GBTB is the variable for what was selected by user: GB or TB $formatted = ($diskSize * 1000000000) ; TB was selected Else $formatted = ($diskSize * 1000000000 * 1000) ; GB was selected EndIf Switch $raidLevel ; Maths for the various levels of RAID Case $raidLevel = 0 $ans = Round(($formatted * $numDisks), 2) Case $raidLevel = 1 $ans = Round(($formatted * $numDisks) / 2, 2) Case $raidLevel = 5 $ans = Round(($formatted * $numDisks) - $formatted, 2) Case $raidLevel = 6 $ans = Round(($formatted * $numDisks) - (2 * $formatted), 2) Case $raidLevel = 10 $ans = Round(($formatted * $numDisks / 2), 2) Case $raidLevel = 50 $ans = Round(($formatted * $numDisks) - (2 * $formatted) , 2) EndSwitch If $GBTB = 1 Then ; Depending on whether user chose GB or TB, the output answer is displayed $ans = $ans / 1000 GUICtrlSetData($Label5, $ans / 1000000000 & " TB (Unformatted)") GUICtrlSetData($Label6, Round($ans / $1GB, 2) & " TB (Formatted)") Else GUICtrlSetData($Label5, $ans / 1000000000 & " GB (Unformatted)") GUICtrlSetData($Label6, Round($ans / $1GB, 2) & " GB (Formatted)") EndIf Else EndIf EndFunc ;==>CalcSize Func ErrorCheck($raidLevel, $numDisks, $diskSize) ; Error checking Local $error = 0 GUICtrlSetData($Label5, "") ; This and next 3 lines resets previous data that may have been set. GUICtrlSetData($Label6, "") GUICtrlSetBkColor($Input1, 0xFFFFFF) GUICtrlSetBkColor($Input2, 0xFFFFFF) ; Begin checks for incorrect amount of disk drives If StringRegExp($numDisks, "[^0-9]") = 1 Then ; Checks for non-numbers in # of disks field GUICtrlSetData($Label5, "Error: Invalid character in") GUICtrlSetData($Label6, "the # Of Disks field.") GUICtrlSetBkColor($Input1, 0xFFFF00) $error = 1 ; These error levels are not currently being used; the returned values may be useful for future functionality. ElseIf StringRegExp($diskSize, "[^0-9]") = 1 Then ; Checks for non-numbers in # of disks field GUICtrlSetData($Label5, "Error: Invalid character in") GUICtrlSetData($Label6, "the RAID Level field.") GUICtrlSetBkColor($Input2, 0xFFFF00) $error = 2 ElseIf $diskSize < 1 Then ; Checks to see if anything is entered at all GUICtrlSetData($Label5, "Error: You did not enter anything") GUICtrlSetData($Label6, "in the RAID Level field.") GUICtrlSetBkColor($Input2, 0xFFFF00) $error = 3 ElseIf $numDisks < 2 Then ; Less than 2 drives GUICtrlSetData($Label5, "Error: You must have at leaset 2") GUICtrlSetData($Label6, "disk drives to create an array.") GUICtrlSetBkColor($Input1, 0xFFFF00) $error = 4 ElseIf $numDisks > 2 AND $raidLevel = 1 Then ; RAID 1 requires exactly 2 drives GUICtrlSetData($Label5, "Error: RAID 1 requires exactly 2 disk") GUICtrlSetData($Label6, "drives to create the array.") GUICtrlSetBkColor($Input1, 0xFFFF00) $error = 5 ElseIf $numDisks < 3 AND $raidLevel = 5 Then ; RAID 5 requires 3 or more drives GUICtrlSetData($Label5, "Error: RAID 5 requires a minimum of") GUICtrlSetData($Label6, "3 disk drives to create the array.") GUICtrlSetBkColor($Input1, 0xFFFF00) $error = 6 ElseIf $numDisks < 4 AND $raidLevel = 6 Then ; RAID 6 requires 4 or more drives GUICtrlSetData($Label5, "Error: RAID 6 requires a minimum of") GUICtrlSetData($Label6, "4 disk drives to create the array.") GUICtrlSetBkColor($Input1, 0xFFFF00) $error = 7 ElseIf $numDisks < 4 AND $raidLevel = 10 Then ; RAID 10 requires 4 or more drives GUICtrlSetData($Label5, "Error: RAID 10 requires a minimum of") GUICtrlSetData($Label6, "4 disk drives to create the array.") GUICtrlSetBkColor($Input1, 0xFFFF00) $error = 8 ElseIf $numDisks < 6 AND $raidLevel = 50 Then ; RAID 50 requires 6 or more drives GUICtrlSetData($Label5, "Error: RAID 10 requires a minimum of") GUICtrlSetData($Label6, "6 disk drives to create the array.") GUICtrlSetBkColor($Input1, 0xFFFF00) $error = 9 EndIf Return $error EndFunc Func LearnAboutRAID() ; The Learn More About RAID tutorial $Form2 = GUICreate("Learn More About RAID", 413, 298) $desc = "RAID 0 - Uses 2 or more striped disks for maximum disk space and maximum performance. This configuration has no redundancy and if any drive in the array fails, you will lose all of your data. Not recommended for storing important data." _ & @CRLF & @CRLF & "RAID 1 – Uses exactly two mirrored disks with little loss in performance. This configuration uses the most disk space for parity, leaving you with only half of the total hard drive space. It has redundancy, so you can lose up to one hard drive without losing data." _ & @CRLF & @CRLF & "RAID 5 - Uses 3 or more disks combined together with a slight loss in performance. This configuration uses the equivalency of one hard disk for parity. The more disks you use, the better ratio of usable hard disk space vs. parity space. It has redundancy, so you can lose up to one hard drive without losing any data." _ & @CRLF & @CRLF & "RAID 6 – Uses 4 or more disks combined together with little loss in performance. This configuration uses the equivalency of two hard disks for parity. The more disks you use, the better ratio of usable hard disk space vs. parity space. It has redundancy, so you can lose up to two hard drives without losing any data." _ & @CRLF & @CRLF & "RAID 10 (aka RAID 1+0) – Uses 4 or more disks in a combination of RAID 1 and RAID 0 with enhanced performance. This configuration uses the equivalency of half of all hard disks for parity. It creates RAID 1 blocks and stripes the data among them (that is the RAID 0 part of the name). It has redundancy, so you will not lose any data as long as you do not lose 2 drives in any of the RAID 1 blocks." _ & @CRLF & @CRLF & "RAID 50 (aka RAID 5+0) – Uses 6 or more disks in a combination of RAID 5 and RAID 0 with enhanced performance. This configuration uses the equivalency of two hard disks parity. It creates RAID 5 blocks and stripes the data among them (that is the RAID 0 part of the name). The more disks you use, the better ratio of usable hard disk space vs. parity space. It has redundancy, so you will not lose any data as long as you do not lose 2 drives in any of the RAID 5 blocks." _ & @CRLF & @CRLF & @CRLF & "Glossary of terms" _ & @CRLF & @CRLF & "Mirror: An exact copy of data." _ & @CRLF & @CRLF & "Parity: Data recovery information to rebuild data from lost hard disks." _ & @CRLF & @CRLF & "Redundancy: To have some kind of backup of data in case a hard drive fails." _ & @CRLF & @CRLF & "Stripe: To distribute data among 2 or more hard drives." $Edit1 = GUICtrlCreateEdit("", 14, 8, 385, 281, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL)) GUICtrlSetData(-1, $desc) GUICtrlSetState($Edit1, $GUI_FOCUS) GUISetState(@SW_SHOW) While 2 $nMsg2 = GUIGetMsg() Switch $nMsg2 Case $GUI_EVENT_CLOSE ; Exit the tutorial GUIDelete($Form2) ExitLoop EndSwitch WEnd EndFunc Func AboutRAIDCalc() ; The About dialog box $Form3 = GUICreate("About RAID Calculator", 324, 239) GUISetIcon("D:006.ico") $GroupBox1 = GUICtrlCreateGroup("", 8, 8, 305, 177) $Labela = GUICtrlCreateLabel("RAID Caclulator", 32, 24, 255, 40, $WS_GROUP) GUICtrlSetFont(-1, 24, 800, 2, "Arial") GUICtrlSetColor(-1, 0x800000) $Labelb = GUICtrlCreateLabel("Version 1.0", 128, 72, 57, 17, $WS_GROUP) $Labelc = GUICtrlCreateLabel("http://www.autoitscript.com", 32, 152, 136, 17, $WS_GROUP) GUICtrlSetColor(-1, 0x0000FF) GUICtrlSetCursor (-1, 0) $Labeld = GUICtrlCreateLabel("Program written in AutoIt scripting language", 32, 128, 220, 17, $WS_GROUP) GUICtrlCreateGroup("", -99, -99, 1, 1) $Buttona = GUICtrlCreateButton("&OK", 120, 200, 75, 25) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg3 = GUIGetMsg() Switch $nMsg3 Case $GUI_EVENT_CLOSE GUIDelete($Form3) ExitLoop Case $Labelc ; Opens the AutoIt website ShellExecute("http://www.autoitscript.com") Case $Buttona ; Exit the About dialog box GUIDelete($Form3) ExitLoop EndSwitch WEnd EndFunc ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;; Written by abberration ;;;;;; ;;;;; Aug 3, 2012 ;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    1 point
  2. And you would learn the basics that you are completely missing. Like what types are. What a stupid comment. You do not need IPC. You want IPC and you want to do it now now now instead of spending time learning to do things right. Every time I tried to do something I couldn't do I'd stop and learn all the intermediate steps. Not a single time did I stop to ask stupid questions about how to do something well beyond my experience level. I sat down with code and I experimented with it and learned how it worked. If I received compiler errors I looked those up until I understood what they actually meant and how to fix them (and avoid creating them in the first place). I do not like your attitude. It's not about learning, otherwise you would listen to somebody who's a self-taught programmer. Instead you just attempt to argue and justify why you want to do concepts that are miles above your head. This will not be your personal C++ support forum. If you post any thread asking for C++ help it will be locked and you may optionally may be disciplined by the moderator for ignoring what you have been explicitly told. If you are unwilling to learn C++ in a sensible fashion then go annoy some other forum with your inane questions.
    1 point
  3. Perhaps the joy of learning and / or doing? Like building your own: hot rod / house / guitar / anti-neighbor-cat taser / etc. when they are readily available. What is the point of doing those things?
    1 point
  4. Actually, it is. It shows a complete lack of critical thinking on your part. As I mentioned, the user doesn't even understand basic syntax so you provide said user with code that uses a magic C-style cast. That's a great example to teach somebody who already doesn't know what the fuck they're doing. Here's a little hint for you: People who use C-style casts do so because 1) They're writing C code (I forgive them); 2) Don't know what they are doing (I want them all to die horribly). I've had to fix stupid-ass bullshit garbage code related to idiotic use of C-style casts in C++. I've seen const cast away via C-style casting when that isn't the intent. Back to the critical thinking part, though. The fact that you are willing to provide somebody an example using C-style casts due to a lack of critical thinking on your part also reflects on your lack of thinking about the user's question. As I also mentioned, they aren't anywhere near needing to worry about IPC. They do not understand basic syntax or basic types. Yet you are happy to provide an example of how to achieve IPC? Why? Do you want yet another shitty programmer who doesn't know what the fuck they are doing releasing garbage code into the wild? You're not just teaching somebody to blow their own foot off. You're giving them an RPG and pointing them towards an apartment building and patting them on the back saying "have fun" as you run off cackling into the night. Stupid stupid stupid. I hope a C-style cast falls on you and breaks your face.
    1 point
  5. Jos

    If Then Else single line?

    Dog ate your helpfile?
    1 point
  6. Here's a little snippet to quickly sync your system clock with that of NIST. #cs--------------- Sync Time By Foxhound Public Domain #ce -------------- #RequireAdmin _set_time(_get_time()) Func _get_time() $central = "http://nist.time.gov/timezone.cgi?Central/d/-6" $eastern = "http://nist.time.gov/timezone.cgi?Eastern/d/-5" $data = BinaryToString(InetRead($central)) $regex = "\d{1,2}:\d{1,2}:\d{1,2}" $match = StringRegExp($data, $regex, 3) if not IsArray($match) Then return false Return $match[1] EndFunc ;==>_get_time Func _set_time($time) if NOT $time Then Exit RunWait(@ComSpec & " /c " & 'time ' & $time, "", @SW_HIDE) EndFunc ;==>_set_time EDIT: Uhhh... why is the forum injecting BBCode into my post? Someone should get to work fixing that :S
    1 point
×
×
  • Create New...