2024-03-04 17:44:41 +02:00
#required V8.sbsl
2024-03-01 19:22:17 +02:00
#required Sql.sbsl
#required BracketsParser.sbsl
#required BytesHelper.sbsl
#required V8BracketsHelper.sbsl
#required AnotherFuckingOneCFormatReader.sbsl
2024-03-05 09:17:19 +02:00
#required ConfigInfo.sbsl
2024-03-01 19:22:17 +02:00
@Global
structure Class
req val Connection: SqlConnection
@Global
2024-03-05 09:17:19 +02:00
method GetConfigInfo(): ConfigInfo.Class
2024-03-01 19:22:17 +02:00
val Root = GetConfigFileDataAsBracketsNode("root")
val Conf = GetConfigFileDataAsBracketsNode(Root.GetChildNode([1]).Value)
2024-03-05 09:17:19 +02:00
return new ConfigInfo.Class(
2024-03-01 19:22:17 +02:00
Conf.GetChildNode([3, 1, 1, 1, 1, 2]).AsString(),
V8BracketsHelper.GetSysonym(Conf.GetChildNode([3, 1, 1, 1, 1, 3])),
Conf.GetChildNode([3, 1, 1, 15]).AsString(),
V8BracketsHelper.GetCompatibilityMode(Conf.GetChildNode([3, 1, 1, 26]))
)
;
2024-03-04 17:44:41 +02:00
@Global
method HasExtension(ExtensionName: String): Boolean
val Query = Connection.CreateQueryWithSelect("SELECT Count(*) as Count FROM [dbo].[_ExtensionsInfo] WITH(NOLOCK) WHERE [_ExtName] = N'%ExtensionName'")
use QResult = Query.Execute()
QResult.Next()
return (QResult.Get("Count") as Number) > 0
;
2024-03-01 19:22:17 +02:00
@Global
2024-03-05 09:17:19 +02:00
method GetExtensionInfo(ExtensionName: String): ConfigInfo.Class
2024-03-01 19:22:17 +02:00
val RawData = GetExtensionZippedInfo(ExtensionName)
val Reader = AnotherFuckingOneCFormatReader.NewInstance(RawData, 2)
2024-03-05 09:17:19 +02:00
Reader.ReadString() // FileName
2024-03-01 19:22:17 +02:00
2024-03-05 09:17:19 +02:00
Reader.ReadByte() // Protect from danger actions " == Bytes {A2}" - is true
Reader.ReadVarbinary() // Generation version
Reader.ReadBoolean() // safe mode
2024-03-01 19:22:17 +02:00
Reader.ReadBoolean() // unknown flag
val BracketsNode = Reader.ReadBracketsNode()
val Synonym = V8BracketsHelper.GetSysonym(BracketsNode.GetChildNode([2]))
2024-03-04 17:44:41 +02:00
var Version = "0.0.0.0"
2024-03-01 19:22:17 +02:00
if not BytesHelper.Contains(Bytes{8182}, Reader.Peek())
// extension version is specified
2024-03-04 17:44:41 +02:00
Version = new String(Reader.ReadVarbinary())
2024-03-01 19:22:17 +02:00
;
2024-03-05 09:17:19 +02:00
return new ConfigInfo.Class(
2024-03-01 19:22:17 +02:00
ExtensionName,
Synonym,
Version,
2024-03-05 09:17:19 +02:00
"")
2024-03-01 19:22:17 +02:00
;
method GetParamsFileDataAsBracketsNode(FileName: String): BracketsParser.BracketsNode
return GetFileDataAsBracketsNode("Params", FileName)
;
2024-03-04 17:44:41 +02:00
method GetConfigCASFileDataAsBracketsNode(FileName: String): Array<BracketsParser.BracketsNode>
return GetFileDataAsBracketsNodes("ConfigCAS", FileName)
2024-03-01 19:22:17 +02:00
;
method GetConfigFileDataAsBracketsNode(FileName: String): BracketsParser.BracketsNode
return GetFileDataAsBracketsNode("Config", FileName)
;
2024-03-04 17:44:41 +02:00
method GetFileDataAsBracketsNodes(TableName: String, FileName: String): Array<BracketsParser.BracketsNode>
val Data = GetFileDataAsString(TableName, FileName)
return BracketsParser.ParseList(Data)
;
2024-03-01 19:22:17 +02:00
method GetFileDataAsBracketsNode(TableName: String, FileName: String): BracketsParser.BracketsNode
val Data = GetFileDataAsString(TableName, FileName)
return BracketsParser.Parse(Data)
;
method GetFileDataAsString(TableName: String, FileName: String): String
return new String(GetFileData(TableName, FileName), Encoding.Utf8)
;
method GetFileData(TableName: String, FileName: String): Bytes
val Query = Connection.CreateQueryWithSelect("SELECT CAST(DECOMPRESS(0x1F8B0800000000000400 + [BinaryData]) AS VARBINARY(MAX)) as Data FROM [dbo].[%TableName] WITH(NOLOCK) WHERE [FileName] = N'%FileName'")
use QResult = Query.Execute()
QResult.Next()
val Result = QResult.Get("Data") as Bytes
if Result.Length() > 3 and Result.GetRange(0, 3) == Bytes{EF BB BF}
return Result.GetRange(3)
else
return Result
;
;
method GetExtensionZippedInfo(ExtensionName: String): Bytes
val Query = Connection.CreateQueryWithSelect("SELECT [_ExtensionZippedInfo] as Data FROM [dbo].[_ExtensionsInfo] WITH(NOLOCK) WHERE [_ExtName] = N'%ExtensionName'")
use QResult = Query.Execute()
QResult.Next()
return QResult.Get("Data") as Bytes
;
2024-03-02 01:06:11 +02:00
;
@Global
method NewInstance(Connection: SqlConnection): Class
return new Class(Connection)
2024-03-01 19:22:17 +02:00
;