• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2* Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd.
3* Licensed under the Apache License, Version 2.0 (the "License");
4* you may not use this file except in compliance with the License.
5* You may obtain a copy of the License at
6*
7* http://www.apache.org/licenses/LICENSE-2.0
8*
9* Unless required by applicable law or agreed to in writing, software
10* distributed under the License is distributed on an "AS IS" BASIS,
11* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12* See the License for the specific language governing permissions and
13* limitations under the License.
14*/
15
16// The module 'vscode' contains the VS Code extensibility API
17// Import the module and reference it with the alias vscode in your code below
18import * as vscode from 'vscode';
19import * as path from 'path';
20import * as ts from 'typescript';
21import * as fs from 'fs';
22import * as os from 'os';
23import { downloadSdk , extractTarGz, extractZip, crossCompile, checkNative } from './ohcrosscompile';
24import { parseHeaderFile } from './parse/parsec';
25import { DtscppRootInfo, GenInfo } from './gen/datatype';
26import { parseTsFile } from './parse/parsets';
27import { genServiceFile } from './gen/gensa';
28import { genDtsFile } from './gen/gendts';
29import { genHdfFile } from './gen/genhdf';
30import { genDtsCppFile, genCppFile } from './gen/gendtscpp';
31import { H2dtsCtrl } from './controller/h2dtsctrl';
32import { H2saCtrl } from './controller/h2sactrl';
33import { H2hdfCtrl } from './controller/h2hdfctrl';
34import { H2dtscppCtrl } from './controller/h2dtscppctrl';
35import { Dts2cppCtrl } from './controller/dts2cppctrl';
36import { WelcomeCtrl } from './controller/welcomectrl';
37import { Logger } from './common/log';
38
39// 获取本地化字符串
40const SELECTED_DIR = vscode.l10n.t('You selected a directory:');
41const SELECTE_DIR = vscode.l10n.t('Please select a directory.');
42const NO_RES_SELECTED = vscode.l10n.t('No resource selected.');
43const HDF_FRAMEWORK = vscode.l10n.t('Hdf Framework');
44const SA_FRAMEWORK = vscode.l10n.t('SystemAbility Framework');
45const NAPI_FRAMEWORK = vscode.l10n.t('N-API Framework');
46const SELECT_VERSION = vscode.l10n.t('Please select the version...');
47const INPUT_SERVICEID = vscode.l10n.t('Please input serviceId like 19000...');
48const INPUT_NO_EMPTY = vscode.l10n.t('Input cannot be empty');
49const INPUT_NUMBER = vscode.l10n.t('Please input a number...');
50const SELECT_FRAMWORK = vscode.l10n.t('Please select framework...');
51const CONFIRM_SELECT = vscode.l10n.t('Please confirm your selection...');
52const INPUT_INCONSISTENT = vscode.l10n.t('Inconsistent input');
53const PARSE_COMPLETE = vscode.l10n.t('Parse complete.');
54const GEN_COMPLETE = vscode.l10n.t('Generation complete:');
55const OPEN_IN_EXPLORER = vscode.l10n.t('Open in Explorer');
56const PICK_MAKE = vscode.l10n.t('Use Makefile for compilation.');
57const PICK_CMAKE = vscode.l10n.t('Use CMakeLists.txt for compilation.');
58const PICK_CONFIGURE = vscode.l10n.t('Use configure script for compilation.');
59const TOOL_PICK_PLACEHOLDER = vscode.l10n.t('Please select the way you want to compile: ');
60const OH_CROSS_COMPILE_TITLE = vscode.l10n.t('OpenHarmony Cross Compile');
61const COMPILATION_METHOD_LOST = vscode.l10n.t('Unable to comfirm the compilation method, compilation aborted.');
62const ARCH_PICK_64 = vscode.l10n.t('To compile 64-bit third-party library.');
63const ARCH_PICK_32 = vscode.l10n.t('To compile 32-bit third-party library.');
64const ARCH_PICK_PLACEHOLDER = vscode.l10n.t('Please select the target system architecture for compilation: ');
65const ARCHITECTURE_LOST = vscode.l10n.t('Unable to comfirm target system architecture, compilation aborted.');
66const LOCAL = vscode.l10n.t('Local');
67const LOCAL_DESCRIPTION = vscode.l10n.t('Please select the \'native\' folder in local OpenHarmony SDK files.');
68const DOWNLOAD = vscode.l10n.t('Download');
69const DOWNLOAD_DESCRIPTION = vscode.l10n.t('Download a specified version of OpenHarmony SDK from internet.');
70const SOURCE_PICK_PLACEHOLDER = vscode.l10n.t('Please select the SDK you want to use: ');
71const NATIVE_CHECK_FAILED = vscode.l10n.t('Unable to verify the integrity of the native tools in OpenHarmony SDK, please try again and select a correct path of the \'native\' folder.');
72const FOLDER_LOST = vscode.l10n.t('No folder selected, compilation aborted.');
73const API9_LABEL = vscode.l10n.t('API Version 9');
74const API9_DETAIL = vscode.l10n.t('Please select a folder to install this SDK. It is compatible with OpenHarmony 3.2 Release.');
75const API10_LABEL = vscode.l10n.t('API Version 10');
76const API10_DETAIL = vscode.l10n.t('Please select a folder to install this SDK. It is compatible with OpenHarmony 4.0 Release.');
77const API11_LABEL = vscode.l10n.t('API Version 11');
78const API11_DETAIL = vscode.l10n.t('Please select a folder to install this SDK. It is compatible with OpenHarmony 4.1 Release.');
79const API12_LABEL = vscode.l10n.t('API Version 12');
80const API12_DETAIL = vscode.l10n.t('Please select a folder to install this SDK. It is compatible with OpenHarmony 5.0.0 Release.');
81const VERSION_PICK_PLACEHOLDER = vscode.l10n.t('Please specify the SDK version: ');
82const DOWNLOADING_TITLE = vscode.l10n.t('Downloading and installing SDK');
83const DOWNLOADING_START = vscode.l10n.t('Start downloading...');
84const DOWNLOADING_COMPLETE = vscode.l10n.t('Download complete. Extracting .tar.gz files... ');
85const SDK_INSTALLED = vscode.l10n.t('SDK installation complete.');
86const SDK_VERSION_LOST = vscode.l10n.t('Unable to specify the version of OpenHarmony SDK, compilation aborted.');
87const SDK_SOURCE_LOST = vscode.l10n.t('Unable to comfirm the source of OpenHarmony SDK, compilation aborted.');
88const CMAKE_MAKE_LOST = vscode.l10n.t('Cannot detect CMakeLists.txt or Makefile!');
89
90// this method is called when your extension is activated
91// your extension is activated the very first time the command is executed
92export function activate(context: vscode.ExtensionContext) {
93    // Use the console to output diagnostic information (Logger.getInstance().debug) and errors (Logger.getInstance().error)
94    // This line of code will only be executed once when your extension is activated
95    Logger.getInstance().debug('Congratulations, your extension "helloworld-sample" is now active!');
96
97    const ohcrosscompile = vscode.commands.registerCommand('extension.ohcrosscompile', async (uri) => {
98      let compileTool: string;
99      let thirdPartyPath: string;
100      let nativePath: string;
101      let ohArchitecture = new Array();
102      const platform = os.platform();
103
104
105      if (uri && uri.path) {
106        thirdPartyPath = uri.path;
107        if (platform === "win32") {
108          thirdPartyPath = thirdPartyPath.slice(1);
109        }
110        const canCmake = fs.existsSync(thirdPartyPath.concat("/CMakeLists.txt"));
111        const canMake = fs.existsSync(thirdPartyPath.concat("/GNUmakefile")) || fs.existsSync(thirdPartyPath.concat("/Makefile")) || fs.existsSync(thirdPartyPath.concat("/makefile"));
112        let canConfigure: boolean;
113        if (platform === "win32") {
114          canConfigure = false;
115        } else {
116          canConfigure = fs.existsSync(thirdPartyPath.concat("/configure"));
117        }
118
119        // 如果检测到CMakeLists.txt或makefile或configure脚本,则可以继续
120        if (canCmake || canMake || canConfigure) {
121          // 若没有插件文件夹、安装文件夹,则创建。可自动获取到安装目录
122          const ohCrossCompilePath = thirdPartyPath.concat("/ohCrossCompile");
123          if (!fs.existsSync(ohCrossCompilePath)) {
124            fs.mkdirSync(ohCrossCompilePath);
125          }
126
127          // 若没有配置文件,则以默认配置创建配置文件
128          const configPath = ohCrossCompilePath.concat("/config.json")
129          if (!fs.existsSync(configPath)) {
130            const defaultConfig = {
131              settings: {
132                compileTool: "",
133                nativePath: "",
134                thirdPartyPath: thirdPartyPath,
135                // ohArchitecture: ["arm64-v8a", "armeabi-v7a"]
136                ohArchitecture: []
137              },
138              actions: []
139            };
140            fs.writeFileSync(configPath, JSON.stringify(defaultConfig, null, 4), 'utf8');
141          }
142          const configContent = JSON.parse(fs.readFileSync(configPath, 'utf8'));
143          if (configContent.settings === undefined) {
144            const defaultConfig = {
145              settings: {
146                compileTool: "",
147                nativePath: "",
148                thirdPartyPath: thirdPartyPath,
149                // ohArchitecture: ["arm64-v8a", "armeabi-v7a"]
150                ohArchitecture: []
151              },
152              actions: []
153            };
154            fs.writeFileSync(configPath, JSON.stringify(defaultConfig, null, 4), 'utf8');
155          }
156
157          // 获取编译方式是make还是cmake还是configure
158          if (configContent.settings.compileTool !== undefined && (configContent.settings.compileTool === "make" || configContent.settings.compileTool === "cmake" || configContent.settings.compileTool === "configure")) {
159            //如果配置文件中已经存储编译方式,则获得
160            compileTool = configContent.settings.compileTool;
161          } else if (canMake ? (canCmake || canConfigure) : (canCmake && canConfigure)) {
162            // 若有两个或两个以上的可选编译方式,则询问用户,并存储结果
163            let toolPickItems: {
164              label: string;
165              description: string;
166            }[] = [];
167            if (canMake) {
168              toolPickItems.push({
169                label: "make",
170                description: PICK_MAKE
171              });
172            }
173            if (canCmake) {
174              toolPickItems.push({
175                label: "cmake",
176                description: PICK_CMAKE
177              });
178            }
179            if (canConfigure) {
180              toolPickItems.push({
181                label: "configure",
182                description: PICK_CONFIGURE
183              });
184            }
185            const toolPickOptions = {
186              canPickMany: false,
187              ignoreFocusOut: true,
188              placeHolder: TOOL_PICK_PLACEHOLDER,
189              title: OH_CROSS_COMPILE_TITLE
190            };
191            const toolPick = await vscode.window.showQuickPick(toolPickItems, toolPickOptions);
192
193            if (toolPick) {
194              compileTool = toolPick.label;
195              configContent.settings.compileTool = compileTool;
196              fs.writeFileSync(configPath, JSON.stringify(configContent, null, 4), 'utf8');
197            } else {
198              vscode.window.showInformationMessage(COMPILATION_METHOD_LOST);
199              return;
200            }
201          } else if (canCmake) {
202            // 若自动判断出只可以使用cmake
203            compileTool = "cmake";
204            configContent.settings.compileTool = "cmake";
205            fs.writeFileSync(configPath, JSON.stringify(configContent, null, 4), 'utf8');
206          } else if (canMake) {
207            // 若自动判断出只可以使用make
208            compileTool = "make";
209            configContent.settings.compileTool = "make";
210            fs.writeFileSync(configPath, JSON.stringify(configContent, null, 4), 'utf8');
211          } else {
212            // 若自动判断出只可以使用configure
213            compileTool = "configure";
214            configContent.settings.compileTool = "configure";
215            fs.writeFileSync(configPath, JSON.stringify(configContent, null, 4), 'utf8');
216          }
217
218
219          // 确认要编译的CPU架构。安装文件夹若不存在则创建
220          if (configContent.settings.ohArchitecture === undefined || configContent.settings.ohArchitecture.length === 0) {
221            // 若根据配置文件无法确定CPU架构参数,则询问用户
222            const archPickItems = [
223              {
224                label: "arm64-v8a",
225                description: ARCH_PICK_64
226              },
227              {
228                label: "armeabi-v7a",
229                description: ARCH_PICK_32
230              }
231            ];
232            const archPickOptions = {
233              canPickMany: true,
234              ignoreFocusOut: true,
235              placeHolder: ARCH_PICK_PLACEHOLDER,
236              title: OH_CROSS_COMPILE_TITLE
237            };
238            const archPick = await vscode.window.showQuickPick(archPickItems, archPickOptions)
239            if (archPick && Array.isArray(archPick) && archPick.length > 0) {
240              // 获得用户选择的信息,并存入配置文件
241              for (let item of archPick) {
242                let arch = item.label;
243                ohArchitecture.push(arch);
244                if (!fs.existsSync(`${ohCrossCompilePath}/${arch}`)) {
245                  fs.mkdirSync(`${ohCrossCompilePath}/${arch}`);
246                }
247                if (!fs.existsSync(`${ohCrossCompilePath}/${arch}/installed`)) {
248                  fs.mkdirSync(`${ohCrossCompilePath}/${arch}/installed`);
249                }
250              }
251              configContent.settings.ohArchitecture = ohArchitecture;
252              fs.writeFileSync(configPath, JSON.stringify(configContent, null, 4), 'utf8');
253            } else {
254              vscode.window.showInformationMessage(ARCHITECTURE_LOST);
255              return;
256            }
257          } else {
258            if (configContent.settings.ohArchitecture.includes("arm64-v8a")) {
259              ohArchitecture.push("arm64-v8a");
260              if (!fs.existsSync(`${ohCrossCompilePath}/arm64-v8a`)) {
261                fs.mkdirSync(`${ohCrossCompilePath}/arm64-v8a`);
262              }
263              if (!fs.existsSync(`${ohCrossCompilePath}/arm64-v8a/installed`)) {
264                fs.mkdirSync(`${ohCrossCompilePath}/arm64-v8a/installed`);
265              }
266            }
267            if (configContent.settings.ohArchitecture.includes("armeabi-v7a")) {
268              ohArchitecture.push("armeabi-v7a");
269              if (!fs.existsSync(`${ohCrossCompilePath}/armeabi-v7a`)) {
270                fs.mkdirSync(`${ohCrossCompilePath}/armeabi-v7a`);
271              }
272              if (!fs.existsSync(`${ohCrossCompilePath}/armeabi-v7a/installed`)) {
273                fs.mkdirSync(`${ohCrossCompilePath}/armeabi-v7a/installed`);
274              }
275            }
276          }
277
278
279          // 确认sdk中native工具的路径
280          if (configContent.settings.nativePath === undefined || configContent.settings.nativePath === "") {
281
282            // 询问用户。确认sdk来源是本地还是下载
283            const sourcePickItems = [
284              {
285                label: LOCAL,
286                description: LOCAL_DESCRIPTION
287              },
288              {
289                label: DOWNLOAD,
290                description: DOWNLOAD_DESCRIPTION
291              }
292            ];
293            const sourcePickOptions = {
294              canPickMany: false,
295              ignoreFocusOut: true,
296              placeHolder: SOURCE_PICK_PLACEHOLDER,
297              title: OH_CROSS_COMPILE_TITLE
298            }
299            const sourcePick = await vscode.window.showQuickPick(sourcePickItems, sourcePickOptions);
300
301            if (sourcePick) {
302              // 若sdk来源为本地,则询问用户native所在的具体路径,并检查是否合法
303              if (sourcePick.label === LOCAL) {
304                const folderUri = await vscode.window.showOpenDialog({
305                  canSelectMany: false,
306                  canSelectFolders: true,
307                  canSelectFiles: false
308                });
309                if (folderUri && folderUri[0]) {
310                  let folderPath = folderUri[0].path;
311                  if (platform === "win32") {
312                    folderPath = folderPath.slice(1);
313                  }
314                  if (checkNative(platform, folderPath)) {
315                    nativePath = folderPath;
316                    configContent.settings.nativePath = folderPath;
317                    fs.writeFileSync(configPath, JSON.stringify(configContent, null, 4), 'utf8');
318
319                    // 执行编译命令
320                    crossCompile(platform, undefined, configPath, thirdPartyPath, compileTool, ohArchitecture, nativePath, ohCrossCompilePath);
321                  } else {
322                    vscode.window.showInformationMessage(NATIVE_CHECK_FAILED);
323                    return;
324                  }
325                } else {
326                  vscode.window.showInformationMessage(FOLDER_LOST);
327                  return;
328                }
329              } else if (sourcePick.label === DOWNLOAD) {
330                // 若sdk来源为网络,则询问下载版本与下载路径,下载并解压sdk
331                // 获取下载版本,从而获得下载链接
332                const versionPickItems = [
333                  {
334                    label: API9_LABEL,
335                    description: "Ohos_sdk_public 3.2.11.9 (API Version 9 Release)",
336                    detail: API9_DETAIL
337                  },
338                  {
339                    label: API10_LABEL,
340                    description: "Ohos_sdk_public 4.0.10.13 (API Version 10 Release)",
341                    detail: API10_DETAIL
342                  },
343                  {
344                    label: API11_LABEL,
345                    description: "Ohos_sdk_public 4.1.7.5 (API Version 11 Release)",
346                    detail: API11_DETAIL
347                  },
348                  {
349                    label: API12_LABEL,
350                    description: "Ohos_sdk_public 5.0.0.71 (API Version 12 Release)",
351                    detail: API12_DETAIL
352                  },
353                ];
354                const versionPickOptions = {
355                  canPickMany: false,
356                  ignoreFocusOut: true,
357                  placeHolder: VERSION_PICK_PLACEHOLDER,
358                  title: OH_CROSS_COMPILE_TITLE
359                }
360                const versionPick = await vscode.window.showQuickPick(versionPickItems, versionPickOptions);
361                if (versionPick) {
362                  const apiVersion = versionPick.label;
363                  let downloadLink: string;
364                  switch (apiVersion) {
365                    case API9_LABEL:
366                      downloadLink = "https://repo.huaweicloud.com/openharmony/os/3.2-Release/ohos-sdk-windows_linux-public.tar.gz";
367                      break;
368                    case API10_LABEL:
369                      downloadLink = "https://repo.huaweicloud.com/openharmony/os/4.0-Release/ohos-sdk-windows_linux-public.tar.gz";
370                      break;
371                    case API11_LABEL:
372                      downloadLink = "https://repo.huaweicloud.com/openharmony/os/4.1-Release/ohos-sdk-windows_linux-public.tar.gz";
373                      break;
374                    case API12_LABEL:
375                      downloadLink = "https://repo.huaweicloud.com/openharmony/os/5.0.0-Release/ohos-sdk-windows_linux-public.tar.gz";
376                      break;
377                  }
378
379                  // 询问下载路径
380                  const folderUri = await vscode.window.showOpenDialog({
381                    canSelectMany: false,
382                    canSelectFolders: true,
383                    canSelectFiles: false
384                  });
385                  if (folderUri && folderUri[0]) {
386                    let folderPath = folderUri[0].path;
387                    if (platform === "win32") {
388                      folderPath = folderPath.slice(1);
389                    }
390                    let filePath = folderPath.concat("/ohos-sdk-windows_linux-public.tar.gz");
391
392                    // 下载并解压sdk中的native
393                    await vscode.window.withProgress({
394                      location: vscode.ProgressLocation.Notification,
395                      title: DOWNLOADING_TITLE,
396                      cancellable: false
397                    }, async (progress) => {
398                      progress.report({ increment: 0, message: DOWNLOADING_START });
399                      await downloadSdk(downloadLink, filePath, progress);
400                      vscode.window.showInformationMessage(vscode.l10n.t('SDK downloaded to: {0}', filePath));
401
402                      // 解压sdk中的native,并拼装nativePath
403                      progress.report({ increment: 10, message: DOWNLOADING_COMPLETE });
404                      await extractTarGz(filePath, folderPath);
405                      progress.report({ increment: 100, message: SDK_INSTALLED });
406
407                      nativePath = folderPath;
408                      if (apiVersion !== API12_LABEL) {
409                        // api12版本路径中没有ohos-sdk;9-11版本则有
410                        nativePath = nativePath.concat("/ohos-sdk");
411                      }
412                      if (platform === "win32") {
413                        // windows系统下的nativePath路径
414                        nativePath = nativePath.concat("/windows");
415                      } else {
416                        // linux系统下的nativePath路径
417                        nativePath = nativePath.concat("/linux");
418                      }
419                      for (const file of await fs.promises.readdir(nativePath)) {
420                        if (file.startsWith("native")) {
421                          // 获取native压缩包的文件路径
422                          filePath = nativePath.concat("/" + file);
423                        }
424                      }
425                      Logger.getInstance().debug(filePath);
426                      const terminal = vscode.window.createTerminal({ name: OH_CROSS_COMPILE_TITLE });
427                      terminal.show();
428                      await extractZip(platform, terminal, filePath, nativePath);
429                      nativePath = nativePath.concat("/native");
430                      configContent.settings.nativePath = nativePath;
431                      fs.writeFileSync(configPath, JSON.stringify(configContent, null, 4), 'utf8');
432
433                      // 执行编译命令
434                      crossCompile(platform, terminal, configPath, thirdPartyPath, compileTool, ohArchitecture, nativePath, ohCrossCompilePath);
435                    });
436                  } else {
437                    vscode.window.showInformationMessage(FOLDER_LOST);
438                    return;
439                  }
440                } else {
441                  vscode.window.showInformationMessage(SDK_VERSION_LOST);
442                  return;
443                }
444              }
445            } else {
446              vscode.window.showInformationMessage(SDK_SOURCE_LOST);
447              return;
448            }
449          } else {
450            // 配置文件中nativePath非空,则从配置文件中获取
451            if (checkNative(platform, configContent.settings.nativePath)) {
452              nativePath = configContent.settings.nativePath;
453              // 执行编译命令
454              crossCompile(platform, undefined, configPath, thirdPartyPath, compileTool, ohArchitecture, nativePath, ohCrossCompilePath);
455            } else {
456              // 从配置文件中获取的nativePath非法,则重置,并提示
457              configContent.settings.nativePath = "";
458              fs.writeFileSync(configPath, JSON.stringify(configContent, null, 4), 'utf8');
459              vscode.window.showInformationMessage(NATIVE_CHECK_FAILED);
460              return;
461            }
462          }
463        } else {
464          // 用户所选文件夹不含CMakeLists.ext、Makefile、configure
465          vscode.window.showErrorMessage(CMAKE_MAKE_LOST);
466        }
467      }
468    });
469    context.subscriptions.push(ohcrosscompile);
470
471    // The command has been defined in the package.json file
472    // Now provide the implementation of the command with registerCommand
473    // The commandId parameter must match the command field in package.json
474    const h2sa = vscode.commands.registerCommand('extension.h2sa', async (uri) => {
475      let h2saCtrl = new H2saCtrl(uri);
476      h2saCtrl.init();
477      // The code you place here will be executed every time your command is executed
478      // if (uri && uri.fsPath) {
479      //     let versionTag = '3.2';
480      //     const version = await vscode.window.showQuickPick(
481      //       ['OpenHarmony 4.1 release', 'OpenHarmony 3.2 release'],
482      //       { placeHolder: SELECT_VERSION }
483      //     );
484      //     if (version === 'OpenHarmony 4.1 release') {
485      //       versionTag = '4.1'
486      //     } else if (version === 'OpenHarmony 3.2 release') {
487      //       versionTag = '3.2'
488      //     }
489      //     const serviceId = await vscode.window.showInputBox({
490      //       placeHolder: INPUT_SERVICEID,
491      //       value: "19000", // 设置默认值
492      //       validateInput: (input) => {
493      //           if (!input) {
494      //               return INPUT_NO_EMPTY;
495      //           }
496      //           if (!Number(input)) {
497      //               return INPUT_NUMBER
498      //           }
499      //       }
500      //     });
501      //     generateSa(uri.fsPath, versionTag, serviceId as string);
502      // }
503    });
504    context.subscriptions.push(h2sa);
505
506    const h2hdf = vscode.commands.registerCommand('extension.h2hdf', async (uri) => {
507      let h2hdfCtrl = new H2hdfCtrl(uri);
508      h2hdfCtrl.init();
509        // // The code you place here will be executed every time your command is executed
510        // if (uri && uri.fsPath) {
511        //   let versionTag = '4.1';
512        //   const version = await vscode.window.showQuickPick(['OpenHarmony 4.1 release'], { placeHolder: SELECT_VERSION });
513        //   if (version === 'OpenHarmony 4.1 release') {
514        //     versionTag = '4.1'
515        //   }
516        //   generateHdf(uri.fsPath, versionTag);
517        // }
518    });
519    context.subscriptions.push(h2hdf);
520
521    const h2dts = vscode.commands.registerCommand('extension.h2dts', async (uri: vscode.Uri) => {
522      let h2dtsCtrl = new H2dtsCtrl(uri);
523      h2dtsCtrl.init();
524
525      // // The code you place here will be executed every time your command is executed
526      // if (uri && uri.fsPath) {
527      //   vscode.window.withProgress({
528      //     location: vscode.ProgressLocation.Notification,
529      //     title: "Generating .d.ts ...",
530      //     cancellable: false
531      //   }, async (progress) => {
532      //     // parse
533      //     let parseRes = await parseHeaderFile(uri.fsPath);
534      //     Logger.getInstance().debug('parse header file res: ', parseRes);
535      //     progress.report({ increment: 50, message: PARSE_COMPLETE });
536
537      //     let rootInfo: GenInfo = {
538      //       parseObj: parseRes,
539      //       rawFilePath: uri.fsPath,  // e://xxx.h
540      //       fileName: path.basename(uri.fsPath, '.h')  // xxx
541      //     };
542      //     // generator
543      //     let outPath = genDtsFile(rootInfo);
544      //     progress.report({ increment: 100, message: GEN_COMPLETE + outPath });
545      //   });
546      // }
547    });
548    context.subscriptions.push(h2dts);
549
550    const h2dtscpp = vscode.commands.registerCommand('extension.h2dtscpp', async (uri) => {
551      let h2dtscppCtrl = new H2dtscppCtrl(uri);
552      h2dtscppCtrl.init();
553      // // The code you place here will be executed every time your command is executed
554        // if (uri && uri.fsPath) {
555        //     generateDtscpp(uri.fsPath);
556        // }
557    });
558    context.subscriptions.push(h2dtscpp);
559
560    const dts2cpp = vscode.commands.registerCommand('extension.dts2cpp', (uri) => {
561      let dts2cppCtrl = new Dts2cppCtrl(uri);
562      dts2cppCtrl.init();
563      // The code you place here will be executed every time your command is executed
564      // Logger.getInstance().debug('uri is : ' + uri.fsPath );
565      // if (uri && uri.fsPath) {
566      //   vscode.window.withProgress({
567      //     location: vscode.ProgressLocation.Notification,
568      //     title: "Generating CPP...",
569      //     cancellable: false
570      //   }, async (progress) => {
571      //     const filename = path.basename(uri.fsPath);
572      //     Logger.getInstance().debug('get filename ' );
573      //     if (filename.endsWith('.d.ts')) {
574      //         // Display a message box to the user
575      //         // analyze
576      //         let res = parseTsFile(uri.fsPath);
577      //         Logger.getInstance().info('res: ' + JSON.stringify(res));
578      //         progress.report({ increment: 50, message: PARSE_COMPLETE });
579      //         // generator
580      //         let out = path.dirname(uri.fsPath);
581      //         genCppFile(res, uri.fsPath, out);
582      //         progress.report({ increment: 100, message: GEN_COMPLETE + out });
583      //     } else {
584      //         Logger.getInstance().debug('not dts uri is : ' + uri.fsPath );
585      //         // Display a message box to the user
586      //         vscode.window.showInformationMessage(`${uri.fsPath} is not a .d.ts file!`);
587      //     }
588      //   });
589      // }
590    });
591    context.subscriptions.push(dts2cpp);
592
593    // welcome page in vscode when no file or dir is opened
594    const ohGenerator = vscode.commands.registerCommand('extension.ohGenerator', async () => {
595      let uri = vscode.Uri.parse('');
596      let welcomeCtrl = new WelcomeCtrl(uri);
597      welcomeCtrl.init();
598      // // The code you place here will be executed every time your command is executed
599      // let hPath = path.join(__dirname, '../test/test.h');
600      // let hdfInputPath = path.join(__dirname, '../test/hello.h');
601      // const value = await vscode.window.showQuickPick([HDF_FRAMEWORK, SA_FRAMEWORK, NAPI_FRAMEWORK], { placeHolder: SELECT_FRAMWORK });
602      // // seems no usage
603      // // await vscode.window.showInputBox({
604      // //   placeHolder: CONFIRM_SELECT,
605      // //   validateInput: (input) => {
606      // //     if (!input) {
607      // //       return INPUT_NO_EMPTY;
608      // //     }
609      // //     if (input !== value) {
610      // //       return INPUT_INCONSISTENT;
611      // //     }
612      // //   }
613      // // });
614      // if (value === HDF_FRAMEWORK) {
615      //   // input the version of oh
616      //   let versionTag = '4.1';
617      //   const version = await vscode.window.showQuickPick(['OpenHarmony 4.1 release'], { placeHolder: SELECT_VERSION })
618      //   if (version === 'OpenHarmony 4.1 release') {
619      //     versionTag === '4.1'
620      //   }
621      //   generateHdf(hdfInputPath, versionTag);
622      // } else if (value === SA_FRAMEWORK) {
623      //   // input the version of oh
624      //   let versionTag = '3.2';
625      //   const version = await vscode.window.showQuickPick(['OpenHarmony 3.2 release', 'OpenHarmony 4.1 release'], { placeHolder: SELECT_VERSION })
626      //   if (version === 'OpenHarmony 4.1 release') {
627      //     versionTag = '4.1';
628      //   } else if (version === 'OpenHarmony 3.2 release') {
629      //     versionTag = '3.2';
630      //   }
631      //   const serviceId = await vscode.window.showInputBox({
632      //     placeHolder: INPUT_SERVICEID,
633      //     value: "19000",
634      //     validateInput: (input) => {
635      //         if (!input) {
636      //             return INPUT_NO_EMPTY;
637      //         }
638      //         if (!Number(input)) {
639      //             return INPUT_NUMBER
640      //         }
641      //     }
642      //   });
643      //   generateSa(hPath, versionTag, serviceId as string);
644      // } else if (value === NAPI_FRAMEWORK) {
645      //   generateDtscpp(hPath);
646      // }
647    });
648    context.subscriptions.push(ohGenerator);
649}
650
651// async function generateHdf(hdfInputPath: string, versionTag: string) {
652//   vscode.window.withProgress({
653//     location: vscode.ProgressLocation.Notification,
654//     title: 'Generating HDF...',
655//     cancellable: false
656//   }, async (progress) => {
657//     // analyze
658//     let funDescList = await parseHeaderFile(hdfInputPath);
659//     Logger.getInstance().debug('parse header file res: ', funDescList);
660//     Logger.getInstance().debug('parse header file jsonstr: ', JSON.stringify(funDescList));
661//     progress.report({ increment: 50, message: PARSE_COMPLETE });
662//     // generator
663//     let out = path.dirname(hdfInputPath);
664//     let driverName = path.basename(hdfInputPath, '.h').toLocaleLowerCase();
665//     let rootInfo = {
666//       driverName: driverName,
667//       funcs: funDescList.funcs,
668//       versionTag: versionTag
669//     };
670//     genHdfFile(rootInfo, out);
671//     progress.report({ increment: 100, message: GEN_COMPLETE + out});
672//   });
673//    // show output path
674//    const choice = await vscode.window.showInformationMessage('outPath:', path.dirname(hdfInputPath), OPEN_IN_EXPLORER);
675//    if (choice === OPEN_IN_EXPLORER) {
676//      // open the output folder
677//      vscode.commands.executeCommand('revealFileInOS', vscode.Uri.file(hdfInputPath));
678//    }
679// }
680
681// async function generateSa(hPath: string, versionTag: string, serviceId: string) {
682//   vscode.window.withProgress({
683//     location: vscode.ProgressLocation.Notification,
684//     title: 'Generating SA...',
685//     cancellable: false
686//   }, async (progress) => {
687//     // analyze
688//     let funDescList = await parseHeaderFile(hPath);
689//     Logger.getInstance().debug('parse header file res: ', funDescList);
690//     Logger.getInstance().debug('parse header file jsonstr: ', JSON.stringify(funDescList));
691
692//     progress.report({ increment: 50, message: PARSE_COMPLETE });
693
694//     // generator
695//     let out = path.dirname(hPath);
696//     let serviceName = path.basename(hPath, '.h');
697//     let rootInfo = {
698//       serviceName: serviceName,
699//       funcs: funDescList.funcs,
700//       serviceId: serviceId,
701//       versionTag: versionTag
702//     };
703//     genServiceFile(rootInfo, out);
704//     progress.report({ increment: 100, message: GEN_COMPLETE + out });
705//   });
706//   // show the output path
707//   const choice = await vscode.window.showInformationMessage('outPath:', path.dirname(hPath), OPEN_IN_EXPLORER);
708//   if (choice === OPEN_IN_EXPLORER) {
709//     // open output dir
710//     vscode.commands.executeCommand('revealFileInOS', vscode.Uri.file(hPath));
711//   }
712// }
713
714// async function generateDtscpp(hFilePath: string) {
715//   vscode.window.withProgress({
716//     location: vscode.ProgressLocation.Notification,
717//     title: 'Generating DTSCPP...',
718//     cancellable: false
719//   }, async (progress) => {
720//     // analyze
721//     let funDescList = await parseHeaderFile(hFilePath);
722//     let fileName = path.basename(hFilePath, '.h');
723//     Logger.getInstance().debug('parse header file res: ', funDescList);
724//     Logger.getInstance().debug('parse header file jsonstr: ', JSON.stringify(funDescList));
725
726//     progress.report({ increment: 50, message: PARSE_COMPLETE });
727
728//     let rootInfo: DtscppRootInfo = {
729//       funcs: funDescList.funcs,
730//       rawFilePath: hFilePath,
731//       fileName: fileName // xxx
732//     };
733
734//     // generator
735//     let out = path.dirname(hFilePath);
736//     genDtsCppFile(rootInfo, out);
737//     progress.report({ increment: 100, message: GEN_COMPLETE + out });
738//   });
739//   // show genarate path
740//   const choice = await vscode.window.showInformationMessage('outPath:', path.dirname(hFilePath), OPEN_IN_EXPLORER);
741//   if (choice === OPEN_IN_EXPLORER) {
742//     // open the folder
743//     vscode.commands.executeCommand('revealFileInOS', vscode.Uri.file(hFilePath));
744//   }
745// }
746
747