; by Jautois 2008

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>

Global $pInputSerial
Global $sWinTitle = "Serial-Generator - Jautois v1.0"
Global $iPars[3] = [Random(111, 999, 1), Random(111, 999, 1), Random(111, 999, 1)], $iFSNA[4]
Global $sComboKeys[2] = ["HDD - Hard Drive Disk Serial", "Random Number"]
Global $sComboFuns[2] = ["_GenerateFSNFromHDD", "_GenerateFSNFromRandomNumber"]
Global $sTemp = ""
Global $iCurPars[4] = ["", $iPars[0], $iPars[1], $iPars[2]]

$hWindow = GUICreate($sWinTitle, 322, 170)
GUISetIcon("shell32.dll", -45)
$pInputSerial = GUICtrlCreateInput("", 8, 104, 305, 21)
$pButtonGenerate = GUICtrlCreateButton("Generate", 8, 128, 153, 33, 0)
$pLabelSeeder = GUICtrlCreateLabel("Seeder: " & $iPars[0] & " - " & $iPars[1] & " - " & $iPars[2], 8, 8, 200, 17)
$pCombo = GUICtrlCreateCombo("", 8, 80, 305, 25, BitOR($CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL))
For $i = 0 To UBound($sComboKeys) - 1
	$sTemp &= $sComboKeys[$i] & "|"
Next
GUICtrlSetData(-1, $sTemp)
Global $pCheckboxSeeder = GUICtrlCreateCheckbox("Seeder constant", 8, 32, 105, 17)
$pInputSerialNum = GUICtrlCreateInput("10", 75, 55, 73, 21)
$pCheckboxMSN = GUICtrlCreateCheckbox("Generate", 8, 56, 65, 17)
GUICtrlCreateLabel("Serials", 152, 59, 35, 17)
$pButtonInfo = GUICtrlCreateButton("Info", 240, 6, 73, 25)
GUISetState(@SW_SHOW)

While 1
	If GUICtrlRead($pCheckboxMSN) = 1 Then
		GUICtrlSetState($pCheckboxSeeder, $GUI_CHECKED)
	EndIf
	$nMsg = GUIGetMsg()
	Switch $nMsg
		Case $GUI_EVENT_CLOSE
			Exit
		Case $pButtonGenerate
			$sT = GUICtrlRead($pCombo)
			$iFunNum = _ArraySearch($sComboKeys, $sT)
			If $iFunNum <> -1 Then
				Call($sComboFuns[$iFunNum])
			Else
				MsgBox(16, "Info - Error", "Please select a Seedersource!")
			EndIf
		Case $pButtonInfo
			MsgBox(1, "Info", "Seeder - With these 3 numbers the serials were generated. They will later need to test the validity of the serials. Serials apply only to the incorporated seeder. " & @CRLF & @CRLF & "[Checkbox] Seeder constant - The Seeder remain constant to create several Serials manually.")
	EndSwitch
WEnd

Func _GenerateSerial($iSeed = 0, $iFiveDataSeed = 0, $iSevenDataSeed = 0, $iNineDataSeed = 0)
	Local $bDone, $iDataF, $iDataN, $iDataS

	If $iFiveDataSeed <= 2 Or $iSevenDataSeed <= 2 Or $iNineDataSeed <= 2 Then
		GUICtrlSetData($pInputSerial, "0000-0000-0000")
		MsgBox(16, "Info - Error", "Invalid Seeder Values!")
	Else
		$bDone = False
		$iDataF = ($iSeed * Random(2, 20, 1)) + 5
		Sleep(100)
		$iDataS = ($iSeed * Random(2, 20, 1)) + 7
		Sleep(100)
		$iDataN = ($iSeed * Random(2, 20, 1)) + 9

		While Not $bDone
			$bDone = True
			If Mod($iDataF, $iFiveDataSeed) <> 0 Then
				$iDataF = $iDataF - 1
				$bDone = False
			EndIf
			If Mod($iDataS, $iSevenDataSeed) <> 0 Then
				$iDataS = $iDataS - 1
				$bDone = False
			EndIf
			If Mod($iDataN, $iNineDataSeed) <> 0 Then
				$iDataN = $iDataN - 1
				$bDone = False
			EndIf
		WEnd
		$sSerial = $iDataF & "-" & $iDataS & "-" & $iDataN
		GUICtrlSetData($pInputSerial, $sSerial)
		Return $sSerial
	EndIf
