Skip to content

Commit b958ca4

Browse files
committed
add cosmic-stm8 licence request & activate ui
1 parent b1b793b commit b958ca4

4 files changed

Lines changed: 322 additions & 3 deletions

File tree

res/icon/Login_16x.svg

Lines changed: 1 addition & 0 deletions
Loading

src/OperationExplorer.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ import {
4545
view_str$prompt$tool_install_mode_online, view_str$prompt$tool_install_mode_local, view_str$operation$empty_anygcc_prj, view_str$operation$setupUtilTools,
4646
view_str$prompt$setupToolchainPrefix,
4747
view_str$prompt$needReloadToUpdateEnv,
48-
view_str$operation$create_prj_done
48+
view_str$operation$create_prj_done,
49+
view_str$prompt$requestAndActivateLicence
4950
} from './StringTable';
5051
import { CreateOptions, ImportOptions, ProjectType } from './EIDETypeDefine';
5152
import { File } from '../lib/node-utility/File';
@@ -56,6 +57,7 @@ import { ToolchainName, ToolchainManager } from './ToolchainManager';
5657
import { GitFileInfo } from './WebInterface/GithubInterface';
5758
import { TemplateIndexDef, TemplateInfo } from './WebInterface/WebInterface';
5859
import * as utility from './utility';
60+
import * as toolchainLicence from './ToolchainLicenceActive';
5961

