#cs ---------------------------------------------------------------------------- # Copyright 2009 Pierre-Yves Gosset. # # This copyrighted material is made available to anyone wishing to use, modify, # copy, or redistribute it subject to the terms and conditions of the GNU # General Public License v.2. This program is distributed in the hope that it # will be useful, but WITHOUT ANY WARRANTY expressed or implied, including the # implied warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # See the GNU General Public License for more details. You should have # received a copy of the GNU General Public License along with this program; if # not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth # Floor, Boston, MA 02110-1301, USA. # # Author(s): Pierre-Yves Gosset #ce ---------------------------------------------------------------------------- Func START_ALL() Global $startTime = TimerInit() ; we start a timer SPLASHSCREEN() ; Show the splashscreen for a defined time TrayTip($appName & " - " & $appVersion, l("StartingAll"), 3, 1) ; treatment of session file. The seesion file is here to prevent multiple simultaneous launch of the same webapp If FileExists($session_file) Then If Not IsDeclared("iMsgBoxAnswer") Then Local $iMsgBoxAnswer $iMsgBoxAnswer = MsgBox(308, l("SessionFileExists"), l("SessionFileExists") & @CRLF & $session_file & @CRLF & l("ApplicationYetStarted") & @CRLF & @CRLF & l("YouMayContinueIfYouWant") & @CRLF & @CRLF & l("IgnoreAndLaunch?")) Select Case $iMsgBoxAnswer = 6 ;Yes ;we continue Case $iMsgBoxAnswer = 7 ;No ;we quit Exit EndSelect EndIf ; launch mysql (if NeedMySQL is not set to False in appinfo.ini) If $NeedMySQL <> "False" Then MYSQL_START() ; lanch web server ZMWS_START() _FileCreate($session_file) ; create session file Sleep(2000) $test = TEST_ALL(4, 500) If $test = True Then TrayTip($appName & " - " & $appVersion, l("ServersReady"), 4, 1) EndIf UpdateStartup() ; launch optional /App/Appinfo/startup.ini scripts to update some critical values. TrayTip($appName & " - " & $appVersion, l("ConfigurationUpdated"), 4, 1) WamLog(@ScriptLineNumber & $DisplayHelp) If ($DisplayHelp == True) Then HELP() EndFunc ;==>START_ALL ; Test if services are alunch (could be refined) Func TEST_ALL($tries, $delay) $test_mysql_status = MYSQL_GET_STATUS() $test_zmws_status = ZMWS_GET_STATUS() If ($test_mysql_status = True) And ($test_zmws_status = True) Then Return True Else $tries = $tries - 1 If $tries < 1 Then Return False Sleep($delay) TEST_ALL($tries, $delay) EndIf Return False EndFunc ;==>TEST_ALL ; Open the main WebApp Page Func LAUNCH() If APP_ACCESS_PATH() = False Then MsgBox(48, l("error"), l("ZMWSNotActive") & @CRLF & l("ZMWSPleaseRestart")) Else OpenWebPage(APP_ACCESS_PATH()) EndIf EndFunc ;==>LAUNCH ; Display the Info window Func INFOS() $APP_ACCESS_PATH = APP_ACCESS_PATH() If $APP_ACCESS_PATH = False Then $access = l("NotApplicable") Else $access = $APP_ACCESS_PATH EndIf if $zmws_bind <> "False" Then $public_url = " - (bind)" Else $public_url = "http://" & _GetIP() & ":" & $zmws_port & "/" & $ApplicationPath EndIf $msg = "======= APPLICATION =============" & @CRLF $msg = "Nom: " & $appName & @CRLF $msg &= "Version: " & $appVersion & @CRLF $msg &= "Description: " & $appDescription & @CRLF $msg &= "Category: " & $Category & @CRLF $msg &= "URL: " & $access & @CRLF $msg &= "Public URL: "& $public_url & @CRLF $msg &= "========= SERVERS =================" & @CRLF $msg &= "ZMWS: " & ZMWS_GET_STATUS() & @CRLF $msg &= "MySQL: " & MYSQL_GET_STATUS() & @CRLF $msg &= "MySQL port: " & $mysql_port & @CRLF If $APP_ACCESS_PATH <> False Then $msg &= "Loopback IP: " & $HTTP_LOOPBACK & @CRLF $msg &= "Local IP: " & $ZMWS_INIT_IP[1] & @CRLF $msg &= "Visible IP: " & _GetIP() & @CRLF $msg &= "Port ZMWS: " & $ZMWS_INIT_HTTP_PORT[1] & @CRLF $msg &= "WebDir: " & $ZMWS_INIT_DOCUMENT_ROOT[1] & @CRLF $msg &= "Started: " & $UPDATE_TIME & @CRLF $msg &= "PID: " & $ZMWS_INIT_PID & @CRLF $msg &= "ZMWS Command: " & @CRLF & ZMWS_COMMAND() & @CRLF $msg &= "MySQL Command: " & @CRLF & MYSQL_COMMAND() & @CRLF Else $msg &= l("ZMWSStatusNotFound") & @CRLF EndIf $msg &= "============ ENVIRONMENT ==================" & @CRLF $msg &= "Logon : " & @LogonDNSDomain & " - " & @LogonDomain & " - " & @LogonServer & @CRLF $msg &= "OS : " & @OSVersion & " - " & @OSBuild & " - " & @OSServicePack & " - " & @OSLang & @CRLF $msg &= "Script : " & @ScriptFullPath & @CRLF InfoShowWindow($msg) EndFunc ;==>INFOS ; quit nicely the webapp Func QUIT() GUISetState($ConfigWindow, @SW_HIDE) TrayTip($appName & " - " & $appVersion, l("ServersDoingShutdown"), 3, 1) MYSQL_STOP() ZMWS_STOP() While (MYSQL_GET_STATUS() = True) Sleep(500) MYSQL_STOP() WEnd While (ZMWS_GET_STATUS() = True) Sleep(500) ZMWS_STOP() WEnd TrayTip($appName & " - " & $appVersion, l("ServersShutdown"), 3, 1) FileDelete($session_file) Sleep(2500) Exit EndFunc ;==>QUIT ; return the main webapp page URL (i.e. http://127.0.0.1:8082/wordpress Func APP_ACCESS_PATH() If ZMWS_GET_STATUS() Then If $ZMWS_INIT_HTTP_PORT[1] <> 80 Then $app_access_local_port = ":" & $ZMWS_INIT_HTTP_PORT[1] Else $app_access_local_port = "" EndIf Return "http://" & $HTTP_LOOPBACK & $app_access_local_port & "/" & $ApplicationPath Else Return False EndIf EndFunc ;==>APP_ACCESS_PATH ; show the splashscreen for a limited time Func SPLASHSCREEN() If $WAMSplashTimeout = 0 Then Return False While TimerDiff($startTime) < $WAMSplashTimeout GUISetState(@SW_SHOW, $Splash) Sleep(500) WEnd GUISetState(@SW_HIDE, $Splash) EndFunc ;==>SPLASHSCREEN ;================ MYSQL ============================================= Func MYSQL_GET_STATUS() TCPStartup() If ProcessExists("mysqld.exe") And TCPConnect($HTTP_LOOPBACK, $mysql_port) <> -1 Then TCPShutdown() Return True Else TCPShutdown() Return False EndIf EndFunc ;==>MYSQL_GET_STATUS Func MYSQL_STATUS() If MYSQL_GET_STATUS() = True Then $status = l("MysqlStatusFound") & $mysql_port & ")" Else $status = l("MysqlStatusNotFound") & $mysql_port & ")" EndIf MsgBox(64, l("MysqlStatus"), $status) Return EndFunc ;==>MYSQL_STATUS ; Create the command line to strat or stop MySQL Func MYSQL_COMMAND($opt = "start") If ($opt = "start") Then $mysql_port = FIND_BEST_MYSQL_PORT() $mysql_port_option = " --port=" & $mysql_port $mysql_cmd = """" & $mysql_bin_path & "\" & $mysql_bin_name & """" & $mysql_no_default_option & $mysql_skip_innodb_option & $mysql_datadir_option & $mysql_pid_file_option & $mysql_port_option ;InfoShowWindow($mysql_bin_path & "\" & $mysql_bin_name & $mysql_options) ElseIf ($opt = "stop") Then $mysql_cmd = """" & $mysql_bin_path & "\" & $mysqladmin_bin_name & """" & $mysql_shutdown_option & $mysql_user_option & $mysql_port_option EndIf Return $mysql_cmd EndFunc ;==>MYSQL_COMMAND ; Determine the mysql port to use Func FIND_BEST_MYSQL_PORT() WamLog("Port avant:"&$mysql_port) if $mysql_port_set=True Then Return $mysql_port IF (($mysql_port = "Auto") Or ($mysql_port=$mysql_default_port) ) Then ; mysql port is "Auto" or default port TCPStartup() WamLog("Port pendant:"&$mysql_port) $mysql_port = $mysql_default_port ; we set the port to the default port While TCPConnect($HTTP_LOOPBACK, $mysql_port) <> -1 ;if a connection is found, a mysql is already in use on that port... $mysql_port = $mysql_port+1 ; so we try the next one WamLog("Port +1:"&$mysql_port) WEnd TCPShutdown() Else ; mysql port is fixed ;$mysql_port=$mysql_default_port ;we do not change anything EndIf WamLog("Port après:"&$mysql_port) $mysql_port_set=True Return $mysql_port EndFunc ;==>FIND_BEST_MYSQL_PORT Func MYSQL_RESTART() $restart = True MySQL_START() $retart = False EndFunc ;==>MYSQL_RESTART Func MYSQL_START() TrayTip(l("MySQL"), l("StartingMysql"), 2, 1) If (MYSQL_GET_STATUS() = True) And ($restart = True) Then MYSQL_STOP() EndIf Run(MYSQL_COMMAND("start"), $mysql_bin_path) ; launch MYSQL with options WAMLog(MYSQL_COMMAND("start")) Sleep(1000) EmptyTrayTip() If (($restart = True) And ( MYSQL_GET_STATUS())) Then TrayTip(l("MySQL"), l("MysqlRestarted"), 3, 1) EndFunc ;==>MYSQL_START Func MYSQL_STOP() If MYSQL_GET_STATUS() = False Then Return ; Nothing to do EndIf TrayTip(l("MySQL"), l("StoppingMysql"), 1, 2) Run(MYSQL_COMMAND("stop"), $mysql_bin_path) ; launch MYSQL with options Sleep(2000) $mysql_port_set=False EmptyTrayTip() EndFunc ;==>MYSQL_STOP ;================ ZMWS ============================================= Func ZMWS_GET_STATUS() If (ProcessExists($ZMWS_INIT_PID)) Then ; We test the pid file Return True Else Return False EndIf EndFunc ;==>ZMWS_GET_STATUS ; Create the command line to strat or stop MySQL Func ZMWS_COMMAND($opt = "start") If ($opt = "start") Then $zmws_options = $zmws_port_option & $zmws_stops_option & $zmws_unique_port_option & $zmws_quiet_option & $zmws_browse_option & $zmws_nolog_option & $zmws_closebrowser_option & $zmws_bind_option & $zmws_noindex_option & $zmws_webdir_option $zmws_cmd = @ComSpec & " /c """ & $zmws_path & "\" & $zmws_bin_name & """ " & $zmws_options ;$zmwsc = Run(@ComSpec & " /c " & $zmws_path & "\ZazouMiniWebServer.exe -stop -closebrowser" & $browse, $zmws_path, @SW_HIDE, 7) ElseIf ($opt = "stop") Then $zmws_options = " -shutdown" & $zmws_port $zmws_cmd = @ComSpec & " /c """ & $zmws_path & "\" & $zmws_bin_name & """ " & $zmws_options EndIf Return $zmws_cmd EndFunc ;==>ZMWS_COMMAND ; display the server web status Func ZMWS_STATUS() If ZMWS_GET_STATUS() = True Then $status = l("ZMWSStatusFound") & " (PID:" & $ZMWS_INIT_PID & ")" $status &= "" Else $status = l("ZMWSStatusNotFound") & " (PID:" & $ZMWS_INIT_PID & ")" EndIf MsgBox(64, "Etat de ZMWS", $status) Return EndFunc ;==>ZMWS_STATUS Func ZMWS_START() $restart = False ; if ZMWS is already launched (we found a PID), we stop it. If ZMWS_GET_STATUS() = True Then $restart = True ZMWS_STOP() EndIf TrayTip(l("ZMWS"), l("StartingZmws"), 2, 1) WAMLog(ZMWS_COMMAND("start")) ; launch ZMWS $zmwsc = Run(ZMWS_COMMAND("start"), $zmws_path, @SW_HIDE, 7) If $zmwsc > 0 Then ; Launching the web server has returned a Process ID (PID) $ZMWS_INIT_PID = $zmwsc $UPDATE_TIME = _NowCalc() Else MsgBox(0, l("Error"), l("ZMWSImpossibleToStart")) EndIf ; quite complex part : we get the output of the hidden DOS window, to get the port and other infos While 1 $line = StdoutRead($zmwsc) $pos = StringInStr($line, "HTTPS") If $pos > 0 Then $ZMWS_INIT_HTTP_PORT = StringRegExp($line, " --> HTTP : YES, port (\d*)", 2) $ZMWS_INIT_HTTPS_PORT = StringRegExp($line, " --> HTTPS : YES, port (\d*)", 2) $ZMWS_INIT_DOCUMENT_ROOT = StringRegExp($line, "WebDir: (.*)", 2) $ZMWS_INIT_IP = StringRegExp($line, "IP: ((\d*)\.(\d*)\.(\d*)\.(\d*))", 2) $zmws_port = $ZMWS_INIT_HTTP_PORT[1] WamLog($line) ExitLoop EndIf If @error Then ExitLoop WEnd $APP_ACCESS_PATH = APP_ACCESS_PATH() ; return the main webapp url EmptyTrayTip() If (($restart) And (ZMWS_GET_STATUS())) Then TrayTip("ZMWS", l("ZMWSRestarted") & " (port:" & $ZMWS_INIT_HTTP_PORT[1] & ";PID:" & $ZMWS_INIT_PID & ")", 3, 1) EndFunc ;==>ZMWS_START Func ZMWS_STOP() If ZMWS_GET_STATUS() = False Then Return ; Nothing to do EndIf TrayTip(l("ZMWS"), l("StoppingZmws"), 2, 1) Run($zmws_path & "\ZazouMiniWebServer -shutdown " & $ZMWS_INIT_HTTP_PORT[1], $zmws_path, @SW_HIDE) Sleep(3000) EmptyTrayTip() $ZMWS_INIT_PID = 0 EndFunc ;==>ZMWS_STOP ; ================ TOOLS ===================== ; return the portableFirefox path Func PFIREFOX_PATH() Return "" ; bypassing : does not work at this time If FileExists($root_path_absolute & "\..\PortableFirefox\PortableFirefox.exe") Then Return """" & $root_path_absolute & "\..\PortableFirefox\PortableFirefox.exe"" " ElseIf FileExists($root_path_absolute & "\..\FirefoxPortable\FirefoxPortable.exe") Then Return """" & $root_path_absolute & "\..\FirefoxPortable\FirefoxPortable.exe"" " Else Return "" EndIf EndFunc ;==>PFIREFOX_PATH Func HEIDISQL() Run($heidisql_file, $zmws_path & "\HeidiSQL\", @SW_HIDE) EndFunc ;==>HEIDISQL Func ESKUEL() If APP_ACCESS_PATH() = False Then MsgBox(48, l("error"), l("ZMWSNotActive") & @CRLF & l("ZMWSPleaseRestart")) Else OpenWebPage("http://" & $HTTP_VHOST & ":" & $ZMWS_INIT_HTTP_PORT[1] & "/eskuel/") EndIf EndFunc ;==>ESKUEL Func OWEBSITE() OpenWebPage($Website) EndFunc ;==>OWEBSITE Func OSUPPORT() OpenWebPage($Support) EndFunc ;==>OSUPPORT Func FWEBSITE() OpenWebPage($framasoftURL) EndFunc ;==>FWEBSITE Func FSUPPORT() OpenWebPage($framasoftSupportURL) EndFunc ;==>FSUPPORT Func HELP() ShowBrowser($appinfo_path & "\help." & $WAMlang & ".html") Return False EndFunc ;==>HELP Func WAMHELP() ShowBrowser(@ScriptDir & "\wamhelp." & $WAMlang & ".html") Return False EndFunc ;==>WAMHELP Func ABOUT() $HelpFileContent = FileRead(@ScriptDir & "\about." & $WAMlang & ".txt") InfoShowWindow($HelpFileContent) EndFunc ;==>ABOUT Func CONFIGWINDOW() GUISetState(@SW_SHOW, $ConfigWindow) $configWindowIsOpen = True ConfigWindowUpdate() EndFunc ;==>CONFIGWINDOW Func OpenWebPage($url2open) If ($url2open = False) Then MsgBox(32, l("Error"), l("BadURL") & $url2open) Else ShellExecute($url2open) EndIf EndFunc ;==>OpenWebPage Func EmptyTrayTip() TrayTip("On vide", "", 0) EndFunc ;==>EmptyTrayTip ; ================ SCRIPTS MENU ======================== Func CREATE_SCRIPTSMENU() ASSIGN_SCRIPTSMENU($generic_scripts_file, $DEFAULTSCRIPTSMENU) ASSIGN_SCRIPTSMENU($appscripts_file, $SPECIFICSCRIPTSMENU) EndFunc ;==>CREATE_SCRIPTSMENU Func ASSIGN_SCRIPTSMENU($scriptfile, $menu) If Not FileExists($scriptfile) Then Return False $aScripts = IniReadSectionNames($scriptfile) If Not IsArray($aScripts) Then Return False For $i = 1 To $aScripts[0] ; Récupération du libellé et de la commande à exécuter $name = ReplaceScriptsValue(ScriptGetValue($scriptfile, $aScripts[$i], "Name")) $type = ScriptGetValue($scriptfile, $aScripts[$i], "Type") $description = ScriptGetValue($scriptfile, $aScripts[$i], "Description") $done = ScriptGetValue($scriptfile, $aScripts[$i], "Done", "") $query = ScriptGetValue($scriptfile, $aScripts[$i], "Query") $file = ScriptGetValue($scriptfile, $aScripts[$i], "File") $searchpattern = ScriptGetValue($scriptfile, $aScripts[$i], "SearchPattern") $replacevalue = ScriptGetValue($scriptfile, $aScripts[$i], "ReplaceValue") ; Création de l'entrée de menu $id = TrayCreateItem($name, $menu) ; Si la commande est spécifiée, on l'associe à l'élément $commands[$id][0] = $name $commands[$id][1] = $type $commands[$id][2] = $description $commands[$id][3] = $done $commands[$id][4] = $query $commands[$id][5] = $file $commands[$id][6] = $searchpattern $commands[$id][7] = $replacevalue TrayItemSetOnEvent(-1, "RunScript") Next EndFunc ;==>ASSIGN_SCRIPTSMENU Func ScriptGetValue($file, $key, $value, $default = "ValueNotFound") $r = IniRead($file, $key, $value & "_" & $WAMlang, $default) If $r <> $default Then Return $r ; we return the value in specific language Return IniRead($file, $key, $value, $default) ; else we return the value in generic language EndFunc ;==>ScriptGetValue Func RunScript() Dim $script[8] ; for each possible command, we assign a value into $script array For $i = 0 To 7 $script[$i] = ReplaceScriptsValue($commands[@TRAY_ID][$i]) Next ; MsgBox creation start If Not IsDeclared("iMsgBoxAnswer") Then Local $iMsgBoxAnswer $msg = "Description :" & @CRLF $msg &= $script[2] & @CRLF $msg &= "=================================" & @CRLF $msg &= "TYPE :" & $script[1] & @CRLF If $commands[@TRAY_ID][1] = "SQL" Then $msg &= "QUERY :" & $script[4] & @CRLF ElseIf $commands[@TRAY_ID][1] = "SQLFILE" Then $msg &= "SQL File :" & $script[5] & @CRLF ElseIf $commands[@TRAY_ID][1] = "EDIT" Then $msg &= "FILE :" & $script[5] & @CRLF ElseIf $commands[@TRAY_ID][1] = "URL" Then $msg &= "URL :" & $script[5] & @CRLF ElseIf $commands[@TRAY_ID][1] = "COMMAND" Then $msg &= "COMMAND :" & $script[4] & @CRLF ElseIf $commands[@TRAY_ID][1] = "FILE" Then $msg &= "FILE ("& $script[4] &"):" & $script[5] & @CRLF ElseIf $commands[@TRAY_ID][1] = "REPLACE" Then $msg &= "Open :" & $script[5] & @CRLF $msg &= "Search :" & $script[6] & @CRLF $msg &= "Replace with :" & $script[7] & @CRLF EndIf ; MsgBox creation stop $iMsgBoxAnswer = MsgBox(292, $commands[@TRAY_ID][0], $msg) Select Case $iMsgBoxAnswer = 6 ; User answerd Yes : we continue Case Else $iMsgBoxAnswer = 7 ; User answered No : we exit Return False EndSelect ; execution of the script command Select Case $commands[@TRAY_ID][1] = "COMMAND" ScriptCOMMAND($script[4], $script[3]) Case $commands[@TRAY_ID][1] = "SQL" ScriptSQL($script[4], $DatabaseName, $script[3]) Case $commands[@TRAY_ID][1] = "SQLFILE" ScriptSQLFILE($script[5], $DatabaseName, $script[3]) Case $commands[@TRAY_ID][1] = "REPLACE" ScriptREPLACE($script[5], $script[6], $script[7], $script[3]) Case $commands[@TRAY_ID][1] = "EDIT" ScriptEDIT($script[5], $script[3]) Case $commands[@TRAY_ID][1] = "FILE" ScriptFILE($script[5], $script[4]) Case $commands[@TRAY_ID][1] = "URL" ScriptURL($script[5]) EndSelect Return EndFunc ;==>RunScript ; this function replace specific strings like {$DatabaseName} by their variable value ("wordpress") Func ReplaceScriptsValue($data) $CurrentDate = @YEAR & "-" & @MON & "-" & @MDAY & "-" & @HOUR & "-" & @MIN & "-" & @SEC Wamlog("start="&$data) $data = StringReplace($data, "{$DatabaseName}", $DatabaseName) $data = StringReplace($data, "{$ApplicationPath}", $ApplicationPath) $data = StringReplace($data, "{$root_path_absolute}", $root_path_absolute) $data = StringReplace($data, "{$r_p_a_backslashes}", $r_p_a_backslashes) $data = StringReplace($data, "{$appinfo_path}", $appinfo_path) $data = StringReplace($data, "{$ApplicationURL}", APP_ACCESS_PATH()) $data = StringReplace($data, "{$appShortName}", $appShortName) $data = StringReplace($data, "{$CurrentDate}", $CurrentDate) $data = StringReplace($data, "{$mysql_bin_path}", $mysql_bin_path) $data = StringReplace($data, "{$mysql_bin_name}", $mysql_bin_name) $data = StringReplace($data, "{$mysql_port}", $mysql_port) $data = StringReplace($data, "{$zmws_webdir}", $zmws_webdir) $data = StringReplace($data, "{$zmws_default_webdir}", $zmws_default_webdir) $data = StringReplace($data, "{$zmws_path}", $zmws_path) $data = StringReplace($data, "{$zmws_port}", $zmws_port) $data = StringReplace($data, "{@ComSpec}", @ComSpec) $data = StringReplace($data, "{@CRLF}", @CRLF) $data = StringReplace($data, "{@ScriptDir}", @ScriptDir) Wamlog("end="&$data) Return $data EndFunc ;==>ReplaceScriptsValue ; Execute a "COMMAND" script Func ScriptCOMMAND($cmd, $info = False) Run($cmd) If $info <> False Then InfoShowWindow($cmd & @CRLF & @CRLF & $info) EndIf EndFunc ;==>ScriptCOMMAND ; Execute a "SQL" script Func ScriptSQL($sql, $DatabaseName, $info = False) Run("""" & $mysql_bin_path & "\mysql.exe"" -u root" & $mysql_port_option & " -e """ & $sql & """ " & $DatabaseName) WAMLog("""" & $mysql_bin_path & "\mysql.exe"" -u root" & $mysql_port_option & " -e """ & $sql & """ " & $DatabaseName) If $info <> False Then InfoShowWindow($info & "-" & $DatabaseName) EndIf EndFunc ;==>ScriptSQL ; Execute a "SQLFILE" script (import and execute SQL query from a file) Func ScriptSQLFILE($file, $DatabaseName, $info = False) If Not FileExists($file) Then MsgBox(64, l("Error"), l("FileNotFound") & @CRLF & $file) EndIf RunWait(@ComSpec & " /c " & """" & $mysql_bin_path & "\mysql.exe"" -u root" & $mysql_port_option & " -e ""source " & $file & """ " & $DatabaseName) If $info <> False Then InfoShowWindow($info) EndIf EndFunc ;==>ScriptSQLFILE ; Execute a "REPLACE" script (search and replace in a file) Func ScriptREPLACE($file, $search, $replace, $info = False) If Not FileExists($file) Then MsgBox(64, l("Error"), l("FileNotFound") & @CRLF & $file) EndIf $filec = FileOpen($file, 0) $content = FileRead($filec) FileClose($filec) $filec = FileOpen($file, 2) $content = StringRegExpReplace($content, $search, $replace) If (@error = 0) Then If $info <> False Then InfoShowWindow($info) EndIf Else MsgBox(32, l("RegExpReplace"), l("RegExpReplaceFail")) If $info <> False Then InfoShowWindow($info) EndIf EndIf FileWrite($filec, $content) FileClose($filec) EndFunc ;==>ScriptREPLACE ; Execute a "EDIT" script (open a file with his default software) Func ScriptEDIT($file, $info = False) If Not FileExists($file) Then MsgBox(64, l("Error"), l("FileNotFound") & @CRLF & $file) EndIf ShellExecute($file) EndFunc ;==>ScriptEDIT ; Execute a "URL" script (open a webpage) Func ScriptURL($url) OpenWebPage($url) EndFunc ;==>ScriptURL Func ScriptFILE($file, $action, $info = False) If Not FileExists($file) Then MsgBox(64, l("Error"), l("FileNotFound") & @CRLF & $file) EndIf Select Case $action = "UNPROTECT" FileSetAttrib($file, "-R") Case $action = "PROTECT" FileSetAttrib($file, "+R") Case $action = "EDIT" ShellExecute($file) EndSelect EndFunc ;==>ScriptEDIT ; ================ Languages and Translations ======================== ; try to guess the language using the OS language Func GUESSLANG() Select Case (@OSLang = "040c" Or @OSLang = "080c" Or @OSLang = "0c0c" Or @OSLang = "100c" Or @OSLang = "140c" Or @OSLang = "180c") Return "fr" Case Else Return "en" EndSelect EndFunc ;==>GUESSLANG ; return the language lists from detected languages files Func GetLangList() $search = FileFindFirstFile(@ScriptDir & "\Lang.*.ini") Dim $LangList While 1 $file = FileFindNextFile($search) If @error Then ExitLoop $f = StringReplace($file, "lang.", "") $f = StringReplace($f, ".ini", "") $LangList &= "|" & $f WEnd Return $LangList FileClose($search) EndFunc ;==>GetLangList ; return a localised string from $trans array (read from language file) Func l($loc) $search = $loc & "=" $pos = _ArraySearch($trans, $search, 0, 0, 0, True) If (@error = 6) Then MsgBox(64, "TRANSLATION ERROR", "String " & $loc & " was searched for translation, but without success." & @CRLF & "Please adjust " & $lngfile) _ArrayDisplay($trans) Return "UNTRANSLATED" EndIf $text = $trans[$pos] $text = ReplaceScriptsValue($text) $locTranslated = StringReplace($text, $search, "") Return $locTranslated EndFunc ;==>l ; ================ Info Window ======================== Func InfoShowWindow($msg, $mode = "set") If $mode = "set" Then _GUICtrlEdit_SetText($InfoArea, $msg) ElseIf $mode = "append" Then _GUICtrlEdit_AppendText($InfoArea, $msg) EndIf GUISetState(@SW_SHOW, $InfoWindow) GUICtrlSetState($InfoCloseButton, $GUI_FOCUS) ;_GUICtrlEdit_SetSel($InfoArea, -1, 1) Return EndFunc ;==>InfoShowWindow Func InfoCloseButtonClick() GUISetState(@SW_HIDE, $InfoWindow) EndFunc ;==>InfoCloseButtonClick Func InfoWindowClose() GUISetState(@SW_HIDE, $InfoWindow) EndFunc ;==>InfoWindowClose ; ================== Create Embedded browser ================== Func HideBrowser() GUISetState(@SW_HIDE, $oIE) GUIDelete($oIE) EndFunc ;==>HideBrowser Func ShowBrowser($url = False, $title = "Infos") GUISetState(@SW_HIDE, $oIE) _IEErrorHandlerRegister() Global $oIE $oIE = _IECreateEmbedded() GUICreate($title, 640, 580, -1, -1) $GUIActiveX = GUICtrlCreateObj($oIE, 0, 0, 640, 537) $oIE_Hide = GUICtrlCreateButton(l("InfoClose"), 272, 544, 105, 25, 0) GUICtrlSetOnEvent($oIE_Hide, "HideBrowser") GUISetOnEvent($GUI_EVENT_CLOSE, "HideBrowser") GUISetState(@SW_SHOW, $oIE) ;Hide GUI If $url <> False Then _IENavigate($oIE, $url) EndFunc ;==>ShowBrowser ; ================== Log File ================================ Func WAMLog($logdata) If (($WAMLog = False) Or ($WAMLog = "False")) Then Return False _FileWriteLog($Logfile, $logdata) EndFunc ;==>WAMLog ; ================== Return absolute root path ================================ Func Root_Path_Absolute() Local $sd, $rpa $sd = StringSplit(@ScriptDir, "\") For $i = 1 To $sd[0] - 2 $rpa &= $sd[$i] If ($i < $sd[0] - 2) Then $rpa &= "\" Next Return $rpa EndFunc ;==>Root_Path_Absolute ; ================== Update App config with running config values ================================ ; this function is run at startup, read the startup.ini file if exists and run scripts ;it's usefull to update some WebApp values to the current environment Func UpdateStartup() If Not FileExists($startup_file) Then Return False $aScripts = IniReadSectionNames($startup_file) If Not IsArray($aScripts) Then Return False For $i = 1 To $aScripts[0] ; Récupération du libellé et de la commande à exécuter $name = ReplaceScriptsValue(ScriptGetValue($startup_file, $aScripts[$i], "Name")) $type = ReplaceScriptsValue(ScriptGetValue($startup_file, $aScripts[$i], "Type")) $description = ReplaceScriptsValue(ScriptGetValue($startup_file, $aScripts[$i], "Description")) $done = ReplaceScriptsValue(ScriptGetValue($startup_file, $aScripts[$i], "Done", "")) $query = ReplaceScriptsValue(ScriptGetValue($startup_file, $aScripts[$i], "Query")) $file = ReplaceScriptsValue(ScriptGetValue($startup_file, $aScripts[$i], "File")) $searchpattern = ReplaceScriptsValue(ScriptGetValue($startup_file, $aScripts[$i], "SearchPattern")) $replacevalue = ReplaceScriptsValue(ScriptGetValue($startup_file, $aScripts[$i], "ReplaceValue")) Select Case $type = "COMMAND" ScriptCOMMAND($query) Case $type = "SQL" ScriptSQL($query, $DatabaseName) Case $type = "SQLFILE" ScriptSQLFILE($file, $DatabaseName) Case $type = "REPLACE" ScriptREPLACE($file, $searchpattern, $replacevalue) Case $type = "URL" ScriptURL($query) Case $type = "FILE" ScriptFILE($file, $query) EndSelect Next EndFunc ;==>UpdateStartup