Advertisement
recca062

Server Config Editor

Mar 9th, 2017
1,101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
  2. ; #Warn  ; Enable warnings to assist with detecting common errors.
  3. SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
  4. SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
  5. #SingleInstance Force
  6. OnExit,OnExit
  7. MYAPP_PROTOCOL:="myapp"
  8. Note_1 = Value is a config switch (on/off, yes/no or 1/0)
  9. Note_2 = Value is in percents (100 means 100`%)
  10. Note_3 = Value is a bit field. If no description is given, assume unit<br>types (1: Pc, 2: Mob, 4: Pet, 8: Homun,16: Mercenary)
  11. HTML_header =
  12. ( Ltrim Join
  13. <!DOCTYPE html>
  14. <html>
  15.     <head>
  16.         <style>
  17.             body {
  18.                 background-color: #ccddff;
  19.             }
  20.         /* TOOL TIP*/
  21. .tooltip {
  22.     position: relative;
  23.     display: inline-block;
  24.     border-bottom: 2px dotted black;
  25. }
  26.  
  27. .tooltip .tooltiptext {
  28.     visibility: hidden;
  29.     width: 300px;
  30.     background-color: #4F4D50;
  31.     color: #fff;
  32.     text-align: left;
  33.     border-radius: 6px;
  34.     padding: 10px 10px;
  35.  
  36.     /* Position the tooltip */
  37.     position: absolute;
  38.     z-index: 1;
  39. }
  40.  
  41. .tooltip:hover .tooltiptext {
  42.     visibility: visible;
  43. }
  44.         </style>
  45.     </head>
  46.     <body>
  47. )
  48. HTML_footer =
  49. ( Ltrim Join
  50.     </body>
  51. </html>
  52. )
  53.  
  54. Gui, Add, Text, x10 y15, Config path
  55. Gui, Add, Edit, yp-2 xp+60 w400 h20 +ReadOnly vpath
  56. Gui, Add, Button, xp+410 yp w70 h20 gBrowse, Browse
  57. Gui, Add, Button, xp+75 yp wp h20 gOpen, Open
  58. Gui, Add, Button, x20 y710 w660 h30 gUpdate, UPDATE
  59. Gui Add, ActiveX, x0 y50 w700 h650 vWB, Shell.Explorer  ; The final parameter is the name of the ActiveX component.
  60. WB.silent := true ;Surpress JS Error boxese)
  61.  
  62. Gui, +Alwaysontop
  63. Gui Show, w700 h750
  64. return
  65.  
  66. Open:
  67. Run %path%
  68. return
  69.  
  70. Browse:
  71. Gui, +OwnDialogs
  72. FileSelectFile, path,
  73. If ErrorLevel
  74.     return
  75. GuiControl,, path, %path%
  76. StringSplit, temp_, path, \
  77. filename := temp_%temp_0%
  78. Load_Conf(path,filename)
  79. Display(WB,HTML_page)
  80. while WB.readystate != 4 or WB.busy
  81.     sleep 10
  82. ;Update := wb.document.getElementById("Update")
  83. ;ComObjConnect(Update, "Update_")
  84. return
  85.  
  86. GuiClose:
  87. ExitApp
  88.  
  89. OnExit:
  90.     FileDelete,%A_Temp%\*.DELETEME.html ;clean tmp file
  91. ExitApp
  92. return
  93.  
  94. Update:
  95. Update_OnClick()
  96. return
  97.  
  98. Update_OnClick() {
  99.     global var_ToContent, wb, path
  100.     Gui, submit, nohide
  101.     ;FileRead, FileData,%path%
  102.     Gui, +OwnDialogs
  103.     Loop, read, %path%
  104.     {
  105.         found = 0
  106.         Loop, parse, var_ToContent, |
  107.         {
  108.             ;MsgBox % A_LoopField
  109.             StringSplit, var_Temp_, A_LoopField, `,
  110.             IfInString, A_LoopReadLine, %A_Tab%%var_Temp_2%:
  111.             {
  112.                 var_Temp_3 := wb.Document.getElementById("conf_" var_Temp_1).Value
  113.                 found = 1
  114.                 StringSplit, temp_Line_, A_LoopReadLine, :
  115.                 FileData = %FileData%%temp_Line_1%: %var_Temp_3%`n
  116.                 break
  117.             }
  118.         }
  119.         if found = 0
  120.             FileData = %FileData%%A_LoopReadLine%`n
  121.     }
  122.     ;Loop, parse, var_ToContent, |
  123.     ;{
  124.     ;   StringSplit, var_Temp_, A_LoopField, `,
  125.        ;MsgBox % var_Temp_2
  126.         ;var_Temp_3 := wb.Document.getElementById("conf_" var_Temp_1).Value
  127.      ;   StringSplit, tempo_, var_Temp_2, :
  128.         ;conf_%var_Temp_1% = %tempo_1%: %var_Temp_3%
  129.         ;Gui, +OwnDialogs
  130.         ;MsgBox, % conf_%A_Index%
  131.       ;  MsgBox StringReplace, FileData, FileData, %var_Temp_2%, %tempo_1%: %var_Temp_3%
  132.     ;}
  133.     FileDelete, %path%
  134.     FileAppend, %FileData%, %path%
  135.     MsgBox, 64, Update, Done !
  136. }
  137.  
  138. Load_Conf(path,header) {
  139.     global HTML_page,HTML_header,HTML_footer,var_ToContent, path_trunk, Note_1, Note_2,Note_3
  140.     var_ToContent=
  141.     HTML_body =
  142.     (Ltrim Join
  143.         <table BORDER=4 CELLSPACING=4 CELLPADDING=4 style="border: 1px solid black; width: 200px;"  bgcolor="ffffff">
  144.         <tr>
  145.             <th colspan="2">%header%</th>
  146.         </tr>
  147.     )
  148.  
  149.     Loop, read, %path%
  150.     {
  151.         ; LINES TO SKIP
  152.         IfInString, A_LoopReadLine, import
  153.             continue
  154.         IfInString, A_LoopReadLine, %A_Tab%amount:
  155.             continue
  156.         IfInString, A_LoopReadLine, %A_Tab%loc:
  157.             continue
  158.         IfInString, A_LoopReadLine, %A_tab%id:
  159.             continue
  160.         IfInString, A_LoopReadLine, %A_Tab%stackable:
  161.             continue
  162.         IfInString, A_LoopReadLine, player: `{
  163.             continue
  164.         IfInString, A_LoopReadLine, new: `{
  165.             continue
  166.         ; SUB-HEADER
  167.         IfInString, A_LoopReadLine,:%A_Space%`{
  168.         {
  169.             StringTrimRight, LoopReadLine, A_LoopReadLine, 3
  170.             HTML_body =
  171.             ( Ltrim Join
  172.             %HTML_body%
  173.             <tr>
  174.                 <td colspan="2">%LoopReadLine%</th>
  175.             </tr>
  176.             )
  177.         }
  178.         StringReplace, LoopReadLine, A_LoopReadLine, %A_Tab%,,all
  179.         StringLeft, temp_Line, LoopReadLine, 2
  180.         ; IF LINE START WITH //
  181.         if (temp_Line != "//")
  182.             IfNotInString, A_LoopReadLine, `{
  183.                 IfNotInString, A_LoopReadLine, (
  184.                     IfInString, A_LoopReadLine, :%A_Space%
  185.                     {
  186.                         var_Index++
  187.                         A_CurrLine := A_index
  188.                         line_count := A_Index -1
  189.                         Loop
  190.                         {
  191.                             FileReadLine, line_data, %path%, line_count
  192.                             ; EXCEPTION
  193.                             IfInString, line_data, //
  194.                                 line_count--
  195.                             else IfInString, line_data, start_point
  196.                                 line_count--
  197.                             else IfInString, line_data, fame
  198.                                 line_count--
  199.                             else
  200.                                 break
  201.                         }
  202.                         Loop
  203.                         {
  204.                             FileReadLine, line_data, %path%, %line_count%
  205.                             line_count++
  206.                             IfInString, line_data, //
  207.                                 Temp_content = %temp_content%%line_data%`n
  208.                             if (line_count = A_CurrLine)
  209.                                 break
  210.                         }
  211.                         StringReplace, Temp_content, Temp_content, %A_Tab%,,all
  212.                         StringReplace, Temp_content, Temp_content, /,,all
  213.                         ;StringReplace, Temp_content, Temp_content,%A_Space%,,
  214.                         StringReplace, Temp_content, Temp_content,`n,<br>,all
  215.                         StringReplace, Temp_content, Temp_content,`",&#34;,all
  216.                        
  217.                         StringReplace, B_LoopReadLine, A_LoopReadLine, %A_TAb%,,all
  218.                         StringSplit, value_, B_LoopReadLine, :
  219.                        var_ToContent = %var_ToContent%%var_Index%,%value_1%|
  220.                         StringReplace, value_2, value_2, `",&#34;,all
  221.                         StringReplace, value_2, value_2, %A_space%,,
  222.                         StringReplace, Temp_content,Temp_content, (Note 1), <br>(Note 1: %Note_1%
  223.                         StringReplace, Temp_content,Temp_content, (Note 2), <br>(Note 2: %Note_2%
  224.                         StringReplace, Temp_content,Temp_content, (Note 3), <br>(Note 3): %Note_3%
  225.                         if Temp_content !=
  226.                         {
  227.                             HTML_body =
  228.                             (   Ltrim Join
  229.                             %HTML_body%
  230.                             <tr>
  231.                             <td bgcolor="#4F4D50"><font color="#FFFFFF">%value_1%</font></td>
  232.                             <td><div class="tooltip"><input type="textarea" id="conf_%var_Index%" value="%value_2%"/><span class="tooltiptext">%Temp_content%</span></div></td>
  233.                             </tr>
  234.                             )
  235.                         }
  236.                         else
  237.                         {
  238.                             HTML_body =
  239.                             (   Ltrim Join
  240.                             %HTML_body%
  241.                             <tr>
  242.                             <td bgcolor="#4F4D50"><font color="#FFFFFF">%value_1%</font></td>
  243.                             <td><input type="textarea" id="conf_%var_Index%" value="%value_2%"/>%Temp_content%</td>
  244.                             </tr>
  245.                             )
  246.                         }
  247.                         Temp_content=
  248.                     }
  249.     }
  250.                 ;   HTML_body =
  251.                 ;   (LTrim Join
  252.                 ;       %HTML_body%
  253.                 ;       <tr>
  254.                 ;           <td align="center" colspan="2"><input type="button" id="Update" value="----------- UPDATE -----------"/></td>
  255.                 ;       </tr>
  256.                 ;       </table>
  257.                 ;   )
  258.                     HTML_page = %HTML_header%`n%HTML_body%`n%HTML_footer%
  259.                     StringTrimRight, var_ToContent, var_ToContent, 1
  260. }
  261.  
  262. Display(WB,html_str) {
  263.     Count:=0
  264.     while % FileExist(f:=A_Temp "\" A_TickCount A_NowUTC "-tmp" Count ".DELETEME.html")
  265.         Count+=1
  266.     FileAppend,%html_str%,%f%
  267.     WB.Navigate("file://" . f)
  268. }
  269.  
  270. Esc::ExitApp
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement