Jump to content

Reading all .ini sections.


LoadStar
 Share

Recommended Posts

I am learning autoit and have a few questions.

I am trying to read multiple sections of an .ini file. Should I use a loop for this? I am wondering what is the best way to go about this?

The picture I have attatched is what I want it to look like, I have figured out everything but the part dealing with reading the ini and displaying it into the listview section.

Here is an example of what my .ini looks like.

[GOODFILE1.mpg]
Format=MPEG-PS
Resolution=1920x1080
VideoFormat=MPEG Video
FrameRate=29.970 fps
BitRate=18.5 Mbps
Scan=Interlaced
AudioFormat=MPEG Audio
AudioVersion=Version 1
AudioProfile=Layer 2
AudioBitrate=384 Kbps
SamplingRate=48.0 KHz

[GOODFILE2.mpg]
Format=MPEG-PS
Resolution=1920x1080
VideoFormat=MPEG Video
FrameRate=29.970 fps
BitRate=18.5 Mbps
Scan=Interlaced
AudioFormat=MPEG Audio
AudioVersion=Version 1
AudioProfile=Layer 2
AudioBitrate=384 Kbps
SamplingRate=48.0 KHz

[BADFILE1.mpg]
Format=MPEG-TS
Resolution=1280x720
VideoFormat=MPEG Video
FrameRate=29.970 fps
BitRate=18.5 Mbps
Scan=Interlaced
AudioFormat=MPEG Audio
AudioVersion=Version 1
AudioProfile=Layer 2
AudioBitrate=192 Kbps
SamplingRate=24.0 KHz

The sample from the .ini above shows the values everything should be, I would like to have a way to make sure all values are correct and give a green box.

#include <ButtonConstants.au3>
#include <DateTimeConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstants.au3>
#include <Date.au3>

_Main()

;#####################################################################Build
Func _Main()
;### Local
Global $StartButton, $RefreshButton, $msg

;### Create Window
$VideoChecker = GUICreate("VideoChecker", 803, 603, 188, 115)

;### Logo
$Logo = GUICtrlCreateGraphic(8, 8, 401, 89)
GUICtrlSetBkColor(-1, 0x00FF00) ;Logo Placeholder

;### Create ListView
Global $ListView1 = GUICtrlCreateListView("Section|Format|Resolution|Video Format|Frame Rate|Bit Rate|Scan|Audio Format|Audio Version|Audio Profile|Audio Bit Rate|Sampling Rate", 8, 104, 785, 489)
   GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 125)
   GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 50)
   GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 2, 50)
   GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 3, 50)
   GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 4, 50)
   GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 5, 50)
   GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 6, 50)
   GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 7, 50)
   GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 8, 50)
   GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 9, 50)
   GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 10, 50)
   GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 11, 50)

;### Create Date
GUICtrlCreateDate("", 536, 8, 257, 33)

;### Create Clock
Opt("GUICoordMode",1)
Global $lblTime = GUICtrlCreateLabel("Time",538 ,68 ,200)
Global $lastsec = @SEC

;### Create StartButton
$StartButton = GUICtrlCreateButton("START", 416, 8, 113, 41)

;### Create RefreshButton
$RefreshButton = GUICtrlCreateButton("CLEAR", 416, 56, 113, 41)

;### GUISetState
GUISetState(@SW_SHOW)
EndFunc
;#################################################################END Build

GUICtrlSetBkColor

;#################################################################### Clock
Func updateTime()
    $cursec = @SEC
    if $cursec <> $lastsec Then
        $lastsec = $cursec
        GUICtrlSetData($lblTime,_NowTime())
    EndIf
EndFunc
;#################################################################END Clock

;###############################################################StartButton
Func StartButton()
   Run("C:playbackMediaInfo.bat", "C:playback", @SW_HIDE)
   Sleep(500)
   ProcessWait("cmd.exe")
   ProcessWaitClose("cmd.exe")
   Sleep(1000)
   SectionName()
EndFunc
;###########################################################END StartButton

;###############################################################SectionName
Func SectionName()
   Global $SectionName = IniReadSectionNames("C:playbackerror.ini")
   