EndFunc   ;==>_GenerateSerial

Func _GenerateFSNFromRandomNumber()
	$sSeederCatch = "Random Number"

	$iStateSeeder = GUICtrlRead($pCheckboxSeeder)
	$iStateMSN = GUICtrlRead($pCheckboxMSN)

	If $iStateMSN = 1 Then
		$iSerialsNum = GUICtrlRead($pInputSerialNum)
		If Int($iSerialsNum) <= 0 Then
			MsgBox(16, "Info - Error", "Not a valid entry!")
		Else
			$sPath = FileSaveDialog("Save Serials ...", @DesktopDir, "Text (*.txt)")
			If Not @error Then
				$sPath &= ".txt"
				For $i = 1 To 3
					$iFSNA[$i] = Random(111, 999, 1)
					$iCurPars[$i] = $iFSNA[$i]
				Next
				GUICtrlSetData($pLabelSeeder, "Seeder: " & $iFSNA[1] & " - " & $iFSNA[2] & " - " & $iFSNA[3])
			EndIf
			FileWriteLine($sPath, "Serials Created With " & $sWinTitle)
			FileWriteLine($sPath, "-------------")
			FileWriteLine($sPath, "Catched By: " & $sSeederCatch)
			FileWriteLine($sPath, "Seeder: " & $iCurPars[1] & " - " & $iCurPars[2] & " - " & $iCurPars[3])
			FileWriteLine($sPath, "-------------")
			FileWriteLine($sPath, "")
			ProgressOn("Generating " & $iSerialsNum & " Serials", "Serial 1 from 100", "0 %")
			$iTimer = TimerInit()
			For $i = 1 To $iSerialsNum
				$sTempSerial = _GenerateSerial(Random(999, 99999, 1), $iCurPars[1], $iCurPars[2], $iCurPars[3])
				ProgressSet(($i / $iSerialsNum) * 100, Round(($i / $iSerialsNum) * 100, 2) & " % - " & $i & "/" & $iSerialsNum, "Serial: " & $sTempSerial)
				FileWriteLine($sPath, $sTempSerial)
			Next
			ProgressOff()
			$iTimerDiff = TimerDiff($iTimer)
			FileWriteLine($sPath, "")
			FileWriteLine($sPath, "Created in: " & Round($iTimerDiff / 1000, 2) & " Seconds")
			MsgBox(64, "Info", "Serials generated successfully!")
			Run('explorer "' & $sPath & '"')
		EndIf
	Else
		If $iStateSeeder = 4 Then
			For $i = 1 To 3
				$iFSNA[$i] = Random(111, 999, 1)
				$iCurPars[$i] = $iFSNA[$i]
			Next
			GUICtrlSetData($pLabelSeeder, "Seeder: " & $iFSNA[1] & " - " & $iFSNA[2] & " - " & $iFSNA[3])
			_GenerateSerial(Random(999, 99999, 1), $iCurPars[1], $iCurPars[2], $iCurPars[3])
		Else
			_GenerateSerial(Random(999, 99999, 1), $iCurPars[1], $iCurPars[2], $iCurPars[3])
		EndIf
	EndIf

EndFunc   ;==>_GenerateFSNFromRandomNumber

