move lang.py and inlinee-sciter.py to res

This commit is contained in:
rustdesk
2022-09-18 11:53:15 +08:00
parent 5751b23a97
commit b7e54081b8
4 changed files with 8 additions and 1 deletions

7
res/gen_icon.sh Normal file
View File

@@ -0,0 +1,7 @@
#!/bin/bash
for size in 16 32 64 128 256 512 1024; do
#inkscape -z -o $size.png -w $size -h $size icon.svg >/dev/null 2>/dev/null
convert icon.png -resize ${size}x${size} app_icon_$size.png
done
# from ImageMagick
#/bin/rm 16.png 32.png 48.png 128.png 256.png

81
res/inline-sciter.py Normal file
View File

@@ -0,0 +1,81 @@
#!/usr/bin/env python3
import re
def strip(s): return re.sub(r'\s+\n', '\n', re.sub(r'\n\s+', '\n', s))
common_css = open('src/ui/common.css').read()
common_tis = open('src/ui/common.tis', encoding='UTF8').read()
index = open('src/ui/index.html').read() \
.replace('@import url(index.css);', open('src/ui/index.css').read()) \
.replace('include "index.tis";', open('src/ui/index.tis').read()) \
.replace('include "msgbox.tis";', open('src/ui/msgbox.tis').read()) \
.replace('include "ab.tis";', open('src/ui/ab.tis').read())
remote = open('src/ui/remote.html').read() \
.replace('@import url(remote.css);', open('src/ui/remote.css').read()) \
.replace('@import url(header.css);', open('src/ui/header.css').read()) \
.replace('@import url(file_transfer.css);', open('src/ui/file_transfer.css').read()) \
.replace('include "remote.tis";', open('src/ui/remote.tis').read()) \
.replace('include "msgbox.tis";', open('src/ui/msgbox.tis').read()) \
.replace('include "grid.tis";', open('src/ui/grid.tis').read()) \
.replace('include "header.tis";', open('src/ui/header.tis').read()) \
.replace('include "file_transfer.tis";', open('src/ui/file_transfer.tis').read()) \
.replace('include "port_forward.tis";', open('src/ui/port_forward.tis').read())
chatbox = open('src/ui/chatbox.html').read()
install = open('src/ui/install.html').read().replace('include "install.tis";', open('src/ui/install.tis').read())
cm = open('src/ui/cm.html').read() \
.replace('@import url(cm.css);', open('src/ui/cm.css').read()) \
.replace('include "cm.tis";', open('src/ui/cm.tis').read())
def compress(s):
s = s.replace("\r\n", "\n")
x = bytes(s, encoding='utf-8')
return '&[u8; ' + str(len(x)) + '] = b"' + str(x)[2:-1].replace(r"\'", "'").replace(r'"',
r'\"') + '"'
with open('src/ui/inline.rs', 'wt') as fh:
fh.write('const _COMMON_CSS: ' + compress(strip(common_css)) + ';\n')
fh.write('const _COMMON_TIS: ' + compress(strip(common_tis)) + ';\n')
fh.write('const _INDEX: ' + compress(strip(index)) + ';\n')
fh.write('const _REMOTE: ' + compress(strip(remote)) + ';\n')
fh.write('const _CHATBOX: ' + compress(strip(chatbox)) + ';\n')
fh.write('const _INSTALL: ' + compress(strip(install)) + ';\n')
fh.write('const _CONNECTION_MANAGER: ' + compress(strip(cm)) + ';\n')
fh.write('''
fn get(data: &[u8]) -> String {
String::from_utf8_lossy(data).to_string()
}
fn replace(data: &[u8]) -> String {
let css = get(&_COMMON_CSS[..]);
let res = get(data).replace("@import url(common.css);", &css);
let tis = get(&_COMMON_TIS[..]);
res.replace("include \\\"common.tis\\\";", &tis)
}
#[inline]
pub fn get_index() -> String {
replace(&_INDEX[..])
}
#[inline]
pub fn get_remote() -> String {
replace(&_REMOTE[..])
}
#[inline]
pub fn get_install() -> String {
replace(&_INSTALL[..])
}
#[inline]
pub fn get_chatbox() -> String {
replace(&_CHATBOX[..])
}
#[inline]
pub fn get_cm() -> String {
replace(&_CONNECTION_MANAGER[..])
}
''')

82
res/lang.py Normal file
View File

@@ -0,0 +1,82 @@
#!/usr/bin/env python3
import os
import glob
import sys
import csv
def get_lang(lang):
out = {}
for ln in open('./src/lang/%s.rs'%lang):
ln = ln.strip()
if ln.startswith('("'):
k, v = line_split(ln)
out[k] = v
return out
def line_split(line):
toks = line.split('", "')
assert(len(toks) == 2)
k = toks[0][2:]
v = toks[1][:-3]
return k, v
def main():
if len(sys.argv) == 1:
expand()
elif sys.argv[1] == '1':
to_csv()
else:
to_rs(sys.argv[1])
def expand():
for fn in glob.glob('./src/lang/*'):
lang = os.path.basename(fn)[:-3]
if lang in ['en','cn']: continue
dict = get_lang(lang)
fw = open("%s.rs"%lang, "wt")
for line in open('./src/lang/cn.rs'):
line_strip = line.strip()
if line_strip.startswith('("'):
k, v = line_split(line_strip)
if k in dict:
line = line.replace(v, dict[k])
else:
line = line.replace(v, "")
fw.write(line)
else:
fw.write(line)
fw.close()
def to_csv():
for fn in glob.glob('./src/lang/*.rs'):
lang = os.path.basename(fn)[:-3]
csvfile = open('./src/lang/%s.csv'%lang, "wt")
csvwriter = csv.writer(csvfile)
for line in open(fn):
line_strip = line.strip()
if line_strip.startswith('("'):
k, v = line_split(line_strip)
csvwriter.writerow([k, v])
csvfile.close()
def to_rs(lang):
csvfile = open('%s.csv'%lang, "rt")
fw = open("./src/lang/%s.rs"%lang, "wt")
fw.write('''lazy_static::lazy_static! {
pub static ref T: std::collections::HashMap<&'static str, &'static str> =
[
''')
for row in csv.reader(csvfile):
fw.write(' ("%s", "%s"),\n'%(row[0].replace('"', '\"'), row[1].replace('"', '\"')))
fw.write(''' ].iter().cloned().collect();
}
''')
fw.close()
main()