Jump to content

best format for storing tags and reading them


Recommended Posts

hello =)

i am trying to store meta data on some images and i would like to be able to read them later.  

this is how i was thinking on storing them:

$who = "bobby! sally2-meg,charles ryan,#swimmermike"
$what = "#kickin' it 4real@home!"
$where = "@myhouse"
$when = "2015:02:06"

$tag = "WHO:" & $who & "|" & "WHAT:" & $what & "|" & "WHERE:" & $where & "|" & "WHEN:" & $when & "|"

this is the format of the result i get when reading the tags

Quote

User Comment                         : WHO:bobby! sally2-meg,charles ryan,#swimmermike|WHAT:#kickin' it 4real@home!|WHERE:@myhouse|WHEN:2015:02:06|

i was going to do a _stringbetween to get the results but gets messy when some of the tags arent there.

good news is i am storing the data so i can put it in any format i want - but i do have to consider special characters the user may input

id like the output for each field $who $what $where $when as seperate variables

i think it might be a better suited job for stringregexp

any recomendations?

thanks in advance!

 

Edited by gcue
Link to comment
Share on other sites

this is what i have so far..

$results = "User Comment                         : WHO:bobby! sally2-meg,charles ryan,#swimmermike|WHAT:#kickin' it 4real@home!|WHERE:@myhouse|WHEN:2015:02:06|"

$array = StringRegExp($results, 'WHO.*?(\V.+)', 1)

i get the full results though.. how can i tell it to stop?  and what if that specific field is missing?

Edited by gcue
Link to comment
Share on other sites

Hello. I know that you're not asking for this. But maybe this can help you to store your data using a diferent way. I just get interesting in save metadata and did this.

 

#include <Array.au3>

Local $who = "bobby! sally2-meg,charles ryan,#swimmermike"
Local $what = "#kickin' it 4real@home!"
Local $where = "@myhouse"
Local $when = "2015:02:06"


;Structure
;Int -> Number of Fields
;Int -> Data Size
;byte ->Raw Data
;Next based in Number of Fields


#Region Test 1
Local $aMetaData[] = [$who, $what, $where, $when]

ConsoleWrite("+Create Meta Data File" & @CRLF)
Local $tMetaData = _MakeStructure($aMetaData)
_WriteMetaData("MetaData.bin", $tMetaData)


ConsoleWrite(@CRLF & @CRLF & "+Read Meta Data" & @CRLF )
Local $aNewMetaData = _ReadMetaData("MetaData.bin")
_ArrayDisplay($aNewMetaData)
ShellExecute("notepad.exe", @ScriptDir & "\MetaData.Bin")
#EndRegion


#Region Test 2
;With More Vaules
Local $aMetaData[] = ["Hi", 123456, "Danyfirex", "Autoit","Rocks","World"]

ConsoleWrite("+Create Meta Data File" & @CRLF)
Local $tMetaData = _MakeStructure($aMetaData)
_WriteMetaData("MetaData.bin", $tMetaData)


ConsoleWrite(@CRLF & @CRLF & "+Read Meta Data" & @CRLF )
Local $aNewMetaData = _ReadMetaData("MetaData.bin")
_ArrayDisplay($aNewMetaData)
ShellExecute("notepad.exe", @ScriptDir & "\MetaData.Bin")
#EndRegion





Func _ReadMetaData($sFilePath)
    Local $sFileBin = _GetFileBin($sFilePath)
    Local $iSize = @extended
    Local $tMetaData = DllStructCreate("byte[" & $iSize & "]")
    DllStructSetData($tMetaData, 1, $sFileBin)
    ConsoleWrite(DllStructGetData($tMetaData, 1) & @CRLF)
    Local $tNumberOfFields = DllStructCreate("int", DllStructGetPtr($tMetaData))
    Local $iNumberOfFields = DllStructGetData($tNumberOfFields, 1)
    ConsoleWrite("Number of Fields: " & $iNumberOfFields & @CRLF)
    Local $aMetaData[$iNumberOfFields]
    Local $pNextData = DllStructGetPtr($tMetaData) + 4 ;4 size Of Int
    If $iNumberOfFields Then
        Local $tFieldSize = 0
        Local $tFieldData = 0
        Local $iFieldSize = 0
        Local $sFieldData = 0

        For $i = 0 To $iNumberOfFields - 1
            $tFieldSize = DllStructCreate("int", $pNextData)
            $iFieldSize = DllStructGetData($tFieldSize, 1)
            $tFieldData = DllStructCreate("wchar[" & $iFieldSize & "]", $pNextData + 4) ;+4 To Get Data
            $sFieldData = DllStructGetData($tFieldData, 1)
            ConsoleWrite("FieldSize: " & $iFieldSize & @CRLF)
            ConsoleWrite("FieldData: " & $sFieldData & @CRLF)
            $aMetaData[$i] = $sFieldData
            $pNextData += $iFieldSize
            $pNextData += 4
            If $iFieldSize = 0 Then $pNextData += 2
        Next

    EndIf

    Return $aMetaData

