@@ -142,14 +142,22 @@ private static string GetBetween(string Source, string Start, string End) {
142
142
// fallback volume is the volume spotify should be set to if an error ever occurs and spotify gets stuck at no volume
143
143
private static float FallbackVolume = 100f ;
144
144
145
+ // if AdRework should always run all functions even if all related settings are disabled (more of a debug setting)
146
+ private static bool ForceRun = false ;
147
+
148
+ // ms interval AdRework should check for ads at
149
+ private static int AdInterval = 100 ;
150
+ // ms interval AdRework should perform an 'integrity check' at
151
+ private static int IntegrityInterval = 450 ;
152
+
145
153
private static void LoadConfiguration ( ) {
146
154
try {
147
155
string AppData = Environment . GetFolderPath ( Environment . SpecialFolder . ApplicationData ) ;
148
156
149
157
if ( ! Directory . Exists ( $ "{ AppData } \\ dmbk") ) Directory . CreateDirectory ( $ "{ AppData } \\ dmbk") ;
150
158
if ( ! Directory . Exists ( $ "{ AppData } \\ dmbk\\ AdRework") ) Directory . CreateDirectory ( $ "{ AppData } \\ dmbk\\ AdRework") ;
151
159
if ( ! File . Exists ( $ "{ AppData } \\ dmbk\\ AdRework\\ config.ini") ) {
152
- File . WriteAllText ( $ "{ AppData } \\ dmbk\\ AdRework\\ config.ini", "SkipAds='True'\n MuteAds='True'\n BypassAds='True'\n ImmediateSkip='True'\n RegistryStartup='True'\n FallbackVolume='50'" ) ;
160
+ File . WriteAllText ( $ "{ AppData } \\ dmbk\\ AdRework\\ config.ini", "SkipAds='True'\n MuteAds='True'\n BypassAds='True'\n ImmediateSkip='True'\n RegistryStartup='True'\n ForceRun='False' \ n FallbackVolume='50' \n AdInterval='100' \n IntegrityInterval='450 '" ) ;
153
161
return ; }
154
162
155
163
try {
@@ -160,27 +168,29 @@ private static void LoadConfiguration() {
160
168
BypassAds = bool . Parse ( GetBetween ( config , "BypassAds='" , "'" ) ) ;
161
169
ImmediateSkip = bool . Parse ( GetBetween ( config , "ImmediateSkip='" , "'" ) ) ;
162
170
RegistryStartup = bool . Parse ( GetBetween ( config , "RegistryStartup='" , "'" ) ) ;
163
- FallbackVolume = Convert . ToInt32 ( GetBetween ( config , "FallbackVolume='" , "'" ) ) ; }
171
+ ForceRun = bool . Parse ( GetBetween ( config , "ForceRun'" , "'" ) ) ;
172
+ FallbackVolume = Convert . ToInt32 ( GetBetween ( config , "FallbackVolume='" , "'" ) ) ;
173
+ AdInterval = Convert . ToInt32 ( GetBetween ( config , "AdInterval='" , "'" ) ) ;
174
+ IntegrityInterval = Convert . ToInt32 ( GetBetween ( config , "IntegrityInterval='" , "'" ) ) ; }
164
175
catch ( Exception ) { // if reading config fails, reset it
165
176
Console . WriteLine ( "failed to read config!" ) ;
166
- File . WriteAllText ( $ "{ AppData } \\ dmbk\\ AdRework\\ config.ini", "# CONFIG RESET DUE TO LOADING ERROR \n SkipAds ='True'\n MuteAds='True'\n BypassAds='True'\n ImmediateSkip='True'\n RegistryStartup='True'\n FallbackVolume='50'" ) ; }
177
+ File . WriteAllText ( $ "{ AppData } \\ dmbk\\ AdRework\\ config.ini", "SkipAds ='True'\n MuteAds='True'\n BypassAds='True'\n ImmediateSkip='True'\n RegistryStartup='True'\n ForceRun='False' \ n FallbackVolume='50' \n AdInterval='100' \n IntegrityInterval='450 '" ) ; }
167
178
} catch ( Exception ) { } }
168
179
169
180
private static void IntegrityCheck ( object sender , EventArgs e ) {
170
181
Process Spotify = Process . GetProcessesByName ( "Spotify" ) . FirstOrDefault ( p => ! string . IsNullOrWhiteSpace ( p . MainWindowTitle ) ) ;
171
- Console . WriteLine ( GetApplicationVolume ( Spotify . Id ) ) ;
172
182
if ( GetAdStatus ( ) == SpotifyAdStatus . None && GetApplicationVolume ( Spotify . Id ) <= 0 ) SetApplicationVolume ( Spotify . Id , FallbackVolume / 100 ) ; }
173
183
174
184
private static void AdReworkStart ( ) {
175
185
// load config
176
186
LoadConfiguration ( ) ;
177
- if ( ! SkipAds && ! MuteAds && ! BypassAds ) Process . GetCurrentProcess ( ) . Kill ( ) ; // terminate if it has nothing to do
187
+ if ( ! SkipAds && ! MuteAds && ! BypassAds && ! ForceRun ) Process . GetCurrentProcess ( ) . Kill ( ) ; // terminate if it has nothing to do
178
188
179
189
// start timer checking for ads every 100ms
180
- Timer timer = new Timer ( 100 ) ; timer . Elapsed += AutoAntiAd ; timer . AutoReset = true ; timer . Start ( ) ;
190
+ Timer timer = new Timer ( AdInterval ) ; timer . Elapsed += AutoAntiAd ; timer . AutoReset = true ; timer . Start ( ) ;
181
191
// make sure program isnt muted during songs every 235ms
182
- if ( FallbackVolume > 0 ) {
183
- Timer integritycheck = new Timer ( 235 ) ; integritycheck . Elapsed += IntegrityCheck ; integritycheck . AutoReset = true ; integritycheck . Start ( ) ; }
192
+ if ( FallbackVolume > 0 || ForceRun ) {
193
+ Timer integritycheck = new Timer ( IntegrityInterval ) ; integritycheck . Elapsed += IntegrityCheck ; integritycheck . AutoReset = true ; integritycheck . Start ( ) ; }
184
194
185
195
// set program to start with windows
186
196
CreateShortcut ( ) ;
0 commit comments