1- convert_legacy () {
2- ui_print " Old ViPER4Android folder detected at: $FOL !"
3- ui_print " If new preset already exists, it will be skipped"
4- ui_print " "
5-
6- mkdir -p $FOL /Preset 2> /dev/null
7- . $MODPATH /common/keys.sh
8- for i in " bt_a2dp.xml" " headset.xml" " usb_device.xml" ; do
9- cp -f $MODPATH /common/blanks/default.xml $MODPATH /common/blanks/$i
10- done
11-
12- find $FOL /Profile -mindepth 1 -maxdepth 1 -type d 2> /dev/null | while read PROFILE; do
13- ui_print " Converting $( basename " $PROFILE " ) "
14- for DEVICE in bluetooth headset speaker usb; do
15- case $DEVICE in
16- bluetooth) DEST=" $FOL /Preset/$( basename " $PROFILE " ) -$DEVICE /bt_a2dp.xml" ;;
17- headset) DEST=" $FOL /Preset/$( basename " $PROFILE " ) -$DEVICE /headset.xml" ;;
18- speaker) DEST=" $FOL /Preset/$( basename " $PROFILE " ) -$DEVICE /speaker.xml" ;;
19- usb) DEST=" $FOL /Preset/$( basename " $PROFILE " ) -$DEVICE /usb_device.xml" ;;
20- esac
21- for FORMAT in txt xml; do
22- if [ " $FORMAT " == " xml" ]; then
23- SOURCE=" $PROFILE /com.vipercn.viper4android_v2.$DEVICE .xml"
24- DEST=" $( echo " $DEST " | sed " s|-$DEVICE |-$DEVICE -Legacy|" ) "
25- [ -f " $SOURCE " ] || continue
26- [ -d " $( dirname " $DEST " ) " ] && { ui_print " New $( basename $DEVICE ) preset already exists! Skipping..." ; continue ; }
27- [ " $( head -n1 " $SOURCE " ) " == " <?xml version='1.0' encoding='utf-8' standalone='yes' ?>" ] || { ui_print " $( basename " $PROFILE " ) $( basename $DEVICE ) profile bugged! Skipping!" ; continue ; }
28- else
29- SOURCE=" $PROFILE /$DEVICE .txt"
30- [ -f " $SOURCE " ] || continue
31- [ -d " $( dirname " $DEST " ) " ] && { ui_print " New $( basename $DEVICE ) preset already exists! Skipping..." ; continue ; }
32- [ " $( head -n1 " $SOURCE " ) " == " <?xml version='1.0' encoding='utf-8' standalone='yes' ?>" ] && { ui_print " $( basename " $PROFILE " ) $( basename $DEVICE ) profile bugged! Skipping!" ; continue ; }
33- fi
34- [ " $FORMAT " == " xml" ] && ui_print " Creating new $DEVICE -legacy profile..." || ui_print " Creating new $DEVICE profile..."
35- mkdir " $( dirname " $DEST " ) " 2> /dev/null
36- cp -f $MODPATH /common/blanks/$( basename " $DEST " ) " $DEST "
37- while read LINE; do
38- [ " $( echo " $LINE " | grep ' ddcblock' ) " ] && continue # Skip ddcblock lines - not used and just slow down script
39- if [ " $FORMAT " == " xml" ]; then
40- case " $LINE " in
41- * " string name=" * ) VALUE=" $( echo " $LINE " | sed -r -e " s|.*>(.*)</.*|\1|" -e " s/FILE://" ) " ; LINE=" $( echo " $LINE " | sed -r -e " s|.*name=\" viper4android.[A-Za-z]*\.(.*)\" .*|\1|" -e " s/viperddc/ddc/" -e " s/\./_/g" ) " ;;
42- * " boolean name=" * ) VALUE=" $( echo " $LINE " | sed -r " s|.*value=\" (.*)\" />.*|\1|" ) " ; LINE=" $( echo " $LINE " | sed -r -e " s|.*name=\" viper4android.[A-Za-z]*\.(.*)\" v.*|\1|" -e " s/viperddc/ddc/" -e " s/\./_/g" ) " ;;
43- * ) continue ;;
44- esac
45- # Change speaker entry names
46- [ " $DEVICE " == " speaker" ]&& { case " $LINE " in
47- convolver* |fet* |fireq* |limiter|outvol|playback* |reverb* ) LINE=" speaker_$LINE " ;;
48- esac ; }
49- # Change dynamicsystem_bass
50- [ " $LINE " == " dynamicsystem_bass" ] && VALUE=$(( VALUE * 20 + 100 ))
51- else
52- case " $LINE " in
53- [A-Z-a-z.]* ) VALUE=" $( echo " $LINE " | sed -e " s|^.*=||" -e " s/FILE://" ) " ; LINE=" $( echo " $LINE " | sed -e " s|=.*$||" -e " s/viperddc/ddc/" -e " s/\./_/g" ) " ;;
54- * ) continue ;;
55- esac
56- # Change speaker entry names
57- [ " $DEVICE " == " speaker" -a " $LINE " == " speaker_enable" ] && LINE=enable
58- # Change vse value
59- [ " $LINE " == " vse_value" ] && { VALUE=" $( echo $VALUE | sed " s/;.*//" ) " ; VALUE=$( awk -v VALUE=$VALUE ' BEGIN{VALUE=(VALUE/5.6); print VALUE;}' ) ; }
60- fi
61- # Change names
62- case " $LINE " in
63- * fireq) continue ;;
64- * fireq_custom) LINE=" $( echo $LINE | sed " s/_custom//" ) " ;;
65- dynamicsystem_coeffs) LINE=dynamicsystem_device;;
66- dynamicsystem_bass) LINE=dynamicsystem_strength;;
67- tube_enable) LINE=tube_simulator_enable;;
68- channelpan) LINE=gate_channelpan;;
69- * limiter) LINE=gate_limiter;;
70- * outvol) LINE=gate_outputvolume;;
71- * reverb* ) LINE=" $( echo $LINE | sed -e " s/reverb_/reverberation_/" -e " s/roomwidth/room_width/" ) " ;;
72- * fetcompressor* ) LINE=" $( echo $LINE | sed " s|fetcompressor_|fet_|" ) " ;;
73- vhs_qual) LINE=vhs_quality;;
74- fidelity_bass_freq) LINE=fidelity_bass_frequency;;
75- spkopt_enable|speaker_optimize) LINE=speaker_optimization;;
76- esac
77- case " $LINE " in
78- fidelity_bass_mode|fidelity_clarity_mode|ddc_device|* fireq|* convolver_kernel|dynamicsystem_device)
79- VALUE=" $( basename " $VALUE " ) "
80- [ " $LINE " == " ddc_device" -o " $LINE " == " convolver_kernel" ] && [ " $VALUE " ] && [ $VALUE -eq $VALUE ] 2> /dev/null && VALUE=" $( grep " $VALUE " $MODPATH /common/VDCIndex.txt | sed -r " s/^[0-9]*=\" (.*)\" /\1/" ) .vdc"
81- LINE=" $( eval echo \$ $LINE ) "
82- sed -i " /$LINE / s|>.*</string>|>$VALUE </string>|" " $DEST " ;;
83- * ) LINE=" $( eval echo \$ $LINE ) "
84- if [ -z $LINE ]; then
85- continue
86- else
87- # Convert to integer
88- case " $VALUE " in
89- [0-9]* .[0-9]* ) VALUE=$( awk -v VALUE=$VALUE ' BEGIN{VALUE=(VALUE*100); print VALUE;}' ) ;;
90- [0-9]* \; [0-9]* ) VALUE=" $( echo $VALUE | sed " s/;.*//" ) " ;; # colorfulmusic_coeffs
91- esac
92- # Round to Tenth place due to profile saving bug in original v4a
93- case " $LINE " in
94- * reverberation_room* ) VALUE=$( awk -v VALUE=$VALUE ' BEGIN{VALUE = sprintf("%1.0e\n",VALUE); printf "%d\n", VALUE}' ) ;;
95- esac
96- sed -i " /$LINE / s|value=\" .*\" |value=\" $VALUE \" |" " $DEST "
97- fi ;;
98- esac
99- done < " $SOURCE "
100- done
101- done
102- done
103- }
104-
105- convert () {
106- if [ " $1 " != " -s" ]; then
107- ui_print " Old ViPER4Android folder detected at: $FOL !"
108- ui_print " If new preset already exists, it will be skipped"
109- ui_print " "
110- fi
111-
112- find $FOL /Preset -mindepth 2 -maxdepth 2 -type f 2> /dev/null | while read PRESET; do
113- NEWPRESET=" $FOL /Preset/$( basename " ` dirname " $PRESET " ` " ) -$( basename " $PRESET " ) "
114- [ -f " $NEWPRESET " ] && continue
115- [ " $1 " != " -s" ] && ui_print " Converting $( basename " ` dirname " $PRESET " ` " ) "
116- cp -f " $PRESET " " $NEWPRESET "
117-
118- # Convert values
119- [ " $( basename " $PRESET " ) " == " speaker.xml" ] && sed -i ' \|^</map>$|i <int name="32775" value="2" />' " $NEWPRESET " || sed -i ' \|^</map>$|i <int name="32775" value="1" />' " $NEWPRESET "
120- local math value count
121- for key in 65587 65554 65555 65556 65558 65560 65561 65573 65576 65577 65580 65586 65588 65608 65609 65566 65605 65567 65606 65568 65607; do
122- unset math; count=0
123- value=$( sed -n " /int name=\" $key \" /p" " $NEWPRESET " | sed -r " s/.*value=\" ([0-9]*)\" .*/\1/" )
124- [ -z $value ] && continue
125- case " $key " in
126- 65587) math=" ($value + 100) / 2" ;; # Limiter - channelPan
127- 65554|65555) math=" ($value - 120) / 10" ;; # FieldSurround - width, midImage
128- 65556) math=" ($value - 200) / 75" ;; # FieldSurround - depth
129- 65558) math=" $value / 100 - 1" ;; # DifferentialSurround - strength
130- 65560|65561|65598|65599) math=" $value / 10" ;; # Speaker/Reverberation - roomSize, roomWidth
131- 65573) math=" ($value - 100) / 20" ;; # DynamicSystem - strength
132- 65576) math=" $value - 15" ;; # ViPERBass - cutOffFrequency
133- 65577) math=" ($value - 50) / 50" ;; # ViPERBass - strength
134- 65580) math=" $value / 50" ;; # ViPERClarity - strength
135- 65586|65608)
136- for i in 1 5 10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160 170 180 190 200; do
137- [ $value -eq $i ] && { math=$count ; break ; }
138- count=$(( count + 1 ))
139- done
140- ;; # Speaker/Limiter - Output gain, Speaker/Playback gain control - Output threshold
141- 65588|65609|65568|65607)
142- for i in 30 50 70 80 90 100; do
143- [ $value -eq $i ] && { math=$count ; break ; }
144- count=$(( count + 1 ))
145- done
146- ;; # Speaker/Limiter - Threshold limit
147- 65566|65605)
148- for i in 50 100 300; do
149- [ $value -eq $i ] && { math=$count ; break ; }
150- count=$(( count + 1 ))
151- done
152- ;; # Speaker/Playback gain control - Strength
153- 65567|65606)
154- for i in 100 200 300 400 500 600 700 800 900 1000 3000; do
155- [ $value -eq $i ] && { math=$count ; break ; }
156- count=$(( count + 1 ))
157- done
158- ;; # Speaker/Playback gain control - Maximum gain
159- esac
160- [ " $math " ] || math=0
161- value=$(( $math ))
162- sed -ri " /int name=\" $key \" / s/(value=\" )[0-9]*\" /\1$value \" /" " $NEWPRESET "
163- done
164- done
165- }
166-
167- profile_convert () {
168- ui_print " - Converting old profiles to new format..."
169- if [ " $( find $FOL /Preset -type d -mindepth 1 -maxdepth 1 2> /dev/null) " ]; then
170- convert
171- elif [ " $( ls -A $FOL /Profile 2> /dev/null) " ]; then
172- convert_legacy
173- convert -s
174- else
175- ui_print " - No old profiles found, nothing to convert"
176- return
177- fi
178- }
1791
1802[ " ` getenforce` " == " Enforcing" ] && ENFORCE=true || ENFORCE=false
1813FOL=" /storage/emulated/0/ViPER4Android"
@@ -184,19 +6,9 @@ NEWFOL="/storage/emulated/0/Android/data/com.pittvandewitt.viperfx/files"
1846# Backup existing presets
1857[ -d " $NEWFOL " ] && cp -rf $NEWFOL /* $FOL /
1868
187- # Uninstall existing v4a installs
188- ui_print " - Removing old v4a app installs..."
189- for i in $( find /data/app -maxdepth 1 -type d -name " *com.pittvandewitt.viperfx*" -o -name " *com.audlabs.viperfx*" -o -name " *com.vipercn.viper4android_v2*" ) ; do
190- case " $i " in
191- * " com.pittvandewitt.viperfx" * ) pm uninstall com.pittvandewitt.viperfx > /dev/null 2>&1 ;;
192- * " com.audlabs.viperfx" * ) pm uninstall com.audlabs.viperfx > /dev/null 2>&1 ;;
193- * " com.vipercn.viper4android" * ) pm uninstall com.vipercn.viper4android_v2 > /dev/null 2>&1 ;;
194- esac
195- done
196- # Remove remnants of any old v4a installs
197- for i in $( find /data/data -maxdepth 1 -name " *ViPER4AndroidFX*" -o -name " *com.audlabs.viperfx*" -o -name " *com.vipercn.viper4android_v2*" ) ; do
198- rm -rf $i 2> /dev/null
199- done
9+ # Uninstall v4a app if installed
10+ VIPERFXPACKAGE=" com.pittvandewitt.viperfx"
11+ [ -n " $( pm list packages | grep " $VIPERFXPACKAGE " ) " ] && pm uninstall " $VIPERFXPACKAGE " > /dev/null 2>&1
20012
20113# Tell user aml is needed if applicable
20214FILES=$( find $NVBASE /modules/* /system $MODULEROOT /* /system -type f -name " *audio_effects*.conf" -o -name " *audio_effects*.xml" 2> /dev/null | sed " /$MODID /d" )
@@ -209,9 +21,6 @@ if [ ! -z "$FILES" ] && [ ! "$(echo $FILES | grep '/aml/')" ]; then
20921 sleep 3
21022fi
21123
212- # Convert old profiles to new presets
213- profile_convert
214-
21524# Copy to new scoped storage directory
21625ui_print " "
21726ui_print " - Placing Files to New Directory:"
@@ -268,13 +77,3 @@ $ENFORCE && setenforce 1
26877
26978# Install temporary service script
27079install_script -l $MODPATH /common/service.sh
271-
272-
273- REMS=$( find $NVBASE /modules/* /system $MODULEROOT /* /system -type f -name " ViPER4AndroidFX.apk" 2> /dev/null)
274- if [ " $REMS " ]; then
275- ui_print " - Marking all old v4a modules for deletion..."
276- for i in ${REMS} ; do
277- i=" $( echo " $i " | sed " s|/system/.*|/|" ) "
278- touch $i /remove
279- done
280- fi
0 commit comments