Quantcast
Channel: AutoIt v3 - General Help and Support
Viewing all articles
Browse latest Browse all 12506

How to check a file for values?

$
0
0
Hi thar,

I have a file, to be more specific, a config file from Counter-Strike (any version), which I need to check for certain values.
For example, I have this file:


unbindall
bind "0" "slot10"
bind "a" "buy hegrenade"
bind "k" "+voicerecord"
bind "q" "buy awp; buy flashbang; buy defuser; buy hegrenade; buy smokegrenade; buy vesthelm; buy flashbang; buy vest"
cl_righthand "0"
alias +cjump "+jump; +duck"
cl_rumblescale "1.0"
cl_debugrumble "0"
cl_detail_avoid_recover_speed "0.25"
cl_logofile "materials/vgui/logos/spray.vtf"
exec autoexec.cfg


So, I have the following patterns:
command
command "+a"
command "-a"
command "a"
command "a b; c d; e f; g h"
command "a" "b"
command a
command a "b; c; d"

Now what I want to do is, to check for certain values. For example, if "cl_righthand" is "0" or "1".
What I did so far is to specify a "ruleset", e.g.:

[ autoit ]      
$cvarHashMap = ObjCreate("Scripting.Dictionary") $cvarHashMap.add('mat_specular=mat_bumpmap', '0/1') $cvarHashMap.add('net_graph', '0/1') $cvarHashMap.add('cl_pitchspeed', '225') $cvarHashMap.add('cl_yawspeed', '210') $cvarHashMap.add('r_proplightingfromdisk', '0/1') $cvarHashMap.add('mat_dxlevel', '80/81/90/95/98')

With some regular expressions I try to get the values from various patterns:

[ autoit ]         
;; BIND cmds ;$bindRegExp = StringRegExpReplace($cfgIncoming, '(\n|^)((?<=)bind)(\s|\t)("?\S+"?)(\s|\t)("?.+"?)', '`~bind~´$2 $4 $6' & @CRLF) ;$bindCmd_Array = StringRegExp($bindRegExp, '`~bind~´(.+)' & @CRLF, 3) ;; ALIAS cmds ;$aliasRegExp = StringRegExpReplace($cfgIncoming, '(\n|^)((?<=)alias)(\s|\t)("?\S+"?)(\s|\t)("?.+"?)', '`~alias~´$2 $4 $6' & @CRLF) ;$aliasCmd_Array = StringRegExp($aliasRegExp, '`~alias~´(.+)' & @CRLF, 3) ;; COMMENT cmds ;$commentRegExp = StringRegExpReplace($cfgIncoming, '(/{2})(.+)', '`~comment~´$1 $2') ;$commentCmd_Array = StringRegExp($commentRegExp, '`~comment~´(.+)', 3) ;; SINGLE cmds ;$singleRegExp = StringRegExpReplace($cfgIncoming, '(\n|^)(\w+)(\r|\n|$)', '`~single~´$2' & @CRLF) ;$singleCmd_Array = StringRegExp($singleRegExp, '`~single~´(.+)' & @CRLF, 3) ;; NORMAL cmds ;$normalRegExp = StringRegExpReplace($cfgIncoming, '[\n|^]([\w+]{5,}?)(\s|\t)+"(.+)?"([^*])', '`~normal~´$1 $3' & @CRLF) ;$normalCmd_Array = StringRegExp($normalRegExp, '`~normal~´(.+)' & @CRLF, 3) ;; TWO VALUES FOR ONE VAR cmds ;$twovalsRegExp = StringRegExpReplace($cfgIncoming, '[\n|^]([\w+]{5,}?)(\s|\t)+"(.+)?"(\s|\t)+"(.+)?"([^*])', '`~twovals~´$1 $3 $5' & @CRLF) ;$twovalsCmd_Array = StringRegExp($twovalsRegExp, '`~twovals~´(.+)' & @CRLF, 3)

As I'm not that experienced in programming, I now wonder:
1. Is that the right way to do what I want to do?
2. Is there a better way?
3. How would you do it?

It feels a bit wrong the way I'm trying to manage this and I appreciate any hints and/or suggestions on doing this.

- 4cc

Viewing all articles
Browse latest Browse all 12506

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>