Func _GenerateFSNFromHDD()
	Global $iHDD[1000], $z = 0, $iRandom, $sSeederCatch = "HDD"

	$iStateSeeder = GUICtrlRead($pCheckboxSeeder)
	$iStateMSN = GUICtrlRead($pCheckboxMSN)

	If $iStateMSN = 1 Then
		$iSerialsNum = GUICtrlRead($pInputSerialNum)
		If Int($iSerialsNum) <= 0 Then
			MsgBox(16, "Info - Error", "Not a valid entry!")
		Else
			$sPath = FileSaveDialog("Save Serials ...", @DesktopDir, "Text (*.txt)")
			If Not @error Then
				$sPath &= ".txt"
				$sHDDn = DriveGetDrive("all")
				If Not @error Then
					If $sHDDn[0] < 3 Then
						MsgBox(16, "Info - Error", "There must be at least 3 harddrives exist!")
					Else
						ReDim $iHDD[$sHDDn[0] + 1]
						For $i = 1 To $sHDDn[0]
							$iTemp = DriveGetSerial($sHDDn[$i])
							If $iTemp <> "" Then
								$iHDD[$i - $z] = $iTemp
							Else
								$z = $z + 1
								ReDim $iHDD[$sHDDn[0] + 1 - $z]
							EndIf
						Next
					EndIf
					For $i = 1 To 3
						$iFSNA[$i] = StringLeft($iHDD[Random(1, UBound($iHDD) - 1, 1)], 3)
						$iCurPars[$i] = $iFSNA[$i]
					Next
					GUICtrlSetData($pLabelSeeder, "Seeder: " & $iFSNA[1] & " - " & $iFSNA[2] & " - " & $iFSNA[3])
				EndIf
				FileWriteLine($sPath, "Serials Created With " & $sWinTitle)
				FileWriteLine($sPath, "-------------")
				FileWriteLine($sPath, "Catched By: " & $sSeederCatch)
				FileWriteLine($sPath, "Seeder: " & $iCurPars[1] & " - " & $iCurPars[2] & " - " & $iCurPars[3])
				FileWriteLine($sPath, "-------------")
				FileWriteLine($sPath, "")
				ProgressOn("Generating " & $iSerialsNum & " Serials", "", "0 %")
				$iTimer = TimerInit()
				For $i = 1 To $iSerialsNum
					$sTempSerial = _GenerateSerial(Random(999, 99999, 1), $iCurPars[1], $iCurPars[2], $iCurPars[3])
					ProgressSet(($i / $iSerialsNum) * 100, Round(($i / $iSerialsNum) * 100, 2) & " % - " & $i & "/" & $iSerialsNum, "Serial: " & $sTempSerial)
					FileWriteLine($sPath, $sTempSerial)
				Next
				ProgressOff()
				$iTimerDiff = TimerDiff($iTimer)
				FileWriteLine($sPath, "")
				FileWriteLine($sPath, "Created in: " & Round($iTimerDiff / 1000, 2) & " Seconds")
				MsgBox(64, "Info", "Serials generated successfully!")
				Run('explorer "' & $sPath & '"')
			EndIf
		EndIf
	Else
		If $iStateSeeder = 4 Then
			$sHDDn = DriveGetDrive("all")
			If Not @error Then
				If $sHDDn[0] < 3 Then
					MsgBox(16, "Info - Error", "There must be at least 3 harddrives exist!")
				Else
					ReDim $iHDD[$sHDDn[0] + 1]
					For $i = 1 To $sHDDn[0]
						$iTemp = DriveGetSerial($sHDDn[$i])
						If $iTemp <> "" Then
							$iHDD[$i - $z] = $iTemp
						Else
							$z = $z + 1
							ReDim $iHDD[$sHDDn[0] + 1 - $z]
						EndIf
					Next
				EndIf
				For $i = 1 To 3
					$iFSNA[$i] = StringLeft($iHDD[Random(1, UBound($iHDD) - 1, 1)], 3)
					$iCurPars[$i] = $iFSNA[$i]
				Next
				GUICtrlSetData($pLabelSeeder, "Seeder: " & $iFSNA[1] & " - " & $iFSNA[2] & " - " & $iFSNA[3])
				_GenerateSerial(Random(999, 99999, 1), $iCurPars[1], $iCurPars[2], $iCurPars[3])
			EndIf
		Else
			_GenerateSerial(Random(999, 99999, 1), $iCurPars[1], $iCurPars[2], $iCurPars[3])
		EndIf
	EndIf
EndFunc   ;==>_GenerateFSNFromHDD
