diff --git a/PhpStorm Protocol (Win)/run_editor.js b/PhpStorm Protocol (Win)/run_editor.js index 08ae8e9..eea001e 100644 --- a/PhpStorm Protocol (Win)/run_editor.js +++ b/PhpStorm Protocol (Win)/run_editor.js @@ -78,29 +78,13 @@ 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 (folderObject.Name.lastIndexOf('plugins') === -1 && compareVersion(folderObject.Name, maxVersionFolder) > 0 ){ + maxVersionFolder = folderObject.Name; } } @@ -113,4 +97,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..cf4aae2 100644 --- a/README.md +++ b/README.md @@ -53,4 +53,7 @@ Installing on Windows 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%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%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 +