Skip to content

Instantly share code, notes, and snippets.

@MrFiregore
Last active September 22, 2021 12:50
Show Gist options
  • Save MrFiregore/0ba76d74f070b07eda5a12f3f24ba054 to your computer and use it in GitHub Desktop.
Save MrFiregore/0ba76d74f070b07eda5a12f3f24ba054 to your computer and use it in GitHub Desktop.
jetbrains toolbox generator regex for windows
<?php
set_time_limit(0);
define("__ROOT__", realpath(__DIR__) . DIRECTORY_SEPARATOR);
ini_set("log_errors", 1);
ini_set("error_log", __ROOT__ . "php-error.log");
$script_dir = 'E:\Program Files (x86)\JetBrains\scripts';
function getAllFiles ($dir, $fileType = ['bmp', 'jpg', 'jpeg', 'gif', 'png'])
{
if (!is_dir($dir)) {
return false;
}
$files = [];
readFiles($dir, $files, $fileType);
// var_dump($files);
return $files;
}
function readFiles ($dir, &$files, $fileType = ['bmp', 'jpg', 'jpeg', 'gif', 'png'])
{
$handle = opendir($dir);
while (($file = readdir($handle)) !== false) {
if ($file == '.' || $file == '..')
continue;
$filePath = $dir == '.' ? $file : $dir . DIRECTORY_SEPARATOR . $file;
if (is_link($filePath)) {
contiune;
}
else if (is_dir($filePath)) {
readFiles($filePath, $files);
}
else {
$pathinfo = pathinfo($dir . DIRECTORY_SEPARATOR . $file);
$file_ext = isset($pathinfo['extension']) ? $pathinfo['extension'] : null;
if (!in_array($file_ext, $fileType)) {
continue;
}
if (strpos($file, '_cropface') === false) {
$files[] = $dir . DIRECTORY_SEPARATOR . $file;
}
}
}
closedir($handle);
}
$listFiles = getAllFiles(realpath($script_dir), ["cmd"]);
d(realpath($script_dir));
foreach ($listFiles as $file) {
$f = pathinfo($file);
$path = $file;
$name = $f["filename"];
$contents = file_get_contents($path);
$pattern = '/start\\s""\\s\\W\\w+\\W\\s"([a-zA-Z]:\\\\[\\\\S|*\\\\S]?.*)"/';
preg_match($pattern, $contents, $m);
$program_path = $m[1];
$skipped_path = str_replace("\\", "\\\\", $program_path);
preg_match('/apps\\\\([a-zA-Z]+)\\W?[a-zA-Z]?\\\\/', $program_path, $program_name);
$program_name = $program_name[1];
$reg_data = <<<EOL
Windows Registry Editor Version 5.00
; $program_name
; when you right click a folder while holding shift
[HKEY_CLASSES_ROOT\Directory\Background\shell\\$program_name]
@="Abrir directorio con $program_name"
"Icon"="$skipped_path,0"
[HKEY_CLASSES_ROOT\Directory\Background\shell\\$program_name\command]
@="$skipped_path \"%V\""
; when you right click a folder
[HKEY_CLASSES_ROOT\Directory\shell\\$program_name]
@="Abrir directorio con $program_name"
"Icon"="$skipped_path,0"
[HKEY_CLASSES_ROOT\Directory\shell\\$program_name\command]
@="$skipped_path \"%1\""
; when you right click a file
[HKEY_CLASSES_ROOT\*\shell\\$program_name]
@="Abrir fichero en $program_name"
"Icon"="$skipped_path,0"
[HKEY_CLASSES_ROOT\*\shell\\$program_name\command]
@="$skipped_path \"%1\""
; when you right click a folder
[HKEY_CLASSES_ROOT\Directory\shell\\$program_name]
@="Abrir directorio con $program_name"
"Icon"="$skipped_path,0"
[HKEY_CLASSES_ROOT\Directory\shell\\$program_name\command]
@="$skipped_path \"%1\""
EOL;
$reg_file = __ROOT__ . $program_name . ".reg";
error_log("creando $reg_file");
file_put_contents($reg_file, $reg_data);
exec("regedit.exe /S " . realpath($reg_file));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment