Advertisement
Guest User

Map Converter - Change Options Source Code

a guest
May 11th, 2015
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 11.29 KB | None | 0 0
  1. #include <File.au3>
  2. #include <GUIConstantsEx.au3>
  3. #include <EditConstants.au3>
  4. #include <ColorConstants.au3>
  5. #include <Array.au3>
  6. #include <StaticConstants.au3>
  7.  
  8. $dataDir = @ScriptDir&"\data"
  9. $errorLog = @ScriptDir&"\Change Options Error Log.txt"
  10.  
  11. $optionsFile = $dataDir&"\options.dat"
  12.  
  13. if Not FileExists($dataDir) Then
  14.    error("Missing dirctory '"&$dataDir&"'",1,True)
  15. EndIf
  16.  
  17. ;Vars
  18. $mapName = ""
  19. $FHFolder = ""
  20. $FHTerrainsFolder = ""
  21. $FHMapFile = ""
  22. $FHMapFolder = ""
  23. $FHObjectsFolder = ""
  24. $CopyObjectFiles = ""
  25. $OutputFolder = ""
  26. ;----
  27.  
  28. loadOptions()
  29.  
  30. $GuiWin = GUICreate("Options", 380, 300,-1,-1)
  31.  
  32. $mapnameLabel = GUICtrlCreateLabel("Map Name:", 5, 10, 90, 20)
  33. $mapnameInput = GUICtrlCreateInput($mapName, 100, 8, 200, 20,BitOR($ES_AUTOHSCROLL,$ES_READONLY))
  34.  
  35. $fhfolderLabel = GUICtrlCreateLabel("FH Folder:", 5, 32, 90, 20)
  36. $fhfolderInput = GUICtrlCreateInput($FHFolder, 100, 30, 200, 20,BitOR($ES_AUTOHSCROLL,$ES_READONLY))
  37. $fhfolderChange = GUICtrlCreateButton("Change",310, 30, 60, 20)
  38.  
  39. $fhterrainsfolderLabel = GUICtrlCreateLabel("FH Terrains Folder:", 5, 54, 90, 20)
  40. $fhterrainsfolderInput = GUICtrlCreateInput($FHTerrainsFolder, 100, 52, 200, 20,BitOR($ES_AUTOHSCROLL,$ES_READONLY))
  41. $fhterrainsfolderChange = GUICtrlCreateButton("Change",310, 52, 60, 20)
  42.  
  43. $fhmapfileLabel = GUICtrlCreateLabel("FH Map File:", 5, 76, 90, 20)
  44. $fhmapfileInput = GUICtrlCreateInput($FHMapFile, 100, 74, 200, 20,BitOR($ES_AUTOHSCROLL,$ES_READONLY))
  45. $fhmapfileChange = GUICtrlCreateButton("Change",310, 74, 60, 20)
  46.  
  47. $fhmapfolderLabel = GUICtrlCreateLabel("FH Map Folder:", 5, 98, 90, 20)
  48. $fhmapfolderInput = GUICtrlCreateInput($FHMapFolder, 100, 96, 200, 20,BitOR($ES_AUTOHSCROLL,$ES_READONLY))
  49. $fhmapfolderChange = GUICtrlCreateButton("Change",310, 96, 60, 20)
  50.  
  51. $fhobjectsfolderLabel = GUICtrlCreateLabel("FH Objects Folder:", 5, 120, 90, 20)
  52. $fhobjectsfolderInput = GUICtrlCreateInput($FHObjectsFolder, 100, 118, 200, 20,BitOR($ES_AUTOHSCROLL,$ES_READONLY))
  53. $fhobjectsfolderChange = GUICtrlCreateButton("Change",310, 118, 60, 20)
  54.  
  55. $outputfolderLabel = GUICtrlCreateLabel("Output Folder:", 5, 142, 90, 20)
  56. $outputfolderInput = GUICtrlCreateInput($OutputFolder, 100, 140, 200, 20,BitOR($ES_AUTOHSCROLL,$ES_READONLY))
  57. $outputfolderChange = GUICtrlCreateButton("Change",310, 140, 60, 20)
  58.  
  59. $copyobjectfilesInput = GUICtrlCreateCheckbox("Copy object files", 130, 165, 160, 20)
  60. GUICtrlSetState(-1,$GUI_DISABLE)
  61. GUICtrlSetFont(-1,12)
  62.  
  63. if $CopyObjectFiles == "1" Then
  64.    GUICtrlSetState($copyobjectfilesInput,$GUI_CHECKED)
  65. Else
  66.    GUICtrlSetState($copyobjectfilesInput,$GUI_UNCHECKED)
  67. EndIf
  68.  
  69. $autoCompleteButton = GUICtrlCreateButton("Auto Complete",55, 190, 130, 30)
  70. GUICtrlSetFont(-1,12)
  71.  
  72. $resetButton = GUICtrlCreateButton("Reset",200, 190, 130, 30)
  73. GUICtrlSetFont(-1,12)
  74.  
  75. $applyButton = GUICtrlCreateButton("Apply",130, 225, 130, 30)
  76. GUICtrlSetFont(-1,15)
  77.  
  78. $warningLabel = GUICtrlCreateLabel("Warning: Some options are missing and may cause problems when converting",20, 260, 350, 50,$SS_CENTER)
  79. GUICtrlSetFont(-1,10)
  80. GUICtrlSetColor(-1,$COLOR_RED)
  81. GUICtrlSetState($warningLabel,$GUI_HIDE)
  82.  
  83. updateCols()
  84.  
  85. GUISetState(@SW_SHOW)
  86. ;WinSetOnTop($GuiWin, "", 1)
  87. $lastName = ""
  88.  
  89. while 1
  90.    $msg = GUIGetMsg()
  91.    If $msg == $GUI_EVENT_CLOSE Then ExitLoop
  92.  
  93.    if $msg == $fhfolderChange Then
  94.       $newdir = FileSelectFolder("Folder:", "C:\",0,$FHFolder)
  95.       if $newdir == "" Then
  96.  
  97.       Else
  98.          $FHFolder = $newdir
  99.          GUICtrlSetData($fhfolderInput,$FHFolder)
  100.          updateCols()
  101.       EndIf
  102.    EndIf
  103.  
  104.    if $msg == $fhterrainsfolderChange Then
  105.       $newdir = FileSelectFolder("Folder:", "C:\",0,$FHTerrainsFolder)
  106.       if $newdir == "" Then
  107.  
  108.       Else
  109.          $FHTerrainsFolder = $newdir
  110.          GUICtrlSetData($fhterrainsfolderInput,$FHTerrainsFolder)
  111.          updateCols()
  112.       EndIf
  113.    EndIf
  114.  
  115.    if $msg == $fhmapfileChange Then
  116.       $newdir = FileOpenDialog("File:", $FHTerrainsFolder, "Map File (*.map*)")
  117.       if $newdir == "" Then
  118.  
  119.       Else
  120.          $FHMapFile = $newdir
  121.          GUICtrlSetData($fhmapfileInput,$FHMapFile)
  122.          Local $sDrive = "", $sDir = "", $sFilename = "", $sExtension = ""
  123.          _PathSplit($FHMapFile, $sDrive, $sDir, $sFilename, $sExtension)
  124.          if $sFilename == "" Then
  125.  
  126.          Else
  127.             $mapName = $sFilename
  128.             GUICtrlSetData($mapnameInput,$mapName)
  129.          EndIf
  130.          updateCols()
  131.       EndIf
  132.    EndIf
  133.  
  134.     if $msg == $fhmapfolderChange Then
  135.       $newdir = FileSelectFolder("Folder:", "C:\",0,$FHMapFolder)
  136.       if $newdir == "" Then
  137.  
  138.       Else
  139.          $FHMapFolder = $newdir
  140.          GUICtrlSetData($fhmapfolderInput,$FHMapFolder)
  141.          updateCols()
  142.       EndIf
  143.    EndIf
  144.  
  145.    if $msg == $fhobjectsfolderChange Then
  146.       $newdir = FileSelectFolder("Folder:", "C:\",0,$FHObjectsFolder)
  147.       if $newdir == "" Then
  148.  
  149.       Else
  150.          $FHObjectsFolder = $newdir
  151.          GUICtrlSetData($fhobjectsfolderInput,$FHObjectsFolder)
  152.          updateCols()
  153.       EndIf
  154.    EndIf
  155.  
  156.    if $msg == $outputfolderChange Then
  157.       if $OutputFolder == "" Then
  158.          $newdir = FileSelectFolder("Folder:", "C:\",0,@ScriptDir)
  159.       Else
  160.          $newdir = FileSelectFolder("Folder:", "C:\",0,$OutputFolder)
  161.       EndIf
  162.       if $newdir == "" Then
  163.  
  164.       Else
  165.          $OutputFolder = $newdir
  166.          GUICtrlSetData($outputfolderInput,$OutputFolder)
  167.          updateCols()
  168.       EndIf
  169.    EndIf
  170.  
  171.    if $msg == $autoCompleteButton Then
  172.       if FileExists($FHFolder) Then
  173.          ;if Not FileExists($FHTerrainsFolder) Then
  174.             if FileExists($FHFolder&"\media\terrains") Then
  175.                $FHTerrainsFolder = $FHFolder&"\media\terrains"
  176.             Else
  177.                If FileExists($FHFolder&"\terrains") Then
  178.                   $FHTerrainsFolder = $FHFolder&"\terrains"
  179.                EndIf
  180.             EndIf
  181.          ;EndIf
  182.          ;if Not FileExists($FHObjectsFolder) then
  183.             if FileExists($FHFolder&"\media\objects") Then
  184.                $FHObjectsFolder = $FHFolder&"\media\objects"
  185.             Else
  186.                If FileExists($FHFolder&"\objects") Then
  187.                   $FHObjectsFolder = $FHFolder&"\objects"
  188.                EndIf
  189.             EndIf
  190.          ;EndIf
  191.       EndIf
  192.       if $mapName == "" Then
  193.          if FileExists($FHMapFile) Then
  194.             Local $sDrive = "", $sDir = "", $sFilename = "", $sExtension = ""
  195.             _PathSplit($FHMapFile, $sDrive, $sDir, $sFilename, $sExtension)
  196.             if $sFilename == "" Then
  197.  
  198.             Else
  199.                $mapName = $sFilename
  200.             EndIf
  201.          EndIf
  202.       Else
  203.          if Not FileExists($FHMapFile) Then
  204.             if FileExists($FHTerrainsFolder) Then
  205.                if FileExists($FHTerrainsFolder&"\"&$mapName&".map") Then
  206.                   $FHMapFile = $FHTerrainsFolder&"\"&$mapName&".map"
  207.                EndIf
  208.             EndIf
  209.          EndIf
  210.       EndIf
  211.       ;if Not FileExists($FHMapFolder) Then
  212.          if $mapName == "" Then
  213.  
  214.          Else
  215.             if FileExists($FHTerrainsFolder&"\"&$mapName) Then
  216.                $FHMapFolder = $FHTerrainsFolder&"\"&$mapName
  217.             EndIf
  218.          EndIf
  219.       ;EndIf
  220.       GUICtrlSetData($mapnameInput,$mapName)
  221.       GUICtrlSetData($fhfolderInput,$FHFolder)
  222.       GUICtrlSetData($fhterrainsfolderInput,$FHTerrainsFolder)
  223.       GUICtrlSetData($fhmapfileInput,$FHMapFile)
  224.       GUICtrlSetData($fhmapfolderInput,$FHMapFolder)
  225.       GUICtrlSetData($fhobjectsfolderInput,$FHObjectsFolder)
  226.       GUICtrlSetData($outputfolderInput,$OutputFolder)
  227.       updateCols()
  228.    EndIf
  229.  
  230.    if $msg == $resetButton Then
  231.       $confirmReset = MsgBox(4,"Reset?", "Are you sure you want to reset all options?")
  232.       if $confirmReset == 6 Then
  233.          $mapName = ""
  234.          $FHFolder = ""
  235.          $FHTerrainsFolder = ""
  236.          $FHMapFile = ""
  237.          $FHMapFolder = ""
  238.          $FHObjectsFolder = ""
  239.          $CopyObjectFiles = ""
  240.          $OutputFolder = ""
  241.          GUICtrlSetData($mapnameInput,$mapName)
  242.          GUICtrlSetData($fhfolderInput,$FHFolder)
  243.          GUICtrlSetData($fhterrainsfolderInput,$FHTerrainsFolder)
  244.          GUICtrlSetData($fhmapfileInput,$FHMapFile)
  245.          GUICtrlSetData($fhmapfolderInput,$FHMapFolder)
  246.          GUICtrlSetData($fhobjectsfolderInput,$FHObjectsFolder)
  247.          GUICtrlSetData($outputfolderInput,$OutputFolder)
  248.          saveOptions()
  249.          MsgBox(0,"Reset","Options have been reset")
  250.       EndIf
  251.    EndIf
  252.  
  253.    if $msg = $applyButton Then
  254.       saveOptions()
  255.       Exit
  256.    EndIf
  257.    $mapName = GUICtrlRead($mapnameInput)
  258.    if $mapName == $lastName Then
  259.    Else
  260.       updateCols()
  261.    EndIf
  262.    $lastName = $mapName
  263.    Sleep(10)
  264. WEnd
  265.  
  266.  
  267.  
  268.  
  269.  
  270. func updateCols()
  271.    $mapName = GUICtrlRead($mapnameInput)
  272.    GUICtrlSetState($warningLabel,$GUI_HIDE)
  273.    if FileExists($FHFolder) Then
  274.       GUICtrlSetColor($fhfolderLabel,$COLOR_BLACK)
  275.    Else
  276.       GUICtrlSetColor($fhfolderLabel,$COLOR_RED)
  277.       GUICtrlSetState($warningLabel,$GUI_SHOW)
  278.  
  279.    EndIf
  280.  
  281.    if FileExists($FHTerrainsFolder) Then
  282.       GUICtrlSetColor($fhterrainsfolderLabel,$COLOR_BLACK)
  283.       if FileExists($FHTerrainsFolder&"\"&$mapName&".map") Then
  284.          GUICtrlSetColor($mapnameLabel,$COLOR_BLACK)
  285.       Else
  286.          GUICtrlSetColor($mapnameLabel,$COLOR_RED)
  287.          GUICtrlSetState($warningLabel,$GUI_SHOW)
  288.       EndIf
  289.    Else
  290.       GUICtrlSetColor($fhterrainsfolderLabel,$COLOR_RED)
  291.       GUICtrlSetState($warningLabel,$GUI_SHOW)
  292.    EndIf
  293.  
  294.    if FileExists($FHMapFile) Then
  295.       GUICtrlSetColor($fhmapfileLabel,$COLOR_BLACK)
  296.    Else
  297.       GUICtrlSetColor($fhmapfileLabel,$COLOR_RED)
  298.       GUICtrlSetState($warningLabel,$GUI_SHOW)
  299.    EndIf
  300.  
  301.    if FileExists($FHMapFolder) Then
  302.       GUICtrlSetColor($fhmapfolderLabel,$COLOR_BLACK)
  303.    Else
  304.       GUICtrlSetColor($fhmapfolderLabel,$COLOR_RED)
  305.       GUICtrlSetState($warningLabel,$GUI_SHOW)
  306.    EndIf
  307.  
  308.    if FileExists($FHObjectsFolder) Then
  309.       GUICtrlSetColor($fhobjectsfolderLabel,$COLOR_BLACK)
  310.    Else
  311.       GUICtrlSetColor($fhobjectsfolderLabel,$COLOR_RED)
  312.       GUICtrlSetState($warningLabel,$GUI_SHOW)
  313.    EndIf
  314.  
  315.    if FileExists($OutputFolder) Then
  316.       GUICtrlSetColor($outputfolderLabel,$COLOR_BLACK)
  317.    Else
  318.       GUICtrlSetColor($outputfolderLabel,$COLOR_RED)
  319.       GUICtrlSetState($warningLabel,$GUI_SHOW)
  320.    EndIf
  321. EndFunc
  322.  
  323. Func loadOptions()
  324.    if FileExists($optionsFile) Then
  325.       Local $ops
  326.       _FileReadToArray($optionsFile, $ops)
  327.       if UBound($ops) == 9 Then
  328.          $mapName = $ops[1]
  329.          $FHFolder = $ops[2]
  330.          $FHTerrainsFolder = $ops[3]
  331.          $FHMapFile = $ops[4]
  332.          $FHMapFolder = $ops[5]
  333.          $FHObjectsFolder = $ops[6]
  334.          $CopyObjectFiles = $ops[7]
  335.          $OutputFolder = $ops[8]
  336.          Return
  337.       EndIf
  338.    EndIf
  339.    $mapName = ""
  340.    $FHFolder = ""
  341.    $FHTerrainsFolder = ""
  342.    $FHMapFile = ""
  343.    $FHMapFolder = ""
  344.    $FHObjectsFolder = ""
  345.    $CopyObjectFiles = ""
  346.    $OutputFolder = ""
  347. EndFunc
  348.  
  349. Func saveOptions()
  350.    if FileExists($optionsFile) Then
  351.       FileDelete($optionsFile)
  352.    EndIf
  353.    FileWriteLine($optionsFile,$mapName)
  354.    FileWriteLine($optionsFile,$FHFolder)
  355.    FileWriteLine($optionsFile,$FHTerrainsFolder)
  356.    FileWriteLine($optionsFile,$FHMapFile)
  357.    FileWriteLine($optionsFile,$FHMapFolder)
  358.    FileWriteLine($optionsFile,$FHObjectsFolder)
  359.    if GUICtrlRead($copyobjectfilesInput) == $GUI_CHECKED Then
  360.       $CopyObjectFiles = "1"
  361.    Else
  362.       $CopyObjectFiles = ""
  363.    EndIf
  364.    FileWriteLine($optionsFile,$CopyObjectFiles)
  365.    FileWriteLine($optionsFile,$OutputFolder)
  366. EndFunc
  367.  
  368.  
  369. Func error($errorText,$errorNumber,$fatal)
  370.    ConsoleWrite("--Error--"&@CRLF)
  371.    ConsoleWrite($errorNumber&": "&$errorText&@CRLF)
  372.    ConsoleWrite("---------"&@CRLF)
  373.    if $fatal Then
  374.       MsgBox(0,"Fatal Error("&$errorNumber&")",$errorText)
  375.       FileWriteLine($errorLog, "["&@MDAY&"/"&@MON&"/"&@YEAR&" "&@HOUR&":"&@MIN&":"&@SEC&"] Fatal Error("&$errorNumber&"): "&$errorText) ;Notice how the date is in the format day/month/year, yay British errors!
  376.       Exit
  377.    Else
  378.       MsgBox(0,"Error("&$errorNumber&")",$errorText)
  379.       FileWriteLine($errorLog, "["&@MDAY&"/"&@MON&"/"&@YEAR&" "&@HOUR&":"&@MIN&":"&@SEC&"] Error("&$errorNumber&"): "&$errorText)
  380.    EndIf
  381. EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement