|
| 1 | +import * as path from "path"; |
1 | 2 | import { |
2 | 3 | commands, |
3 | 4 | Disposable, |
@@ -83,41 +84,74 @@ async function _activate(context: ExtensionContext, disposables: Disposable[]) { |
83 | 84 | outputChannel.show(); |
84 | 85 | } |
85 | 86 |
|
86 | | - try { |
87 | | - await init(context, outputChannel, disposables); |
88 | | - } catch (err) { |
89 | | - if (!/Svn installation not found/.test(err.message || "")) { |
90 | | - throw err; |
91 | | - } |
92 | | - |
93 | | - const shouldIgnore = |
94 | | - configuration.get<boolean>("ignoreMissingSvnWarning") === true; |
| 87 | + const tryInit = async () => { |
| 88 | + try { |
| 89 | + await init(context, outputChannel, disposables); |
| 90 | + } catch (err) { |
| 91 | + if (!/Svn installation not found/.test(err.message || "")) { |
| 92 | + throw err; |
| 93 | + } |
| 94 | + |
| 95 | + const shouldIgnore = |
| 96 | + configuration.get<boolean>("ignoreMissingSvnWarning") === true; |
| 97 | + |
| 98 | + if (shouldIgnore) { |
| 99 | + return; |
| 100 | + } |
| 101 | + |
| 102 | + console.warn(err.message); |
| 103 | + outputChannel.appendLine(err.message); |
| 104 | + outputChannel.show(); |
| 105 | + |
| 106 | + const findSvnExecutable = "Find SVN executable"; |
| 107 | + const download = "Download SVN"; |
| 108 | + const neverShowAgain = "Don't Show Again"; |
| 109 | + const choice = await window.showWarningMessage( |
| 110 | + "SVN not found. Install it or configure it using the 'svn.path' setting.", |
| 111 | + findSvnExecutable, |
| 112 | + download, |
| 113 | + neverShowAgain |
| 114 | + ); |
95 | 115 |
|
96 | | - if (shouldIgnore) { |
97 | | - return; |
| 116 | + if (choice === findSvnExecutable) { |
| 117 | + let filters: { [name: string]: string[] } | undefined; |
| 118 | + |
| 119 | + // For windows, limit to executable files |
| 120 | + if (path.sep === "\\") { |
| 121 | + filters = { |
| 122 | + svn: ["exe", "bat"] |
| 123 | + }; |
| 124 | + } |
| 125 | + |
| 126 | + const executable = await window.showOpenDialog({ |
| 127 | + canSelectFiles: true, |
| 128 | + canSelectFolders: false, |
| 129 | + canSelectMany: false, |
| 130 | + filters |
| 131 | + }); |
| 132 | + |
| 133 | + if (executable && executable[0]) { |
| 134 | + const file = executable[0].fsPath; |
| 135 | + |
| 136 | + outputChannel.appendLine(`Updated "svn.path" with "${file}"`); |
| 137 | + |
| 138 | + await configuration.update("path", file); |
| 139 | + |
| 140 | + // Try Re-init after select the executable |
| 141 | + await tryInit(); |
| 142 | + } |
| 143 | + } else if (choice === download) { |
| 144 | + commands.executeCommand( |
| 145 | + "vscode.open", |
| 146 | + Uri.parse("https://subversion.apache.org/packages.html") |
| 147 | + ); |
| 148 | + } else if (choice === neverShowAgain) { |
| 149 | + await configuration.update("ignoreMissingSvnWarning", true); |
| 150 | + } |
98 | 151 | } |
| 152 | + }; |
99 | 153 |
|
100 | | - console.warn(err.message); |
101 | | - outputChannel.appendLine(err.message); |
102 | | - outputChannel.show(); |
103 | | - |
104 | | - const download = "Download SVN"; |
105 | | - const neverShowAgain = "Don't Show Again"; |
106 | | - const choice = await window.showWarningMessage( |
107 | | - "SVN not found. Install it or configure it using the 'svn.path' setting.", |
108 | | - download, |
109 | | - neverShowAgain |
110 | | - ); |
111 | | - |
112 | | - if (choice === download) { |
113 | | - commands.executeCommand( |
114 | | - "vscode.open", |
115 | | - Uri.parse("https://subversion.apache.org/packages.html") |
116 | | - ); |
117 | | - } else if (choice === neverShowAgain) { |
118 | | - await configuration.update("ignoreMissingSvnWarning", true); |
119 | | - } |
120 | | - } |
| 154 | + await tryInit(); |
121 | 155 | } |
122 | 156 |
|
123 | 157 | export async function activate(context: ExtensionContext) { |
|
0 commit comments