; German forum: http://www.purebasic.fr/german/archive/viewtopic.php?t=5140&highlight= ; Author: Kooky (updated for PB 4.00 by Andre) ; Date: 22. July 2004 ; OS: Windows ; Demo: No ; Problem: Invalid memory access beim Beenden der Procedure StringSize(Size) OnErrorGoto(?Error) Enumeration #Window_Main EndEnumeration Enumeration #MenuBar_0 EndEnumeration Enumeration #MENU_Replace #MENU_Quit #MENU_About EndEnumeration Enumeration #Editor_Seach #Editor_Replace #Frame3D_Menu #Button_Replace #Text_C #Button_Quit #Combo_Pattern #Text_Pattern EndEnumeration Procedure Open_Window_Main() If OpenWindow(#Window_Main, 266, 166, 789, 336, "Quick Replacing Tool", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_TitleBar | #PB_Window_ScreenCentered ) If CreateMenu(#MenuBar_0, WindowID(#Window_Main)) MenuTitle("Datei") MenuItem(#MENU_Replace, "Ersetzten") MenuBar() MenuItem(#MENU_Quit, "Beenden") MenuTitle("?") MenuItem(#MENU_About, "About") EndIf If CreateGadgetList(WindowID(#Window_Main)) EditorGadget(#Editor_Seach, 10, 10, 300, 300) EditorGadget(#Editor_Replace, 320, 10, 300, 300) Frame3DGadget(#Frame3D_Menu, -10, -6, 2000, 2000, "") ButtonGadget(#Button_Replace, 630, 10, 150, 20, "Erstzen") TextGadget(#Text_C, 700, 300, 90, 15, "© 2004 by Kooky") ButtonGadget(#Button_Quit, 630, 40, 150, 20, "Beenden") ComboBoxGadget(#Combo_Pattern, 630, 90, 150, 80, #PB_ComboBox_LowerCase) TextGadget(#Text_Pattern, 630, 70, 150, 20, "Zu Erstetzende Dateien") EndIf EndIf EndProcedure Procedure StringSize(Size) PBStringBase.l = 0 PBMemoryBase.l = 0 !MOV eax, dword [PB_StringBase] !MOV [esp+4],eax !MOV eax, dword [PB_MemoryBase] !MOV [esp+8],eax HeapReAlloc_(PBMemoryBase, #GMEM_ZEROINIT, PBStringBase, Size) !MOV dword [_PB_StringBase],eax EndProcedure Procedure Init() Structure Daten Name.s Inhalt.s EndStructure Global NewList Files.Daten() AddGadgetItem(#Combo_Pattern, -1, "html") AddGadgetItem(#Combo_Pattern, -1, "htm") AddGadgetItem(#Combo_Pattern, -1, "txt") AddGadgetItem(#Combo_Pattern, -1, "") SetGadgetState(#Combo_Pattern, 0) AddGadgetItem(#Editor_Seach,0,"Hier kommt der Text rein, nachdem gesucht wird.") AddGadgetItem(#Editor_Replace,0,"Hier kommt der Text rein, der den gefundenen Text ersetzt.") EndProcedure Procedure ReadDirs(Path.s, Rek.l,Pattern.s) If Right(Path, 1) = "\" : Path = Left(Path, Len(Path) - 1) : EndIf NextOK.l Name.s ExamineDirectory(Rek, Path, "") Repeat NextOK = NextDirectoryEntry(Rek) Name = DirectoryEntryName(Rek) If NextOK = 2 And Name <> "." And Name <> ".." ReadDirs(Path + "\" + Name, Rek + 1,Pattern.s) ElseIf NextOK = 1 If LCase(GetExtensionPart(Name)) = Pattern.s Or Pattern.s = "" AddElement(Files()) Files()\Name = Name EndIf EndIf Until NextOK = #False EndProcedure Procedure Replace(Pattern.s,Search.s,Replace.s) ResetList(Files()) While NextElement(Files()) DeleteElement(Files()) Wend Count.l = 0 ReadDirs("",0,Pattern.s) ForEach Files() If OpenFile(0,Files()\Name) StringSize(Lof(0)) While Eof(0) = 0 Files()\Inhalt + ReadString(0) + Chr(13) +Chr(10) Wend CloseFile(0) : EndIf Next ForEach Files() If FindString(Files()\Inhalt,Search.s,0) If Search <> "" CreateDirectory("BAK") CopyFile(Files()\Name,"Bak\"+Files()\Name) Count.l + 1 Files()\Inhalt = ReplaceString(Files()\Inhalt,Search.s,Replace.s,1,0) If CreateFile(0,Files()\Name) WriteString(0,Files()\inhalt) CloseFile(0) EndIf EndIf EndIf Next MessageRequester("Info","Gefundene Dateien: "+Str(CountList(Files()))+Chr(13)+"Erstetzte Dateien: "+Str(count),#MB_ICONINFORMATION) EndProcedure Open_Window_Main() Init() Repeat Event = WaitWindowEvent() If Event = #PB_Event_Menu MenuID = EventMenu() If MenuID = #MENU_Replace Replace(GetGadgetText(#Combo_Pattern),GetGadgetText(#Editor_Seach),GetGadgetText(#Editor_Replace)) ElseIf MenuID = #MENU_Quit quit = 1 ElseIf MenuID = #MENU_About MessageRequester("Info","Quick Replacing Tool."+Chr(13)+"© 2004 by Kooky",#MB_ICONINFORMATION) EndIf EndIf If Event = #PB_Event_Gadget GadgetID = EventGadget() If GadgetID = #Button_Replace Replace(GetGadgetText(#Combo_Pattern),GetGadgetText(#Editor_Seach),GetGadgetText(#Editor_Replace)) ElseIf GadgetID = #Button_Quit quit = 1 EndIf EndIf Until Event = #PB_Event_CloseWindow Or quit = 1 End Error: If CreateFile(0,"Error.log") WriteString(0,GetErrorDescription()+Chr(13)+Chr(10)+"Line: "+Str(GetErrorLineNR()+1)+Chr(13)+Chr(10)+"Module: "+GetErrorModuleName()) CloseFile(0) EndIf MessageRequester("Error",GetErrorDescription()+Chr(13)+"Line: "+Str(GetErrorLineNR()+1)+Chr(13)+"Module: "+GetErrorModuleName()+Chr(13)+"Error.log has been created!",#MB_ICONSTOP) ; IDE Options = PureBasic v4.02 (Windows - x86) ; Folding = -