6062
import * as events from 'events';
6163
import * as fs from 'fs';
@@ -671,7 +673,13 @@ export class OperationExplorer {
671673
type: 'COSMIC_STM8',
672674
description: this.getStatusTxt(toolchainManager.isToolchainPathReady('COSMIC_STM8'))
673675
+ ` Loc: ${toolchainManager.getToolchainExecutableFolder('COSMIC_STM8')?.path}`,
674-
detail: view_str$operation$setToolchainInstallDir.replace('${name}', 'COSMIC_STM8')
676+
detail: view_str$operation$setToolchainInstallDir.replace('${name}', 'COSMIC_STM8'),
677+
buttons: [
678+
{
679+
iconPath: vscode.Uri.file(resManager.GetIconByName('Login_16x.svg').path),
680+
tooltip: view_str$prompt$requestAndActivateLicence
681+
}
682+
]
675683
},
676684
/* {
677685
label: 'SDCC With GNU Patch For STM8 (Only for stm8)',
@@ -805,6 +813,14 @@ export class OperationExplorer {
805813
utility.notifyReloadWindow(view_str$prompt$needReloadToUpdateEnv);
806814
}
807815
}
816+
817+
if (ctx.button.tooltip == view_str$prompt$requestAndActivateLicence) {
818+
819+
picker.hide();
820+
picker.dispose();
821+
822+
toolchainLicence.requestAndActivateLicence(ctx.item.type);
823+
}
808824
});
809825

810826
picker.onDidAccept(() => {

src/StringTable.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export enum LanguageIndexs {
2929
English
3030
}
3131

32-
let langIndex: number = /zh-cn/.test(vscode.env.language)
32+
let langIndex: number = /zh-cn/i.test(vscode.env.language)
3333
? LanguageIndexs.Chinese
3434
: LanguageIndexs.English;
3535

@@ -429,6 +429,16 @@ export const view_str$prompt$setupToolchainPrefix = [
429429
`Setup Compiler Prefix`
430430
][langIndex];
431431

432+
export const view_str$prompt$requestAndActivateLicence = [
433+
`获取并激活许可证`,
434+
`Obtain And Active Licence`
435+
][langIndex];
436+
437+
export const view_str$prompt$requestAndActivateLicence_warn_setupPath = [
438+
`在开始之前激活之前,你必须先安装并设置编译器的路径!`,
439+
`Before you start activating, you must install and set the path of the compiler !`
440+
][langIndex];
441+
432442
export const view_str$prompt$need_reload_project = [
433443
`'{}' 的项目文件 'eide.json' 已被更改,重新加载项目?`,
434444
`The project file 'eide.json' of '{}' has been changed !, reload it ?`

src/ToolchainLicenceActive.ts

Lines changed: 292 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,292 @@
1+
import { ToolchainName, IToolchian, ToolchainManager } from "./ToolchainManager";
2+
import { GlobalEvent } from "./GlobalEvents";
3+
import { newMessage } from "./Message";
4+
import { view_str$prompt$requestAndActivateLicence_warn_setupPath, getLocalLanguageType, LanguageIndexs } from "./StringTable";
5+
import { SimpleUIConfig, SimpleUIConfigData_tag, SimpleUIConfigData_divider, SimpleUIConfigData_input, SimpleUIConfigData_button } from './SimpleUIDef';
6+
import { WebPanelManager } from "./WebPanelManager";
7+
import { runShellCommand, openUrl } from "./utility";
8+
import { File } from "../lib/node-utility/File";
9+
10+
import * as path from "path";
11+
import * as os from "os";
12+
import * as fs from "fs";
13+
import * as vscode from "vscode";
14+
15+
export function requestAndActivateLicence(toolchainId: ToolchainName) {
16+
17+
const toolchain_ = ToolchainManager.getInstance().getToolchainByName(toolchainId);
18+
if (!toolchain_) {
19+
GlobalEvent.emit('msg', newMessage('Error', `Not found this toolchain: '${toolchainId}' !`));
20+
return;
21+
}
22+
23+
if (!ToolchainManager.getInstance().isToolchainPathReady(toolchainId)) {
24+
GlobalEvent.emit('msg', newMessage('Warning', view_str$prompt$requestAndActivateLicence_warn_setupPath));
25+
return;
26+
}
27+
28+
switch (toolchainId) {
29+
case 'COSMIC_STM8':
30+
requestAndActivate_COSMIC_STM8(toolchain_);
31+
break;
32+
default:
33+
GlobalEvent.emit('msg', newMessage('Warning', `We not support this toolchain: '${toolchainId}' !`));
34+
break;
35+
}
36+
}
37+
38+
function requestAndActivate_COSMIC_STM8(toolchain: IToolchian) {
39+
40+
const toolchainRootDir = toolchain.getToolchainDir();
41+
const isChinese = getLocalLanguageType() == LanguageIndexs.Chinese;
42+
43+
const ui_1: SimpleUIConfig = isChinese
44+
45+
// chinese
46+
? {
47+
title: '申请 COSMIC STM8 编译器许可证',
48+
viewColumn: vscode.ViewColumn.One,
49+
notTakeFocus: false,
50+
btns: {
51+
'submit': {
52+
title: '发送申请',
53+
hidden: false
54+
},
55+
'reset': {
56+
title: '',
57+
hidden: true
58+
}
59+
},
60+
items: {
61+
'userName': {
62+
type: 'input',
63+
name: '输入用户名(系统的当前账户名)',
64+
attrs: { 'singleLine': true },
65+
data: <SimpleUIConfigData_input>{
66+
value: path.basename(os.homedir())
67+
}
68+
},
69+
'hostId': {
70+
type: 'input',
71+
name: '输入主机ID',
72+
attrs: { 'singleLine': true },
73+
data: <SimpleUIConfigData_input>{
74+
value: ''
75+
}
76+
},
77+
'hostId-1': {
78+
type: 'button',
79+
name: '查看当前的主机ID',
80+
attrs: {},
81+
data: <SimpleUIConfigData_button>{
82+
clickEvent: 'btn.show-host-id'
83+
}
84+
},
85+
'email': {
86+
type: 'input',
87+
name: '输入你的邮箱(用于接收许可证)',
88+
attrs: { 'singleLine': true },
89+
data: <SimpleUIConfigData_input>{
90+
placeHolder: 'xxx@xxx.xx',
91+
value: ''
92+
}
93+
}
94+
}
95+
}
96+
// en-us
97+
: {
98+
99+
title: 'Request Licence For COSMIC STM8 Compiler',
100+
viewColumn: vscode.ViewColumn.One,
101+
notTakeFocus: false,
102+
btns: {
103+
'submit': {
104+
title: 'Send Request',
105+
hidden: false
106+
},
107+
'reset': {
108+
title: '',
109+
hidden: true
110+
}
111+
},
112+
items: {
113+
'userName': {
114+
type: 'input',
115+
name: 'User Name For This PC',
116+
attrs: { 'singleLine': true },
117+
data: <SimpleUIConfigData_input>{
118+
value: path.basename(os.homedir())
119+
}
120+
},
121+
'hostId': {
122+
type: 'input',
123+
name: 'Enter Your Host ID',
124+
attrs: { 'singleLine': true },
125+
data: <SimpleUIConfigData_input>{
126+
value: ''
127+
}
128+
},
129+
'hostId-1': {
130+
type: 'button',
131+
name: 'Show My Host ID',
132+
attrs: {},
133+
data: <SimpleUIConfigData_button>{
134+
clickEvent: 'btn.show-host-id'
135+
}
136+
},
137+
'email': {
138+
type: 'input',
139+
name: 'Enter Your Email (to receive licence file)',
140+
attrs: { 'singleLine': true },
141+
data: <SimpleUIConfigData_input>{
142+
placeHolder: 'xxx@xxx.xx',
143+
value: ''
144+
}
145+
}
146+
}
147+
};
148+
149+
WebPanelManager.instance().showSimpleConfigUI(ui_1,
150+
151+
// on submited
152+
(data) => {
153+
154+
// http://vps362893.ovh.net/registerAuto.php?name={1}&hostid={2}&mail={3}&product=LXSTM8FSE_2023
155+
// 其中:
156+
// - {1} 填 用户名
157+
// - {2} 填 主机ID
158+
// - {3} 填 邮箱
159+
160+
const usrNam = data.items['userName'].data.value.trim();
161+
const hostId = data.items['hostId'].data.value.replace(/"/g, '').trim();
162+
const email_ = data.items['email'].data.value.trim();
163+
164+
const url = `http://vps362893.ovh.net/registerAuto.php?name=${usrNam}&hostid=${hostId}&mail=${email_}&product=LXSTM8FSE_2023`;
165+
166+
openUrl(url);
167+
},
168+
169+
// on msg
170+
(msg) => {
171+
172+
if (msg == 'btn.show-host-id') {
173+
174+
runShellCommand('(COSMIC) show host id',
175+
'LmregFSE', undefined, true, toolchainRootDir.path);
176+
}
177+
});
178+
179+
setTimeout(() => {
180+
181+
const ui_2: SimpleUIConfig = isChinese
182+
183+
// chinese
184+
? {
185+
title: '激活 COSMIC STM8 编译器许可证',
186+
viewColumn: vscode.ViewColumn.Two,
187+
notTakeFocus: true,
188+
btns: {
189+
'submit': {
190+
title: '激活',
191+
hidden: false
192+
},
193+
'reset': {
194+
title: '',
195+
hidden: true
196+
}
197+
},
198+
items: {
199+
'licence': {
200+
type: 'input',
201+
name: `输入你收到的许可证(邮件附件 'licence.lic' 的完整内容)`,
202+
attrs: { 'singleLine': false, 'rows': 15 },
203+
data: <SimpleUIConfigData_input>{
204+
placeHolder: [
205+
`#`,
206+
`# Please don't change or add any lines in this file`,
207+
`# Generated automatically by Cosmic website on 2023-04-09 07:34:46`,
208+
`#`,
209+
`FEATURE LXSTM8FSE_202X cosmic 31.1 09-apr-2024 uncounted \\`,
210+
` HOSTID="xxxxxxxx xxxxxxxx" SIGN=xxxxxxxx`,
211+
`FEATURE LXSTM8FSE_2020 cosmic 31.1 09-apr-2024 uncounted \\`,
212+
` HOSTID="xxxxxxxx xxxxxxxx" SIGN=xxxxxxxx`,
213+
`FEATURE LXSTM8FSE_2019 cosmic 31.1 09-apr-2024 uncounted \\`,
214+
` HOSTID="xxxxxxxx xxxxxxxx" SIGN=xxxxxxxx`,
215+
`FEATURE LXSTM8FSE_2018 cosmic 31.1 09-apr-2024 uncounted \\`,
216+
` HOSTID="xxxxxxxx xxxxxxxx" SIGN=xxxxxxxx`,
217+
`FEATURE LXSTM8FSE_2017 cosmic 31.1 09-apr-2024 uncounted \\`,
218+
` HOSTID="xxxxxxxx xxxxxxxx" SIGN=xxxxxxxx`,
219+
].join(os.EOL),
220+
value: ''
221+
}
222+
}
223+
}
224+
}
225+
// en-us
226+
: {
227+
title: 'Activate Licence For COSMIC STM8 Compiler',
228+
viewColumn: vscode.ViewColumn.Two,
229+
notTakeFocus: true,
230+
btns: {
231+
'submit': {
232+
title: 'Activate',
233+
hidden: false
234+
},
235+
'reset': {
236+
title: '',
237+
hidden: true
238+
}
239+
},
240+
items: {
241+
'licence': {
242+
type: 'input',
243+
name: `Enter Your Licence (Content of 'licence.lic' file in your email)`,
244+
attrs: { 'singleLine': false, 'rows': 15 },
245+
data: <SimpleUIConfigData_input>{
246+
placeHolder: [
247+
`#`,
248+
`# Please don't change or add any lines in this file`,
249+
`# Generated automatically by Cosmic website on 2023-04-09 07:34:46`,
250+
`#`,
251+
`FEATURE LXSTM8FSE_202X cosmic 31.1 09-apr-2024 uncounted \\`,
252+
` HOSTID="xxxxxxxx xxxxxxxx" SIGN=xxxxxxxx`,
253+
`FEATURE LXSTM8FSE_2020 cosmic 31.1 09-apr-2024 uncounted \\`,
254+
` HOSTID="xxxxxxxx xxxxxxxx" SIGN=xxxxxxxx`,
255+
`FEATURE LXSTM8FSE_2019 cosmic 31.1 09-apr-2024 uncounted \\`,
256+
` HOSTID="xxxxxxxx xxxxxxxx" SIGN=xxxxxxxx`,
257+
`FEATURE LXSTM8FSE_2018 cosmic 31.1 09-apr-2024 uncounted \\`,
258+
` HOSTID="xxxxxxxx xxxxxxxx" SIGN=xxxxxxxx`,
259+
`FEATURE LXSTM8FSE_2017 cosmic 31.1 09-apr-2024 uncounted \\`,
260+
` HOSTID="xxxxxxxx xxxxxxxx" SIGN=xxxxxxxx`,
261+
].join(os.EOL),
262+
value: ''
263+
}
264+
}
265+
}
266+
};
267+
268+
WebPanelManager.instance().showSimpleConfigUI(ui_2,
269+
270+
// on submited
271+
(data) => {
272+
273+
const licenceCont: string = data.items['licence'].data.value;
274+
275+
if (!licenceCont.trim()) {
276+
throw new Error('licence can not be empty !');
277+
}
278+
279+
let outDir: File;
280+
281+
const dirs = toolchainRootDir.GetList(File.EXCLUDE_ALL_FILTER, [/License/i]);
282+
if (dirs.length == 0) {
283+
outDir = File.fromArray([toolchainRootDir.path, 'License']);
284+
outDir.CreateDir(false);
285+
} else {
286+
outDir = dirs[0];
287+
}
288+
289+
fs.writeFileSync(outDir.path + File.sep + 'license.lic', licenceCont);
290+
});
291+
}, 600);
292+
}

0 commit comments

Comments
 (0)