If @error Then
      MsgBox(4096, "", "Error occurred, probably no INI file.")
   Else
      For $i = 1 To $SectionName[0]
         ;GUICtrlCreateListViewItem($SectionName[$i], $ListView1)
         Global $Format = IniRead("C:playbackerror.ini", $SectionName[$i], "Format", "NotFound")
         Global $Resolution = IniRead("C:playbackerror.ini", $SectionName[$i], "Resolution", "NotFound")
         Global $VideoFormat = IniRead("C:playbackerror.ini", $SectionName[$i], "VideoFormat", "NotFound")
         Global $FrameRate = IniRead("C:playbackerror.ini", $SectionName[$i], "FrameRate", "NotFound")
         Global $BitRate = IniRead("C:playbackerror.ini", $SectionName[$i], "BitRate", "NotFound")
         Global $Scan = IniRead("C:playbackerror.ini", $SectionName[$i], "Scan", "NotFound")
         Global $AudioFormat = IniRead("C:playbackerror.ini", $SectionName[$i], "AudioFormat", "NotFound")
         Global $AudioVersion = IniRead("C:playbackerror.ini", $SectionName[$i], "AudioVersion", "NotFound")
         Global $AudioProfile = IniRead("C:playbackerror.ini", $SectionName[$i], "AudioProfile", "NotFound")
         Global $AudioBitrate = IniRead("C:playbackerror.ini", $SectionName[$i], "AudioBitrate", "NotFound")
         Global $SamplingRate = IniRead("C:playbackerror.ini", $SectionName[$i], "SamplingRate", "NotFound")
      Check()
         GUICtrlCreateListViewItem($SectionName[$i] & "|" & $Format & "|" & $Resolution & "|" & $VideoFormat & "|" &  $FrameRate & "|" & $BitRate & "|" & $Scan & "|" & $AudioFormat & "|" & $AudioVersion & "|" & $AudioProfile & "|" & $AudioBitrate & "|" & $SamplingRate, $ListView1)
   Next
EndIf
EndFunc
;###########################################################END SectionName

;#####################################################################Check
Func Check()
   If $Format <> "MPEG-PS" Then
      $Format = "FAIL"
   EndIf
   If $Resolution <> "1920x1080" Then
      $Resolution = "FAIL"
   EndIf
   If $VideoFormat <> "MPEG Video" Then
      $VideoFormat = "FAIL"
   EndIf
   If $FrameRate <> "29.970 fps" Then
      $FrameRate = "FAIL"
   EndIf
   If $BitRate <> "18.5 Mbps" Then
      $BitRate = "FAIL"
   EndIf
   If $Scan <> "Interlaced" Then
      $Scan = "FAIL"
   EndIf
   If $AudioFormat <> "MPEG Audio" Then
      $AudioFormat = "FAIL"
   EndIf
   If $AudioVersion <> "Version 1" Then
      $AudioVersion = "FAIL"
   EndIf
   If $AudioProfile <> "Layer 2" Then
      $AudioProfile = "FAIL"
   EndIf
   If $AudioBitrate <> "384 Kbps" Then
      $AudioBitrate = "FAIL"
   EndIf
   If $SamplingRate <> "48.0 KHz" Then
      $SamplingRate = "FAIL"
      EndIf
EndFunc
;#################################################################END Check

;#############################################################RefreshButton
Func RefreshButton()
   GUICtrlDelete($ListView1)
   $ListView1 = GUICtrlCreateListView("Section|Format|Resolution|Video Format|Frame Rate|Bit Rate|Scan|Audio Format|Audio Version|Audio Profile|Audio Bit Rate|Sampling Rate", 8, 104, 785, 489)
   GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 125)
   GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 50)
   GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 2, 50)
   GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 3, 50)
   GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 4, 50)
   GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 5, 50)
   GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 6, 50)
   GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 7, 50)
   GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 8, 50)
   GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 9, 50)
   GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 10, 50)
   GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 11, 50)
EndFunc
;#########################################################END RefreshButton

;#####################################################################While
While 1
      $msg = GUIGetMsg()
      Select
         Case $msg = $GUI_EVENT_CLOSE
               ExitLoop
         Case $msg = $StartButton
               StartButton()
         Case $msg = $RefreshButton
               RefreshButton()
         Case Else
      EndSelect
      updateTime()