EndFunc   ;==>_ReadMetaData


Func _GetFileBin($sFilePath)
    Local $hFile = FileOpen($sFilePath, 16)
    Local $sFileBin = FileRead($hFile)
    Local $iSize = @extended
    FileClose($hFile)
    Return SetError(0, $iSize, $sFileBin)
EndFunc   ;==>_GetFileBin

Func _WriteMetaData($sFilePath, $tStruct)
    Local $tStructBytes = DllStructCreate("byte[" & DllStructGetSize($tStruct) & "]", DllStructGetPtr($tStruct))
    Local $hFile = FileOpen($sFilePath, 18)
    FileWrite($hFile, DllStructGetData($tStructBytes, 1))
    FileClose($hFile)
EndFunc   ;==>_WriteMetaData


Func _MakeStructure($aMetaData)
    Local $sTagStructure = "Int NumberOfFields;"
    Local $tStruct = 0
    For $i = 0 To UBound($aMetaData) - 1
        $sTagStructure &= "align 1; int FieldSize" & String($i + 1) & ";wchar FieldData" & String($i + 1) & "[" & StringLen($aMetaData[$i]) + 1 & "];"
    Next
    ConsoleWrite($sTagStructure & @CRLF)
    $tStruct = DllStructCreate($sTagStructure)
    ConsoleWrite(IsDllStruct($tStruct) & @CRLF)

    $tStruct.NumberOfFields = UBound($aMetaData)

    For $i = 0 To UBound($aMetaData) - 1
        DllStructSetData($tStruct, "FieldSize" & String($i + 1), (StringLen($aMetaData[$i]) * 2) + 2)
        DllStructSetData($tStruct, "FieldData" & String($i + 1), ($aMetaData[$i]))
        ConsoleWrite("FiledSize: " & DllStructGetData($tStruct, "FieldSize" & String($i + 1)) & @CRLF)
        ConsoleWrite("FiledData: " & DllStructGetData($tStruct, "FieldData" & String($i + 1)) & @CRLF)
    Next

    Return $tStruct

EndFunc   ;==>_MakeStructure

Saludos

 

Edited by Danyfirex
Link to comment
Share on other sites

very nice going through dll

i just want to be able to store and read from the images themselves so i dont need to keep a file storing the information.

i think this format might be good

$tag = "WHO:" & $who & "|" & "WHAT:" & $what & "|" & "WHERE:" & $where & "|" & "WHEN:" & $when & "|"

just need the stringregexp to get each field

 

Link to comment
Share on other sites

What about using StringSplit? You wouldn't even need the WHO: WHAT: WHERE: if you didn't want it in there and it deals with "missing" data nicely too...

#include<array.au3>

Local $who = "bobby! sally2-meg,charles ryan,#swimmermike"
Local $what = "#kickin' it 4real@home!"
Local $where = "@myhouse"
Local $when = "2015:02:06"

$tag = "WHO:" & $who & "|" & "WHAT:" & $what & "|" & "WHERE:" & $where & "|" & "WHEN:" & $when & "|"

$array = StringSplit($tag,"|")
_ArrayDisplay($array)

 

Link to comment
Share on other sites

What I wrote can be used to write to any file. (write a little change)

 

I'm not a regexp man. so I prefer doing it using string functions only.

#include <Array.au3>


$results = "User Comment                         : WHO:bobby! sally2-meg,charles ryan,#swimmermike|WHAT:#kickin' it 4real@home!|WHERE:@myhouse|WHEN:2015:02:06|"


Local $aStrings = StringSplit($results, "|")
Local $iNumberOfFields = $aStrings[0] - 1

If $iNumberOfFields > 0 Then
    Local $aFields[$iNumberOfFields]
    Local $aMatch = 0
    Local $iStartPos = 0
    Local $iIndex = 0
    For $i = 1 To $aStrings[0]
        $aMatch = StringRegExp($aStrings[$i], "WHO:|WHAT:|WHERE:|WHEN:", 3)
;~      _ArrayDisplay($aMatch)
        If IsArray($aMatch) Then
            $iStartPos = StringInStr($aStrings[$i], $aMatch[0])
            $aFields[$iIndex] = StringMid($aStrings[$i], $iStartPos + StringLen($aMatch[0]))
            $iIndex += 1
        EndIf
    Next
EndIf

_ArrayDisplay($aFields)

Saludos

Link to comment
Share on other sites

So the regex way could be this...

#Include <Array.au3>

$str = "User Comment                         : WHO:bobby! sally2-meg,charles ryan,#swimmermike|WHAT:#kickin' it 4real@home!|WHERE:@myhouse|WHEN:2015:02:06| "
$res = StringRegExp($str, '(?<=WHO:|WHAT:|WHERE:|WHEN:)([^\|]*)', 3)
_ArrayDisplay($res)

 

Edited by mikell
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...