From 256ecd52b6c315623b24243a8db3c3de3e083a88 Mon Sep 17 00:00:00 2001 From: Falko Hilbert Date: Wed, 27 Nov 2019 12:07:43 +0100 Subject: [PATCH 1/5] add support for Jetbrains Toolbox --- PhpStorm Protocol (Win)/run_editor.js | 174 +++++++++++++++++--------- 1 file changed, 117 insertions(+), 57 deletions(-) diff --git a/PhpStorm Protocol (Win)/run_editor.js b/PhpStorm Protocol (Win)/run_editor.js index 77f80d2..623a1a2 100644 --- a/PhpStorm Protocol (Win)/run_editor.js +++ b/PhpStorm Protocol (Win)/run_editor.js @@ -1,57 +1,117 @@ -var settings = { - // Set to 'true' (without quotes) if run on Windows 64bit. Set to 'false' (without quotes) otherwise. - x64: true, - - // Set to folder name, where PhpStorm was installed to (e.g. 'PhpStorm') - folder_name: 'PhpStorm 2017.1.4', - - // Set to window title (only text after dash sign), that you see, when switching to running PhpStorm instance - window_title: 'PhpStorm 2017.1.4', - - // In case your file is mapped via a network share and paths do not match. - // eg. /var/www will can replaced with Y:/ - projects_basepath: '', - projects_path_alias: '' -}; - - -// don't change anything below this line, unless you know what you're doing -var url = WScript.Arguments(0), - match = /^phpstorm:\/\/open\/?\?(url=file:\/\/|file=)(.+)&line=(\d+)$/.exec(url), - project = '', - editor = '"C:\\' + (settings.x64 ? 'Program Files' : 'Program Files (x86)') + '\\JetBrains\\' + settings.folder_name + (settings.x64 ? '\\bin\\phpstorm64.exe' : '\\bin\\phpstorm.exe')+'"'; - -if (match) { - - var shell = new ActiveXObject('WScript.Shell'), - file_system = new ActiveXObject('Scripting.FileSystemObject'), - file = decodeURIComponent(match[2]).replace(/\+/g, ' '), - search_path = file.replace(/\//g, '\\'); - - if (settings.projects_basepath != '' && settings.projects_path_alias != '') { - file = file.replace(new RegExp('^' + settings.projects_basepath), settings.projects_path_alias); - } - - while (search_path.lastIndexOf('\\') != -1) { - search_path = search_path.substring(0, search_path.lastIndexOf('\\')); - - if(file_system.FileExists(search_path+'\\.idea\\.name')) { - project = search_path; - break; - } - } - - if (project != '') { - editor += ' "%project%"'; - } - - editor += ' --line %line% "%file%"'; - - var command = editor.replace(/%line%/g, match[3]) - .replace(/%file%/g, file) - .replace(/%project%/g, project) - .replace(/\//g, '\\'); - - shell.Exec(command); - shell.AppActivate(settings.window_title); -} +var settings = { + // flag to active Jetbrain Toolbox configuration + toolBoxActive: false, + + // Set to 'true' (without quotes) if run on Windows 64bit. Set to 'false' (without quotes) otherwise. + x64: true, + + // Set to folder name, where PhpStorm was installed to (e.g. 'PhpStorm') + folder_name: 'PhpStorm 2017.1.4', + + // Set to window title (only text after dash sign), that you see, when switching to running PhpStorm instance + window_title: 'PhpStorm 2017.1.4', + + // In case your file is mapped via a network share and paths do not match. + // eg. /var/www will can replaced with Y:/ + projects_basepath: '', + projects_path_alias: '' +}; + + +// don't change anything below this line, unless you know what you're doing +var url = WScript.Arguments(0), + match = /^phpstorm:\/\/open\/?\?(url=file:\/\/|file=)(.+)&line=(\d+)$/.exec(url), + project = '', + editor = '"C:\\' + (settings.x64 ? 'Program Files' : 'Program Files (x86)') + '\\JetBrains\\' + settings.folder_name + (settings.x64 ? '\\bin\\phpstorm64.exe' : '\\bin\\phpstorm.exe')+'"'; + +if( settings.toolBoxActive ) +{ + configureToolboxSettings(settings); +} + +if (match) { + + var shell = new ActiveXObject('WScript.Shell'), + file_system = new ActiveXObject('Scripting.FileSystemObject'), + file = decodeURIComponent(match[2]).replace(/\+/g, ' '), + search_path = file.replace(/\//g, '\\'); + + if (settings.projects_basepath != '' && settings.projects_path_alias != '') { + file = file.replace(new RegExp('^' + settings.projects_basepath), settings.projects_path_alias); + } + + while (search_path.lastIndexOf('\\') != -1) { + search_path = search_path.substring(0, search_path.lastIndexOf('\\')); + + if(file_system.FileExists(search_path+'\\.idea\\.name')) { + project = search_path; + break; + } + } + + if (project != '') { + editor += ' "%project%"'; + } + + editor += ' --line %line% "%file%"'; + + var command = editor.replace(/%line%/g, match[3]) + .replace(/%file%/g, file) + .replace(/%project%/g, project) + .replace(/\//g, '\\'); + + shell.Exec(command); + shell.AppActivate(settings.window_title); +} + +function configureToolboxSettings(settings) { + var shell = new ActiveXObject('WScript.Shell'), + appDataLocal = shell.ExpandEnvironmentStrings("%localappdata%"), + toolboxDirectory = appDataLocal + '\\JetBrains\\Toolbox\\apps\\PhpStorm\\ch-0\\'; + + // Reference the FileSystemObject + var fso = new ActiveXObject('Scripting.FileSystemObject'); + + // Reference the Text directory + var folder = fso.GetFolder(toolboxDirectory); + + // Reference the File collection of the Text directory + var fileCollection = folder.SubFolders; + + + var maxMajor = 0, + maxMinor = 0, + maxPatch = 0, + maxVersionFolder = ""; + // Traverse through the fileCollection using the FOR loop + // read the maximum version from toolbox filesystem + for (var objEnum = new Enumerator(fileCollection); !objEnum.atEnd(); objEnum.moveNext()) { + var folderObject = ( objEnum.item() ); + if (folderObject.Name.lastIndexOf('plugins') == -1) { + var versionMatch = /(\d+)\.(\d+)\.(\d+)/.exec(folderObject.Name), + major = parseInt(versionMatch[ 1 ]), + minor = parseInt(versionMatch[ 2 ]), + patch = parseInt(versionMatch[ 3 ]) + if (maxMajor == 0 || maxMajor <= major) { + maxMajor = major; + if (maxMinor == 0 || maxMinor <= minor) { + maxMinor = minor; + if (maxPatch == 0 || maxPatch <= patch) { + maxPatch = patch; + maxVersionFolder = folderObject.Name; + } + } + } + } + } + + settings.folder_name = maxVersionFolder; + + // read version name and product name from product-info.json + var versionFile = fso.OpenTextFile(toolboxDirectory + settings.folder_name + "\\product-info.json", 1, true); + var content = versionFile.ReadAll(); + + eval('var productVersion = ' + content + ';'); + settings.window_title = 'PhpStorm ' + productVersion.version; + editor = '"' + toolboxDirectory + settings.folder_name + '\\' + productVersion.launch[ 0 ].launcherPath.replace(/\//g, '\\') + '"'; +} \ No newline at end of file From 5aa05173ae1f4eb7d8e8eaa7456395af34d14c0b Mon Sep 17 00:00:00 2001 From: Falko Hilbert Date: Wed, 27 Nov 2019 15:26:44 +0100 Subject: [PATCH 2/5] reformat code --- PhpStorm Protocol (Win)/run_editor.js | 185 +++++++++++++------------- 1 file changed, 92 insertions(+), 93 deletions(-) diff --git a/PhpStorm Protocol (Win)/run_editor.js b/PhpStorm Protocol (Win)/run_editor.js index 623a1a2..08ae8e9 100644 --- a/PhpStorm Protocol (Win)/run_editor.js +++ b/PhpStorm Protocol (Win)/run_editor.js @@ -1,117 +1,116 @@ var settings = { - // flag to active Jetbrain Toolbox configuration - toolBoxActive: false, + // flag to active Jetbrain Toolbox configuration + toolBoxActive: false, - // Set to 'true' (without quotes) if run on Windows 64bit. Set to 'false' (without quotes) otherwise. - x64: true, + // Set to 'true' (without quotes) if run on Windows 64bit. Set to 'false' (without quotes) otherwise. + x64: true, - // Set to folder name, where PhpStorm was installed to (e.g. 'PhpStorm') - folder_name: 'PhpStorm 2017.1.4', + // Set to folder name, where PhpStorm was installed to (e.g. 'PhpStorm') + folder_name: 'PhpStorm 2017.1.4', - // Set to window title (only text after dash sign), that you see, when switching to running PhpStorm instance - window_title: 'PhpStorm 2017.1.4', + // Set to window title (only text after dash sign), that you see, when switching to running PhpStorm instance + window_title: 'PhpStorm 2017.1.4', - // In case your file is mapped via a network share and paths do not match. - // eg. /var/www will can replaced with Y:/ - projects_basepath: '', - projects_path_alias: '' + // In case your file is mapped via a network share and paths do not match. + // eg. /var/www will can replaced with Y:/ + projects_basepath: '', + projects_path_alias: '' }; // don't change anything below this line, unless you know what you're doing -var url = WScript.Arguments(0), - match = /^phpstorm:\/\/open\/?\?(url=file:\/\/|file=)(.+)&line=(\d+)$/.exec(url), - project = '', - editor = '"C:\\' + (settings.x64 ? 'Program Files' : 'Program Files (x86)') + '\\JetBrains\\' + settings.folder_name + (settings.x64 ? '\\bin\\phpstorm64.exe' : '\\bin\\phpstorm.exe')+'"'; - -if( settings.toolBoxActive ) -{ - configureToolboxSettings(settings); +var url = WScript.Arguments(0), + match = /^phpstorm:\/\/open\/?\?(url=file:\/\/|file=)(.+)&line=(\d+)$/.exec(url), + project = '', + editor = '"C:\\' + ( settings.x64 ? 'Program Files' : 'Program Files (x86)' ) + '\\JetBrains\\' + settings.folder_name + ( settings.x64 ? '\\bin\\phpstorm64.exe' : '\\bin\\phpstorm.exe' ) + '"'; + +if (settings.toolBoxActive) { + configureToolboxSettings(settings); } if (match) { - var shell = new ActiveXObject('WScript.Shell'), - file_system = new ActiveXObject('Scripting.FileSystemObject'), - file = decodeURIComponent(match[2]).replace(/\+/g, ' '), - search_path = file.replace(/\//g, '\\'); + var shell = new ActiveXObject('WScript.Shell'), + file_system = new ActiveXObject('Scripting.FileSystemObject'), + file = decodeURIComponent(match[ 2 ]).replace(/\+/g, ' '), + search_path = file.replace(/\//g, '\\'); - if (settings.projects_basepath != '' && settings.projects_path_alias != '') { - file = file.replace(new RegExp('^' + settings.projects_basepath), settings.projects_path_alias); - } + if (settings.projects_basepath !== '' && settings.projects_path_alias !== '') { + file = file.replace(new RegExp('^' + settings.projects_basepath), settings.projects_path_alias); + } - while (search_path.lastIndexOf('\\') != -1) { - search_path = search_path.substring(0, search_path.lastIndexOf('\\')); + while (search_path.lastIndexOf('\\') !== -1) { + search_path = search_path.substring(0, search_path.lastIndexOf('\\')); - if(file_system.FileExists(search_path+'\\.idea\\.name')) { - project = search_path; - break; - } - } + if (file_system.FileExists(search_path + '\\.idea\\.name')) { + project = search_path; + break; + } + } - if (project != '') { - editor += ' "%project%"'; - } + if (project !== '') { + editor += ' "%project%"'; + } - editor += ' --line %line% "%file%"'; + editor += ' --line %line% "%file%"'; - var command = editor.replace(/%line%/g, match[3]) - .replace(/%file%/g, file) - .replace(/%project%/g, project) - .replace(/\//g, '\\'); + var command = editor.replace(/%line%/g, match[ 3 ]) + .replace(/%file%/g, file) + .replace(/%project%/g, project) + .replace(/\//g, '\\'); - shell.Exec(command); - shell.AppActivate(settings.window_title); + shell.Exec(command); + shell.AppActivate(settings.window_title); } function configureToolboxSettings(settings) { - var shell = new ActiveXObject('WScript.Shell'), - appDataLocal = shell.ExpandEnvironmentStrings("%localappdata%"), - toolboxDirectory = appDataLocal + '\\JetBrains\\Toolbox\\apps\\PhpStorm\\ch-0\\'; - - // Reference the FileSystemObject - var fso = new ActiveXObject('Scripting.FileSystemObject'); - - // Reference the Text directory - var folder = fso.GetFolder(toolboxDirectory); - - // Reference the File collection of the Text directory - var fileCollection = folder.SubFolders; - - - var maxMajor = 0, - maxMinor = 0, - maxPatch = 0, - maxVersionFolder = ""; - // Traverse through the fileCollection using the FOR loop - // read the maximum version from toolbox filesystem - for (var objEnum = new Enumerator(fileCollection); !objEnum.atEnd(); objEnum.moveNext()) { - var folderObject = ( objEnum.item() ); - if (folderObject.Name.lastIndexOf('plugins') == -1) { - var versionMatch = /(\d+)\.(\d+)\.(\d+)/.exec(folderObject.Name), - major = parseInt(versionMatch[ 1 ]), - minor = parseInt(versionMatch[ 2 ]), - patch = parseInt(versionMatch[ 3 ]) - if (maxMajor == 0 || maxMajor <= major) { - maxMajor = major; - if (maxMinor == 0 || maxMinor <= minor) { - maxMinor = minor; - if (maxPatch == 0 || maxPatch <= patch) { - maxPatch = patch; - maxVersionFolder = folderObject.Name; - } - } - } - } - } - - settings.folder_name = maxVersionFolder; - - // read version name and product name from product-info.json - var versionFile = fso.OpenTextFile(toolboxDirectory + settings.folder_name + "\\product-info.json", 1, true); - var content = versionFile.ReadAll(); - - eval('var productVersion = ' + content + ';'); - settings.window_title = 'PhpStorm ' + productVersion.version; - editor = '"' + toolboxDirectory + settings.folder_name + '\\' + productVersion.launch[ 0 ].launcherPath.replace(/\//g, '\\') + '"'; + var shell = new ActiveXObject('WScript.Shell'), + appDataLocal = shell.ExpandEnvironmentStrings("%localappdata%"), + toolboxDirectory = appDataLocal + '\\JetBrains\\Toolbox\\apps\\PhpStorm\\ch-0\\'; + + // Reference the FileSystemObject + var fso = new ActiveXObject('Scripting.FileSystemObject'); + + // Reference the Text directory + var folder = fso.GetFolder(toolboxDirectory); + + // Reference the File collection of the Text directory + var fileCollection = folder.SubFolders; + + + var maxMajor = 0, + maxMinor = 0, + maxPatch = 0, + maxVersionFolder = ""; + // Traverse through the fileCollection using the FOR loop + // read the maximum version from toolbox filesystem + for (var objEnum = new Enumerator(fileCollection); !objEnum.atEnd(); objEnum.moveNext()) { + var folderObject = ( objEnum.item() ); + if (folderObject.Name.lastIndexOf('plugins') === -1) { + var versionMatch = /(\d+)\.(\d+)\.(\d+)/.exec(folderObject.Name), + major = parseInt(versionMatch[ 1 ]), + minor = parseInt(versionMatch[ 2 ]), + patch = parseInt(versionMatch[ 3 ]); + if (maxMajor === 0 || maxMajor <= major) { + maxMajor = major; + if (maxMinor === 0 || maxMinor <= minor) { + maxMinor = minor; + if (maxPatch === 0 || maxPatch <= patch) { + maxPatch = patch; + maxVersionFolder = folderObject.Name; + } + } + } + } + } + + settings.folder_name = maxVersionFolder; + + // read version name and product name from product-info.json + var versionFile = fso.OpenTextFile(toolboxDirectory + settings.folder_name + "\\product-info.json", 1, true); + var content = versionFile.ReadAll(); + + eval('var productVersion = ' + content + ';'); + settings.window_title = 'PhpStorm ' + productVersion.version; + editor = '"' + toolboxDirectory + settings.folder_name + '\\' + productVersion.launch[ 0 ].launcherPath.replace(/\//g, '\\') + '"'; } \ No newline at end of file From ffd832246369337d198699dc82f4625d0f84aa12 Mon Sep 17 00:00:00 2001 From: Falko Hilbert Date: Thu, 19 Dec 2019 14:04:52 +0100 Subject: [PATCH 3/5] - fix bug when comparing versions - add Informations to README.md --- PhpStorm Protocol (Win)/run_editor.js | 35 ++++++++++++++------------- README.md | 1 + 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/PhpStorm Protocol (Win)/run_editor.js b/PhpStorm Protocol (Win)/run_editor.js index 08ae8e9..b9cabed 100644 --- a/PhpStorm Protocol (Win)/run_editor.js +++ b/PhpStorm Protocol (Win)/run_editor.js @@ -78,28 +78,14 @@ function configureToolboxSettings(settings) { var fileCollection = folder.SubFolders; - var maxMajor = 0, - maxMinor = 0, - maxPatch = 0, - maxVersionFolder = ""; + var maxVersionFolder = "0"; // Traverse through the fileCollection using the FOR loop // read the maximum version from toolbox filesystem for (var objEnum = new Enumerator(fileCollection); !objEnum.atEnd(); objEnum.moveNext()) { var folderObject = ( objEnum.item() ); if (folderObject.Name.lastIndexOf('plugins') === -1) { - var versionMatch = /(\d+)\.(\d+)\.(\d+)/.exec(folderObject.Name), - major = parseInt(versionMatch[ 1 ]), - minor = parseInt(versionMatch[ 2 ]), - patch = parseInt(versionMatch[ 3 ]); - if (maxMajor === 0 || maxMajor <= major) { - maxMajor = major; - if (maxMinor === 0 || maxMinor <= minor) { - maxMinor = minor; - if (maxPatch === 0 || maxPatch <= patch) { - maxPatch = patch; - maxVersionFolder = folderObject.Name; - } - } + if( compareVersion(folderObject.Name, maxVersionFolder) > 0 ){ + maxVersionFolder = folderObject.Name; } } } @@ -113,4 +99,19 @@ function configureToolboxSettings(settings) { eval('var productVersion = ' + content + ';'); settings.window_title = 'PhpStorm ' + productVersion.version; editor = '"' + toolboxDirectory + settings.folder_name + '\\' + productVersion.launch[ 0 ].launcherPath.replace(/\//g, '\\') + '"'; +} + +function compareVersion(v1, v2) { + if (typeof v1 !== 'string') return false; + if (typeof v2 !== 'string') return false; + v1 = v1.split('.'); + v2 = v2.split('.'); + const k = Math.min(v1.length, v2.length); + for (let i = 0; i < k; ++ i) { + v1[i] = parseInt(v1[i], 10); + v2[i] = parseInt(v2[i], 10); + if (v1[i] > v2[i]) return 1; + if (v1[i] < v2[i]) return -1; + } + return v1.length == v2.length ? 0: (v1.length < v2.length ? -1 : 1); } \ No newline at end of file diff --git a/README.md b/README.md index 550b025..d5acbe5 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,7 @@ Installing on Windows 4. double click on ```C:\Program Files\PhpStorm Protocol (Win)\run_editor.reg``` file 5. agree to whatever Registry Editor asks you 6. update settings at ```C:\Program Files\PhpStorm Protocol (Win)\run_editor.js``` file, because each PhpStorm version is installed into it's own sub-folder! + 1. if you're using the JetBrains Toolbox, you're only need to set the settings.toolBoxActive flag to ```true``` and no other settings needs to be configured, because all settings will read automatically 7. delete cloned folder #### Working under another path? From 3620de3f049e709c0625260e543d99ced63e2b9a Mon Sep 17 00:00:00 2001 From: Falko Hilbert Date: Thu, 19 Dec 2019 16:09:50 +0100 Subject: [PATCH 4/5] refactoring after PR-review --- PhpStorm Protocol (Win)/run_editor.js | 6 ++---- README.md | 6 ++++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/PhpStorm Protocol (Win)/run_editor.js b/PhpStorm Protocol (Win)/run_editor.js index b9cabed..eea001e 100644 --- a/PhpStorm Protocol (Win)/run_editor.js +++ b/PhpStorm Protocol (Win)/run_editor.js @@ -83,10 +83,8 @@ function configureToolboxSettings(settings) { // read the maximum version from toolbox filesystem for (var objEnum = new Enumerator(fileCollection); !objEnum.atEnd(); objEnum.moveNext()) { var folderObject = ( objEnum.item() ); - if (folderObject.Name.lastIndexOf('plugins') === -1) { - if( compareVersion(folderObject.Name, maxVersionFolder) > 0 ){ - maxVersionFolder = folderObject.Name; - } + if (folderObject.Name.lastIndexOf('plugins') === -1 && compareVersion(folderObject.Name, maxVersionFolder) > 0 ){ + maxVersionFolder = folderObject.Name; } } diff --git a/README.md b/README.md index d5acbe5..310f4b7 100644 --- a/README.md +++ b/README.md @@ -50,8 +50,10 @@ Installing on Windows 4. double click on ```C:\Program Files\PhpStorm Protocol (Win)\run_editor.reg``` file 5. agree to whatever Registry Editor asks you 6. update settings at ```C:\Program Files\PhpStorm Protocol (Win)\run_editor.js``` file, because each PhpStorm version is installed into it's own sub-folder! - 1. if you're using the JetBrains Toolbox, you're only need to set the settings.toolBoxActive flag to ```true``` and no other settings needs to be configured, because all settings will read automatically 7. delete cloned folder #### Working under another path? -You can make use of the [project alias settings](/PhpStorm Protocol (Win)/run_editor.js#L11-L14) in case you are working under a network share or Vagrant. +* You can make use of the [project alias settings](PhpStorm Protocol%20(Win)/run_editor.js#L14-L16) in case you are working under a network share or Vagrant. + +* If you're using the JetBrains Toolbox, you're only need to set the [toolBoxActive](PhpStorm Protocol%20(Win)/run_editor.js#L2-L3) flag to ```true``` and no other settings needs to be configured, because all settings will read automatically + From e3b1c8d4d5849225f06363208deb0bf08e486184 Mon Sep 17 00:00:00 2001 From: Falko Hilbert Date: Thu, 19 Dec 2019 16:12:54 +0100 Subject: [PATCH 5/5] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 310f4b7..cf4aae2 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ Installing on Windows 7. delete cloned folder #### Working under another path? -* You can make use of the [project alias settings](PhpStorm Protocol%20(Win)/run_editor.js#L14-L16) in case you are working under a network share or Vagrant. +* You can make use of the [project alias settings](PhpStorm%20Protocol%20(Win)/run_editor.js#L14-L17) in case you are working under a network share or Vagrant. -* If you're using the JetBrains Toolbox, you're only need to set the [toolBoxActive](PhpStorm Protocol%20(Win)/run_editor.js#L2-L3) flag to ```true``` and no other settings needs to be configured, because all settings will read automatically +* If you're using the JetBrains Toolbox, you're only need to set the [toolBoxActive](PhpStorm%20Protocol%20(Win)/run_editor.js#L2-L3) flag to ```true``` and no other settings needs to be configured, because all settings will read automatically