reini
Posted: Sat Aug 10, 2024 8:40 pm
The user asked for the ability to launch a program window with the same coordinates and window sizes, despite the fact that the program saves the current data. I suggested saving data from one ini file to another and then running the program.
Download
Download
Code: Select all
EnableExplicit
Structure Group
Map KeyVal.s()
EndStructure
Global i, tmp$
Global iniSource$
Global Destination$
Global NameProg$
Global agent$
Global NewMap virtini.Group()
agent$ = GetFilePart(ProgramFilename(), #PB_FileSystem_NoExtension)
iniSource$ = Left(ProgramFilename(), Len(ProgramFilename()) - 4) + ".ini"
If CountProgramParameters()
For i = 0 To CountProgramParameters() - 1
tmp$ = ProgramParameter(i)
Select Asc(tmp$)
Case 'p'
NameProg$ = Mid(tmp$, 3)
Case 'd'
Destination$ = Mid(tmp$, 3)
EndSelect
Next
EndIf
Procedure.s PathFind3(*pfile)
Protected Dim Dirs.s(1)
Protected Path.s{#MAX_PATH} = PeekS(*pfile)
Dirs(0) = GetPathPart(ProgramFilename())
PathFindOnPath_(@Path, @Dirs())
ProcedureReturn Path
EndProcedure
Procedure Read_INI(Map virtini.Group())
If OpenPreferences(iniSource$)
ExaminePreferenceGroups()
While NextPreferenceGroup()
If PreferenceGroupName() = agent$
If Not Asc(NameProg$)
NameProg$ = ReadPreferenceString("NameProg", "")
EndIf
If Not Asc(Destination$)
Destination$ = ReadPreferenceString("Destination", "")
If Not FindString(Destination$, ":")
Destination$ = PathFind3(@Destination$)
EndIf
EndIf
Continue
EndIf
AddMapElement(virtini(), PreferenceGroupName(), #PB_Map_NoElementCheck)
ExaminePreferenceKeys()
While NextPreferenceKey()
If AddMapElement(virtini()\KeyVal(), PreferenceKeyName(), #PB_Map_NoElementCheck)
virtini()\KeyVal() = PreferenceKeyValue()
EndIf
Wend
Wend
ClosePreferences()
EndIf
ProcedureReturn MapSize(virtini())
EndProcedure
If Read_INI(virtini()) And FileSize(Destination$) > - 1
ForEach virtini()
ForEach virtini()\KeyVal()
WritePrivateProfileString_(MapKey(virtini()), MapKey(virtini()\KeyVal()), virtini()\KeyVal(), Destination$)
Next
Next
EndIf
If Not FindString(NameProg$, ":")
NameProg$ = PathFind3(@NameProg$)
EndIf
RunProgram(NameProg$)