GetMessage() . PHP_EOL; } function parse_dir($dir) { $dh = opendir($dir); if ( !$dh ) { throw new Exception('could not open dir - ' . $dir); } while ( $file = readdir($dh) ) { if ( !preg_match('/\.ini$/', $file) ) { continue; } $path = $dir . '\\' . $file; modify_ini($path); } closedir($dh); } function modify_ini($path) { echo $path . PHP_EOL; $buf = file($path); if ( !count($buf) ) { return; } $cnt = 0; $is_in_section = false; foreach ($buf as &$str) { if ( $is_in_section ) { if ( strpos($str, '[') !== false ) { break; } if ( preg_match('/^(DirectLightingIntensity[^=]+)=([0-9\.]+)/', $str, $matches) ) { //echo $matches[1] . ' = ' . $matches[2] . PHP_EOL; $name = $matches[1]; $value = $matches[2]; if ($value >= 0.3) { $value_new = $value * 0.33; printf("%s: %s => %s" . PHP_EOL, $name, $value, $value_new); $str = $name . '=' . $value_new . PHP_EOL; $cnt++; } else if ($value >= 0.2) { $value_new = $value * 0.5; printf("%s: %s => %s" . PHP_EOL, $name, $value, $value_new); $str = $name . '=' . $value_new . PHP_EOL; $cnt++; } } } else { if ( strpos($str, '[ENVIRONMENT]') !== false ) { $is_in_section = true; } } } $is_in_section = false; foreach ($buf as &$str) { if ( $is_in_section ) { if ( strpos($str, '[') !== false ) { break; } if ( preg_match('/^(SpecularAmountMultiplier[^=]+)=([0-9\.]+)/', $str, $matches) ) { //echo $matches[1] . ' = ' . $matches[2] . PHP_EOL; $name = $matches[1]; $value = $matches[2]; if ($value != 0.3) { $value_new = 0.3; printf("%s: %s => %s" . PHP_EOL, $name, $value, $value_new); $str = $name . '=' . $value_new . PHP_EOL; $cnt++; } } } else { if ( strpos($str, '[OBJECT]') !== false ) { $is_in_section = true; } } } if ( $cnt >= 1 ) { write_ini($path, $buf); } } function write_ini($path, $buf) { $fp = fopen($path, 'w'); if ( !$fp ) { return; } foreach ($buf as $str) { fputs($fp, $str); } fclose($fp); }