WEnd
;#################################################################END While

Edit: Updated script.

post-42405-0-51770500-1347399784_thumb.j

Edited by LoadStar
Link to comment
Share on other sites

Look at IniReadSectionNames to get all of the sections, then IniReadSection to get the contents of them, you will need to loop through the array returned by IniReadSectionNames to do this.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Alright, I've got it pulling data from the .ini file! So here is what I have, I have noticed that it SEEMS extremely messy...

#include <ButtonConstants.au3>
#include <DateTimeConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

_Main()

Func _Main()
Local $StartButton
Local $SectionName = IniReadSectionNames("C:playbackerror.ini")
$VideoChecker = GUICreate("VideoChecker", 802, 602, 188, 115)
$Logo = GUICtrlCreateGraphic(8, 8, 401, 89)
GUICtrlSetBkColor(-1, 0x00FF00) ;Logo Placeholder

$ListView1 = GUICtrlCreateListView("Section|Format|Resolution|Video Format|Frame Rate|Bit Rate|Scan|Audio Format|Audio Version|Audio Profile|Audio Bit Rate|Sampling Rate", 8, 104, 785, 489)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 50)

If @error Then
MsgBox(4096, "", "Error occurred, probably no INI file.")
Else
For $i = 1 To $SectionName[0]
GUICtrlCreateListViewItem($SectionName[$i], $ListView1)
Next
EndIf


$Date = GUICtrlCreateDate("2012/09/11 17:47:29", 536, 8, 257, 33)
$StartButton = GUICtrlCreateButton("START", 416, 8, 113, 89)
GUISetState(@SW_SHOW)


While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
ExitLoop
;
Case $StartButton
Run("C:playbackMediaInfo.bat", "C:playback", @SW_HIDE)
ProcessWaitClose("MediaInfo.bat")
Sleep(500)
;
Case Else
EndSwitch
WEnd

GUIDelete()
EndFunc ;==>_Main

Is there a way to make it refresh the array when I press the start button?

Edited by LoadStar
Link to comment
Share on other sites

Put the entire process of reading the ini file into its own function and use that function whenever you want to update it.

EDIT:

Are you sure that you don't want to use either a MYSQL or SQLITE database for what you're doing?

Edited by mechaflash213
Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Link to comment
Share on other sites

There is a function I created in the AutoIt Snippets wiki, have a look in the Examples thread.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Here >> _IniReadFile

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Alright I am having some trouble grasping functions and While statements.Am I supposed to leave the

While 1
$msg = GUIGetMsg()
Select
     Case $msg = $GUI_EVENT_CLOSE
         ExitLoop
EndSelect
updateTime()
WEnd

by itself, outside of a function? Is that where it looks when a the button is pressed?

I am also having trouble understanding how it goes to a function, does it run them all when it starts? Like with this clock:

$lblTime = GUICtrlCreateLabel("Time", 632, 70, 100, 20)
$lastsec = @SEC

Func updateTime()
    $cursec = @SEC
    if $cursec <> $lastsec Then
        $lastsec = $cursec
        GUICtrlSetData($lblTime,_NowTime())
    EndIf
EndFunc

I do not understand how it is calling the function.

Edited by LoadStar
Link to comment
Share on other sites

I'd start by using the tutorials that are in the wiki to learn how to do the basics before attempting a larger script that you're not properly trained to handle.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Functions are just ways of grouping code for later or reuse.

So you would have the while loop with an if statement checking for some condition to be met. Once the condition is met it would then run the function, Like updating the GUI with new info.

So something like this:

$A = 0

while 1
$A = $A + 1

If $A = 25 then
TestFucntion()
endif

wend

Func TestFunction()
msgbox(0,"Test","Got to 25")
EndFunc

Notice that the function can be located just about anywhere and can be called from elsewhere.

Also While 1 just means that it will check forever.

Edited by Attckdog

A true renaissance man

Link to comment
Share on other sites

Thank you for your post Attckdog! That little bit of information has helped so much!

I have updated the first post to reflect where I am now.

I think the last thing I need to do is get a color background behind each "FAIL" in the list view. I have tried GUICtrlSetBkColor (-1, color) but this seems to do the whole line above it.

Thank you for the support!

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...