📄 install.inc
字号:
} elseif($this->my_dir_exists($file)){ $this->logger->log ("Backing-up directory: $file"); $this->my_move($file, $file.$this->conf['backup_suffix'], true); $new_file = $file.$this->conf['backup_suffix']; } return isset($new_file) ? $new_file : null; } // MY_FNMATCH function my_fnmatch($pattern, $file) { if(function_exists('fnmatch')) { return fnmatch ($pattern, $file); } $lenpattern = strlen($pattern); $lenfile = strlen($file); for($i=0 ; $i<$lenpattern ; $i++) { if($pattern[$i] == "*") { for($c=$i ; $c<max($lenpattern, $lenfile) ; $c++) { if($this->my_fnmatch(substr($pattern, $i+1), substr($file, $c))) return true; } return false; } if($pattern[$i] == "[") { $letter_set = array(); for($c=$i+1 ; $c<$lenpattern ; $c++) { if($pattern[$c] != "]") array_push($letter_set, $pattern[$c]); else break; } foreach($letter_set as $letter) { if($this->my_fnmatch($letter.substr($pattern, $c+1), substr($file, $i))) return true; } return false; } if($pattern[$i] == "?") continue; if($pattern[$i] != $file[$i]) return false; } if(($lenpattern != $lenfile) && ($pattern[$i - 1] == "?")) return false; return true; } // MY_SCANDIR function my_scandir($dir) { $files = array(); if($this->my_dir_exists ($dir)) { $fh = opendir($dir); while (false !== ($filename = readdir($fh))) { array_push($files, $filename); } closedir($fh); } return $files; } // FIND_FILE function find_file($dir, $pattern, $ret_arr=null) { $num_files = 0; if($this->my_dir_exists ($dir)) { $files = preg_grep ("/^\.+$/", $this->my_scandir ($dir), PREG_GREP_INVERT);; foreach ($files as $file) { $num_files += $this->find_file ($this->make_path($dir, $file), $pattern, $ret_arr); } } else if($this->my_file_exists ($dir)) { if($this->my_fnmatch($pattern, basename($dir))) { if(is_array($ret_arr)) { array_push ($ret_arr, $dir); } return 1; } } return $num_files; } // FILECMP function filecmp($file1, $file2) { return strcmp(file2str($file1), file2str($file2)); } // STR2FILE function str2file($str , $file) { $fp = $this->my_fopen($file, "w"); $ret = fwrite($fp, $str); fclose($fp); return $ret; } // FILE_WORD_WRAP function file_word_wrap($file) { $this->logger->log ("Wrapping text from file: $file"); $tmp_file = $this->conf['tmp_dir'].$this->conf['slash'].basename($file).".wrapped"; $this->str2file(wordwrap($this->file2str($file), $this->conf['wrap_size']), $tmp_file); return $tmp_file; } // MY_OPENDIR function my_opendir($path) { if(!$this->my_dir_exists($path)){ $this->on_error("No such directory: $path"); } $dir = $this->run_silently("opendir", $path); if(empty($dir)){ $this->on_error("Cannot open directory: $path for reading"); } return $dir; } // PUSHD function pushd($dir) { $cwd = getcwd(); if(empty($cwd)){ $this->on_error("Unable to store the current working directory."); } if(!isset($this->conf['cwd'])) { $this->conf['cwd'] = array(); } array_push($this->conf['cwd'], $cwd); $this->my_chdir($dir); } // POPD function popd() { if(!isset($this->conf['cwd'])) { $error = "Current directory is not stored"; } $cwd = array_pop($this->conf['cwd']); if(!chdir($cwd)){ $error = "Can't change directory to: $cwd"; } if(isset($error)) { $this->on_error("Unable to restore the current working directory.\n$error"); } } // MY_CHDIR function my_chdir($dir, $log=false) { if ($log) { $this->logger->log ("Changing directory to: $dir"); } if(!chdir($dir)){ $this->on_error("Unable to change directory to: $dir"); } } // GET_FILE_TREE function get_file_tree($dir, &$file_tree) { $totalsize = 0; $file_tree = array(); $this->get_file_tree_a($dir, $file_tree, $totalsize); return $totalsize; } function get_file_tree_a($path, &$file_tree, &$totalsize) /* returns number of files */ { $dir = $this->my_opendir($path); $num_files = 0; while($file = readdir($dir)){ if($file != "." && $file != ".."){ if($this->my_file_exists("$path/$file")){ $size = filesize($path.$this->conf['slash'].$file); $file_tree[$path.$this->conf['slash'].$file] = $size; $totalsize += $size; } elseif($this->my_dir_exists($path.$this->conf['slash'].$file)){ if($this->get_file_tree_a($path.$this->conf['slash'].$file, $file_tree, $totalsize)==0){ $file_tree[$path.$this->conf['slash'].$file] = 0; /* if directory is empty put it into components array */ } } $num_files ++; } } closedir($dir); return $num_files; } // ------------------------------ // DIALOG FUNCTIONS // ============================== // MY_READLINE function my_readline($msg = "[To continue, press Enter]") { print($msg); flush(); if($this->conf['interactive']) { exec("read OUTPUT\necho \$OUTPUT", $output); } print ("\n"); return isset($output[0]) ? $output[0] : ""; } // RUNDIALOG function rundialog($mode, $msg, $extra_args=null) { $this->progress_bar_stop(); $command = $this->conf['dialog']; # Strip not always displayable HTML and PHP tags: $msg = strip_tags ($msg); # remove ascii escape sequences(not suitable for dialog) $msg = preg_replace('/\\033[0-9;\[]*m/', '', $msg); # If message is empty escapeshellarg() returns empty string, instead of expected '' $msg = strlen($msg) ? $msg : " "; switch($mode) { case 'fselect': case 'msgbox': case 'inputbox': case 'passwordbox': case 'noyes': if($mode == "noyes") { $command .= " --defaultno "; $mode = "yesno"; } case 'yesno': case 'infobox': if ($mode == "infobox") $command .= " --sleep 1 "; case 'menu': case 'checklist': $command .= sprintf(" --%s %s 0 0", $mode, escapeshellarg("{$msg}\n")); break; case 'textbox': $command .= sprintf(" --%s %s 0 0", $mode, escapeshellarg($msg)); break; default: print("Unsupported dialog option\n"); return(''); } if (is_array ($extra_args)) { foreach ($extra_args as $arg) { $arg = strlen($arg) ? $arg : " "; $command .= " ".escapeshellarg ($arg); } } else if ($extra_args !== null) { $extra_args = strlen($extra_args) ? $extra_args : " "; $command .= " ".escapeshellarg ($extra_args); } $rc = $this->dialog_execute($command); if((($mode == 'passwordbox') || ($mode == 'inputbox')) && ($rc>0)) { // Cancel pressed. return -1; } $dialog_output = $this->dialog_get_output(); if(preg_match ('/Error opening terminal/', $dialog_output)) { unset($this->conf['dialog']); $this->on_error($this->conf['dialog_error']); } return($mode == 'yesno' ? 1 - $rc : $dialog_output); } function floating_box($msg) { } // MSGBOX function msgbox($msg) { $this->progress_bar_stop(); $this->logger->log ("MSGBOX: \n\"$msg\""); if(!empty($this->conf['dialog'])){ $this->rundialog("msgbox", "\n{$msg}"); } else{ print("\n$msg\n"); $this->my_readline(); } } // INPUTBOX function inputbox($msg, $init="", $accept_empty=false, $show_empty_msg=true) { $this->progress_bar_stop(); $this->logger->log ("ASK: $msg"); do { if(!empty($this->conf['dialog'])){ while(true) { if ($show_empty_msg && $accept_empty && $init == "") { $msg .= "\n\nPress OK to leave empty."; } $input = $this->rundialog("inputbox", "\n{$msg}", $init); if(!$accept_empty && $input == -1) { $this->on_abort(); continue; } break; } } else{ // replace last ':' if it exits and trim : $msg = preg_replace("/\:\s*$/", "", $msg); if($show_empty_msg && $accept_empty && $init == ""){ $init = "Press ENTER to leave empty"; } $prompt = "{$msg}: "; if (!empty ($init)) { if (preg_match ('/\n$/', $msg)) { $prompt = "{$msg}[{$init}]: "; } else { $prompt = "{$msg} [{$init}]: "; } } $input = $this->my_readline ($prompt); if($input == "" && $init != "Press ENTER to leave empty") { $input = $init; } } $this->logger->log ("INPUTBOX: $input"); } while((empty($input) || preg_match("/^\s*$/", $input)) && !$accept_empty); $input = trim($input); /* trim the line */ $input = addslashes($input); /* add the back slashes to illegal characters */ return $input; } // INPUTBOX_BOUNDED function inputbox_bounded($msg, $what, $min_chars, $max_chars, $init="", $accept_empty=false) { while(true) { $output = $this->inputbox($msg, $init, $accept_empty); if(strlen($output) < $min_chars) { $this->msgbox("A $what should contain at least $min_chars characters. Please try again."); continue; } if(strlen($output) > $max_chars) { $this->msgbox("A $what should contain at most $max_chars characters. Please try again."); continue; } break; } return $output; } // YESNOBOX function yesnobox($msg, $defaultno=false, $abort_on_no=false) { $this->progress_bar_stop(); $this->logger->log ("YESNO: $msg"); $answer = false; $default = ($defaultno ? "NO" : "YES"); while(true) { if(!empty($this->conf['dialog'])){ if($defaultno) { $answer = $this->rundialog("noyes", "\n{$msg}"); } else { $answer = $this->rundialog("yesno", "\n{$msg}"); } } else{ print("\n$msg\n"); do{ $output = $this->my_readline("Answer (yes or no) [$default]: "); if(preg_match("/^\s*$/", $output)){ $output = $default; } if(strcasecmp($output, "yes") == 0 || strcasecmp($output, "y") == 0){ $answer = true; break; } if(strcasecmp($output, "no") == 0 || strcasecmp($output, "n") == 0){ $answer = false; break; } }while(true); } if($abort_on_no && !$answer) { $this->on_abort(); continue; } print("\n"); break; } $result = $answer ? "YES" : "NO"; $this->logger->log ("User choose: $result"); return $answer; } // INFOBOX function infobox($msg) { $this->progress_bar_stop(); $this->logger->log ("INFOBOX: \n\"$msg\""); if(!empty($this->conf['dialog'])){ $this->rundialog("infobox", "\n{$msg}"); } else{ print("\n$msg\n\n"); } } // PASSWDBOX function passwdbox($msg, $accept_cancel=false) { $this->progress_bar_stop(); do{ if(!empty($this->conf['dialog'])){ while(true) { $passwd = $this->rundialog("passwordbox", $msg); if($passwd == -1 && !$accept_cancel) { $this->on_abort(); continue; } break; } }else{ print("\n$msg"); exec("stty -echo"); $passwd = $this->my_readline(""); exec("stty echo"); //print("\n"); } } while(empty($passwd) || preg_match("/^\s*$/", $passwd)); $this->logger->log ("PASSWDBOX: " . preg_replace ("/\w/", "X", $passwd)); return($passwd); } // PASSWORD_CHECK function password_check($passwd, $num_chars=4) { if(strlen($passwd) < $num_chars){ $this->msgbox("A password should contain at least $num_chars characters. Please try again."); return false; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -