Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- EnableExplicit
- CompilerIf #PB_Compiler_OS = #PB_OS_Windows
- #PathSeparator = "\"
- #StringCase = #PB_String_NoCase
- CompilerElse
- #PathSeparator = "/"
- #StringCase = #PB_String_CaseSensitive
- CompilerEndIf
- Structure udtFileInfo
- file.s
- ; size.q
- ; date.i
- EndStructure
- Declare GetFileInfoRecursive(List FileInfo.udtFileInfo(), Directory.s, Recursive = #True, Include.s = "", Trim = 0)
- Global Stop, PathMirror$, PathOrig$, Value$, FileOrig$, FileMirror$, Format, Text$
- ; ——————————————————————————————————————————————————
- ; PathMirror$ = PathRequester("Выберите зеркало", GetHomeDirectory())
- PathMirror$ = "/home/user/Загрузки/config_my/"
- If PathMirror$ = ""
- End
- EndIf
- ; PathOrig$ = PathRequester("Выберите оригинальный", GetPathPart(RTrim(GetUserDirectory( #PB_Directory_Desktop), "/")) + ".config")
- PathOrig$ = "/home/user/Загрузки/config_alien/"
- If PathOrig$ = ""
- End
- EndIf
- Global NewList FileInfo.udtFileInfo()
- Global NewList GroupsConf.s()
- Global NewMap KeyValueConf.s()
- ForEach FileInfo()
- Debug FileInfo()\file
- Next
- Define count = GetFileInfoRecursive(FileInfo(), PathMirror$, #True, "ini;conf", Len(PathMirror$)+1)
- ForEach FileInfo()
- ; Debug PathOrig$+FileInfo()\file
- ; Debug PathMirror$+FileInfo()\file
- FileOrig$ = PathOrig$+FileInfo()\file
- If FileSize(FileOrig$) > 1
- If ReadFile(0, FileOrig$)
- Format=ReadStringFormat(0) ; читаем метку файла BOM
- CompilerIf #PB_Compiler_Debugger = 1
- Debug FileOrig$
- Select Format
- Case #PB_Ascii
- Debug "Ascii или UTF без BOM"
- Case #PB_UTF8
- Debug "UTF-8 с BOM"
- Case #PB_Unicode
- Debug "UTF-16 LE с BOM"
- Case #PB_UTF16BE
- Debug "UTF-16 BE с BOM"
- Case #PB_UTF32
- Debug "UTF-32 LE с BOM"
- Case #PB_UTF32BE
- Debug "UTF-32 BE с BOM"
- Default
- Debug "неизвестный формат"
- EndSelect
- CompilerEndIf
- CloseFile(0)
- EndIf
- FileMirror$ = PathMirror$+FileInfo()\file
- If OpenPreferences(FileMirror$)
- ExaminePreferenceGroups()
- While NextPreferenceGroup() ; Пока находит группы
- AddElement(GroupsConf())
- GroupsConf() = PreferenceGroupName()
- ; MessageRequester("группы", GroupsConf())
- Wend
- ClosePreferences()
- EndIf
- ForEach GroupsConf()
- If OpenPreferences(FileMirror$) And PreferenceGroup(GroupsConf())
- ExaminePreferenceKeys()
- While NextPreferenceKey() ; Следующий ключ
- KeyValueConf(PreferenceKeyName()) = PreferenceKeyValue()
- Wend
- ClosePreferences()
- EndIf
- If OpenPreferences(FileOrig$) And PreferenceGroup(GroupsConf())
- ForEach KeyValueConf()
- Value$ = ReadPreferenceString(MapKey(KeyValueConf()) , "|-|")
- If KeyValueConf() <> Value$
- Debug "пишем: " + MapKey(KeyValueConf()) + " = " + KeyValueConf()
- WritePreferenceString(MapKey(KeyValueConf()), KeyValueConf())
- EndIf
- Next
- ClosePreferences()
- EndIf
- ClearMap(KeyValueConf())
- Next
- ClearList(GroupsConf())
- ; переоткрываем файл, чтобы записать его в оригинальном формате
- If ReadFile(0, FileOrig$)
- Text$ = ReadString(0, #PB_UTF8 | #PB_File_IgnoreEOL)
- CloseFile(0)
- If CreateFile(0, FileOrig$, Format)
- WriteStringFormat(0 , Format)
- Text$ = ReplaceString(Text$, " = ", "=")
- WriteString(0, Text$)
- CloseFile(0)
- EndIf
- EndIf
- EndIf
- Next
- ; ——————————————————————————————————————————————————
- Procedure GetFileInfoRecursive(List FileInfo.udtFileInfo(), Directory.s, Recursive = #True, Include.s = "", Trim = 0)
- Protected ID, name.s, extension.s
- ID = ExamineDirectory(#PB_Any, Directory, "*.*")
- If ID
- While NextDirectoryEntry(ID)
- name = DirectoryEntryName(ID)
- If DirectoryEntryType(ID) = #PB_DirectoryEntry_Directory
- If Recursive And name <> ".." And name <> "."
- GetFileInfoRecursive(FileInfo(), Directory+name+#PathSeparator, Recursive, Include, Trim)
- EndIf
- Else
- extension = GetExtensionPart(name)
- If extension And FindString(";" + Include + ";", ";" + extension + ";", 1, #StringCase)
- If AddElement(FileInfo()) = 0
- ; Out Of Memory
- Break
- EndIf
- With FileInfo()
- ; \file = StringField(Directory + name , 2 , PathMirror$)
- If Trim
- \file = Mid(Directory + name, Trim)
- Else
- \file = Directory + name
- EndIf
- ; \size = DirectoryEntrySize(ID)
- ; \date = DirectoryEntryDate(ID, #PB_Date_Modified)
- EndWith
- EndIf
- EndIf
- ; Abbruch
- If Stop
- Break
- EndIf
- Wend
- FinishDirectory(ID)
- EndIf
- ProcedureReturn ListSize(FileInfo())
- EndProcedure
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement