我目前正在研究一個遊戲啓動器,並從互聯網借用的工作代碼能夠解析一個INI。所有的工作都很好地保存了一個問題。VBScript,HTA - INI分析,允許內嵌評論
它無法解析ini文件中的內嵌評論。
例子:
[Window]
Width=800
解析罰款,沒有問題,很好。
[Window]
Width=800 ; width in pixels
但是上面沒有,我需要它能夠停止讀取線在檢測;如果可能的話。
這裏是我的全部HTA代碼:
<Html>
<Head>
<Title>Installer</Title>
<Meta Http-Equiv="x-ua-compatible" Content="ie=9">
<Link Rel="stylesheet" Type="text/css" Href="image/appStyles.css" Media="screen" />
<Script Language="VBScript" Type="Text/VBScript">
'-- Scripts to be carried out before the installer loads in.
'-- Functions --'
Function ReadIni(myFilePath, mySection, myKey)
' This function returns a value read from an INI file
' Examples
' ReadIni("settings.config", "Section1", "Keyname1")
' ReadIni("settings.config", "Section1", "Keyname2")
' ReadIni("settings.config", "Section2", "Keyname1")
' ReadIni("settings.config", "Section4", "Keyname2")
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Dim intEqualPos
Dim objFSO, objIniFile
Dim strFilePath, strKey, strLeftString, strLine, strSection
Set objFSO = CreateObject("Scripting.FileSystemObject")
ReadIni = ""
strFilePath = Trim(myFilePath)
strSection = Trim(mySection)
strKey = Trim(myKey)
If objFSO.FileExists(strFilePath) Then
Set objIniFile = objFSO.OpenTextFile(strFilePath, ForReading, False)
Do While objIniFile.AtEndOfStream = False
strLine = Trim(objIniFile.ReadLine)
' Check if section is found in the current line
If LCase(strLine) = "[" & LCase(strSection) & "]" Then
strLine = Trim(objIniFile.ReadLine)
' Parse lines until the next section is reached
Do While Left(strLine, 1) <> "["
' Find position of equal sign in the line
intEqualPos = InStr(1, strLine, "=", 1)
If intEqualPos > 0 Then
strLeftString = Trim(Left(strLine, intEqualPos - 1))
' Check if item is found in the current line
If LCase(strLeftString) = LCase(strKey) Then
ReadIni = Trim(Mid(strLine, intEqualPos + 1))
' In case the item exists but value is blank
If ReadIni = "" Then
ReadIni = " "
End If
' Abort loop when item is found
Exit Do
End If
End If
' Abort if the end of the INI file is reached
If objIniFile.AtEndOfStream Then Exit Do
' Continue with next line
strLine = Trim(objIniFile.ReadLine)
Loop
Exit Do
End If
Loop
objIniFile.Close
Else
' WScript.Echo strFilePath & " doesn't exists. Exiting..."
' Wscript.Quit 1
End If
End Function
'-- Subroutines --'
'-- Resize & move app to center
Sub SetWindow(WidthX,HeightY)
Self.ResizeTo WidthX, HeightY
Self.MoveTo (screen.Width - WidthX)/2, (screen.Height - HeightY)/2
End Sub
'-- Close app
Sub WinClose
Self.Close
End Sub
'-- Startup --'
'-- Read the configuration settings.
IniFile = "settings.config"
WinWidth = ReadIni(IniFile, "Window", "Width")
WinHeight = ReadIni(IniFile, "Window", "Height")
'-- Set Window size
SetWindow WinWidth, WinHeight
</Script>
<Hta:Application Id="Installer" ApplicationName="Installer" Version="0.1"
SingleInstance="Yes"
Icon="image/appIcon.ico"
Caption="No"
Border="None"
InnerBorder="No"
ContextMenu="No"
SysMenu="None"
Scroll="No"
Selection="No"
/>
</Head>
<Body>
<Div Id="status">Hello</Div>
<Script Language="VBScript" Type="Text/VBScript">
'-- Scripts that require access to the DOM...
'-- Startup
document.getElementById("status").InnerHTML = "Idle"
document.title = ReadIni(IniFile, "App", "Title")
</Script>
<Script Type="Text/Javascript">
//-- Javascripts that require access to the DOM...
window.onload = function() {
var a = document.getElementsByTagName("img");
a.ondragstart = function() { return false; }
}
</Script>
</Body>
</Html>
任何幫助,你們可以提供將是巨大的,謝謝!
不完全相關,但JS部分將無法正常工作。 'getElementsByTagName()'返回一個HTMLCollection,它是一個類似數組的對象。你必須遍歷它來訪問圖像元素,集合本身沒有'ondragstart'方法。 – Teemu
哦,是的,我正在修補它,將它應用於任何圖像,但意識到我不打算與發射器內的多個圖像(將要使用圖像的一個關閉圖標),但決定只是使用CSS來代替。因此,我將其更改回爲'var a = document.getElementById(「Logo」);' – Ctrlaltdenied