2016-07-23 95 views
0

我的保存功能,注意我不想知道更好的方法来保存它或更正我的保存代码,我只需要帮助我需要的部分自动删除其他非必需的部分/上产生的旧支架节省: 这里的保存按钮:AutoHotKey帮助,匹配字符并替换

buttonSave: 
FileAppend, 
(
nprocess,exist, %Input% 
nprocess,priority, %Input%, %PriorInput% 
} 
), C:\Users\%A_UserName%\Desktop\AutoSetup\Settings.ahk 
MsgBox, 0, Saved, %PriorInput% Priority to %Input% has been saved. 

我怎样才能得到AutoHotkey的找到}并删除任何匹配的字符},然后添加一个}在文件的最后,并有这个循环?

我有一个保存功能,输出是这样的:

loop 
{ 
process,exist, Steam.exe 
process,priority, Steam.exe, 
} 
process,exist, Steam.exe 
process,priority, Steam.exe, 
} 

我希望它找到结束}和中间}删除他们两个,然后在最后添加一个}。如果保存,它总是在底部添加一个括号。

+0

举例来说,如果我有这样的设置文件,保存一个新的项目,将补充一点: process,exists,something.exe process,priority,something.exe }因此,它会添加到当前代码我有 – Ethorbit

+0

如何显示一个非常简短的例子(几行)的前处理文件和后处理文件。 .. –

+0

现在正在做它 – Ethorbit

回答

1
buttonSave: 
FileRead, Contents, C:\Users\%A_UserName%\Desktop\AutoSetup\Settings.ahk 
if not ErrorLevel ; Successfully loaded 
{ 
    StringTrimRight, Contents, Contents, 1 ; remove the end } 
    FileAppend, %Contents%, C:\Users\%A_UserName%\Desktop\AutoSetup\Temp.ahk 
    Contents = ; Free the memory 
} 
FileAppend, 
(
process,exist, %Input% 
process,priority, %Input%, %PriorInput% 
} 
), C:\Users\%A_UserName%\Desktop\AutoSetup\Temp.ahk 
FileMove, C:\Users\%A_UserName%\Desktop\AutoSetup\Temp.ahk, C:\Users\%A_UserName%\Desktop\AutoSetup\Settings.ahk, 1 ; overwrite existing file 
; Run, edit C:\Users\%A_UserName%\Desktop\AutoSetup\Settings.ahk 
MsgBox, 0, Saved, %PriorInput% Priority to %Input% has been saved. 
; reload ; if Settings.ahk is included in this script 
return 
+0

非常感谢你,还没有尝试过,但它看起来很完美。 – Ethorbit

+0

它的工作原理!再次谢谢你! – Ethorbit

1

我会用这样的事情(的循环会导致高CPU使用率):

#NoEnv 
#SingleInstance Force 
#Persistent 

Menu, Tray, Add 
Menu, Tray, Add, Add Process, Add_Process 
Menu, Tray, Default, Add Process ; doubleclick the tray icon to add a new process 

SetTimer, set_priority, 500 
return 

set_priority: 
Process,exist, Notepad.exe 
Process,priority, Notepad.exe, L 
; Add Process 
return 

Add_Process: 
InputBox, ProcessName, ProcessName, Enter a Process. 
if !ErrorLevel 
InputBox, priority, priority, Enter a priority. 
if !ErrorLevel 
{ 
    text = 
    (  
    Process,exist, %ProcessName%.exe 
    Process,priority, %ProcessName%.exe, %priority% 
    ; Add Process 
    ) 
    FileRead, Contents, %A_ScriptFullPath% 
    if not ErrorLevel ; Successfully loaded 
    { 
     StringReplace, Contents, Contents, `; Add Process, %text% 
     FileAppend, %Contents%, %A_ScriptDir%\Temp.ahk 
     Contents = ; Free the memory 
    } 
    FileMove, %A_ScriptDir%\Temp.ahk, %A_ScriptFullPath%, 1 ; overwrite existing file 
    reload 
} 
return 
+0

不,我有一个全功能的方式要添加一个进程,我只需要知道如何找到保存的设置文件并删除保存时自动生成的额外括号。 – Ethorbit

+0

我现在编辑我的帖子,包括我的保存如何工作,我不认为我需要真正添加到整个GUI界面的流程添加尽管。 – Ethorbit