| 
									
										
										
										
											2024-04-02 18:10:09 +08:00
										 |  |  | #!/usr/bin/env python3 | 
					
						
							|  |  |  | # -*- coding: utf-8 -*- | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-11 11:51:35 +08:00
										 |  |  | import json | 
					
						
							| 
									
										
										
										
											2024-04-02 18:10:09 +08:00
										 |  |  | import sys | 
					
						
							|  |  |  | import uuid | 
					
						
							|  |  |  | import argparse | 
					
						
							| 
									
										
										
										
											2024-04-11 11:51:35 +08:00
										 |  |  | import datetime | 
					
						
							| 
									
										
										
										
											2024-04-19 17:57:04 +08:00
										 |  |  | import subprocess | 
					
						
							| 
									
										
										
										
											2024-04-11 11:51:35 +08:00
										 |  |  | import re | 
					
						
							| 
									
										
										
										
											2024-04-02 18:10:09 +08:00
										 |  |  | from pathlib import Path | 
					
						
							| 
									
										
										
										
											2024-04-25 22:35:51 +08:00
										 |  |  | import shutil | 
					
						
							| 
									
										
										
										
											2024-04-02 18:10:09 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | g_indent_unit = "\t" | 
					
						
							| 
									
										
										
										
											2024-04-11 11:51:35 +08:00
										 |  |  | g_version = "" | 
					
						
							|  |  |  | g_build_date = datetime.datetime.now().strftime("%Y-%m-%d %H:%M") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-16 13:09:20 +08:00
										 |  |  | # Replace the following links with your own in the custom arp properties. | 
					
						
							| 
									
										
										
										
											2024-04-11 11:51:35 +08:00
										 |  |  | # https://learn.microsoft.com/en-us/windows/win32/msi/property-reference | 
					
						
							|  |  |  | g_arpsystemcomponent = { | 
					
						
							|  |  |  |     "Comments": { | 
					
						
							|  |  |  |         "msi": "ARPCOMMENTS", | 
					
						
							|  |  |  |         "t": "string", | 
					
						
							|  |  |  |         "v": "!(loc.AR_Comment)", | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     "Contact": { | 
					
						
							|  |  |  |         "msi": "ARPCONTACT", | 
					
						
							|  |  |  |         "v": "https://github.com/rustdesk/rustdesk", | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     "HelpLink": { | 
					
						
							|  |  |  |         "msi": "ARPHELPLINK", | 
					
						
							|  |  |  |         "v": "https://github.com/rustdesk/rustdesk/issues/", | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     "ReadMe": { | 
					
						
							|  |  |  |         "msi": "ARPREADME", | 
					
						
							| 
									
										
										
										
											2024-07-20 23:49:40 +08:00
										 |  |  |         "v": "https://github.com/rustdesk/rustdesk", | 
					
						
							| 
									
										
										
										
											2024-04-11 11:51:35 +08:00
										 |  |  |     }, | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2024-04-02 18:10:09 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-22 23:37:25 +08:00
										 |  |  | def default_revision_version(): | 
					
						
							|  |  |  |     return int(datetime.datetime.now().timestamp() / 60) | 
					
						
							| 
									
										
										
										
											2024-04-02 18:10:09 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | def make_parser(): | 
					
						
							|  |  |  |     parser = argparse.ArgumentParser(description="Msi preprocess script.") | 
					
						
							|  |  |  |     parser.add_argument( | 
					
						
							| 
									
										
										
										
											2024-04-16 14:12:39 +08:00
										 |  |  |         "-d", | 
					
						
							|  |  |  |         "--dist-dir", | 
					
						
							|  |  |  |         type=str, | 
					
						
							|  |  |  |         default="../../rustdesk", | 
					
						
							|  |  |  |         help="The dist direcotry to install.", | 
					
						
							| 
									
										
										
										
											2024-04-11 11:51:35 +08:00
										 |  |  |     ) | 
					
						
							|  |  |  |     parser.add_argument( | 
					
						
							|  |  |  |         "--arp", | 
					
						
							|  |  |  |         action="store_true", | 
					
						
							|  |  |  |         help="Is ARPSYSTEMCOMPONENT", | 
					
						
							|  |  |  |         default=False, | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     parser.add_argument( | 
					
						
							|  |  |  |         "--custom-arp", | 
					
						
							|  |  |  |         type=str, | 
					
						
							|  |  |  |         default="{}", | 
					
						
							|  |  |  |         help='Custom arp properties, e.g. \'["Comments": {"msi": "ARPCOMMENTS", "v": "Remote control application."}]\'', | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2024-04-02 18:10:09 +08:00
										 |  |  |     parser.add_argument( | 
					
						
							|  |  |  |         "-c", "--custom", action="store_true", help="Is custom client", default=False | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2024-08-01 15:08:52 +08:00
										 |  |  |     parser.add_argument( | 
					
						
							| 
									
										
										
										
											2024-08-03 22:29:30 +08:00
										 |  |  |         "--conn-type", | 
					
						
							| 
									
										
										
										
											2024-08-01 15:08:52 +08:00
										 |  |  |         type=str, | 
					
						
							| 
									
										
										
										
											2024-08-03 22:29:30 +08:00
										 |  |  |         default="", | 
					
						
							|  |  |  |         help='Connection type, e.g. "incoming", "outgoing". Default is empty, means incoming-outgoing', | 
					
						
							| 
									
										
										
										
											2024-08-01 15:08:52 +08:00
										 |  |  |     ) | 
					
						
							| 
									
										
										
										
											2024-04-02 18:10:09 +08:00
										 |  |  |     parser.add_argument( | 
					
						
							| 
									
										
										
										
											2024-04-19 17:57:04 +08:00
										 |  |  |         "--app-name", type=str, default="RustDesk", help="The app name." | 
					
						
							| 
									
										
										
										
											2024-04-02 18:10:09 +08:00
										 |  |  |     ) | 
					
						
							|  |  |  |     parser.add_argument( | 
					
						
							| 
									
										
										
										
											2024-04-11 11:51:35 +08:00
										 |  |  |         "-v", "--version", type=str, default="", help="The app version." | 
					
						
							| 
									
										
										
										
											2024-04-02 18:10:09 +08:00
										 |  |  |     ) | 
					
						
							| 
									
										
										
										
											2024-07-22 23:37:25 +08:00
										 |  |  |     parser.add_argument( | 
					
						
							|  |  |  |         "--revision-version", type=int, default=default_revision_version(), help="The revision version." | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2024-04-02 18:10:09 +08:00
										 |  |  |     parser.add_argument( | 
					
						
							|  |  |  |         "-m", | 
					
						
							|  |  |  |         "--manufacturer", | 
					
						
							|  |  |  |         type=str, | 
					
						
							| 
									
										
										
										
											2024-04-15 21:19:46 +08:00
										 |  |  |         default="PURSLANE", | 
					
						
							| 
									
										
										
										
											2024-04-02 18:10:09 +08:00
										 |  |  |         help="The app manufacturer.", | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     return parser | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-03 14:27:35 +08:00
										 |  |  | def read_lines_and_start_index(file_path, tag_start, tag_end): | 
					
						
							| 
									
										
											  
											
												Refact/msi more install options (#8949)
* refact: msi, more install options
Signed-off-by: fufesou <linlong1266@gmail.com>
* refact: msi, reg values on upgrade/modify
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: msi, silent repair/upgrade, RemoveInstallFolder()
Signed-off-by: fufesou <linlong1266@gmail.com>
* Options support both 1/0 and Y/N
Signed-off-by: fufesou <linlong1266@gmail.com>
* refact: msi, preprocess, open file with explicit encoding
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: msi, read previous options
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: mis, install folder, read previous option
Signed-off-by: fufesou <linlong1266@gmail.com>
* Comment on Control -> Checkbox
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: UI, checkbox options, read previous values
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: shortcuts options, init state
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: shortcuts, init state
Signed-off-by: fufesou <linlong1266@gmail.com>
* Better shortcuts property conditions
Signed-off-by: fufesou <linlong1266@gmail.com>
---------
Signed-off-by: fufesou <linlong1266@gmail.com>
											
										 
											2024-08-05 17:49:48 +08:00
										 |  |  |     with open(file_path, "r", encoding="utf-8") as f: | 
					
						
							| 
									
										
										
										
											2024-04-02 18:10:09 +08:00
										 |  |  |         lines = f.readlines() | 
					
						
							| 
									
										
										
										
											2024-04-03 14:27:35 +08:00
										 |  |  |     index_start = -1 | 
					
						
							|  |  |  |     index_end = -1 | 
					
						
							| 
									
										
										
										
											2024-04-02 18:10:09 +08:00
										 |  |  |     for i, line in enumerate(lines): | 
					
						
							| 
									
										
										
										
											2024-04-03 14:27:35 +08:00
										 |  |  |         if tag_start in line: | 
					
						
							|  |  |  |             index_start = i | 
					
						
							|  |  |  |         if tag_end in line: | 
					
						
							|  |  |  |             index_end = i | 
					
						
							| 
									
										
										
										
											2024-04-02 18:10:09 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-03 14:27:35 +08:00
										 |  |  |     if index_start == -1: | 
					
						
							|  |  |  |         print(f'Error: start tag "{tag_start}" not found') | 
					
						
							| 
									
										
										
										
											2024-04-02 18:10:09 +08:00
										 |  |  |         return None, None | 
					
						
							| 
									
										
										
										
											2024-04-03 14:27:35 +08:00
										 |  |  |     if index_end == -1: | 
					
						
							|  |  |  |         print(f'Error: end tag "{tag_end}" not found') | 
					
						
							|  |  |  |         return None, None | 
					
						
							|  |  |  |     return lines, index_start | 
					
						
							| 
									
										
										
										
											2024-04-02 18:10:09 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-11 18:54:32 +08:00
										 |  |  | def insert_components_between_tags(lines, index_start, app_name, dist_dir): | 
					
						
							| 
									
										
										
										
											2024-04-02 18:10:09 +08:00
										 |  |  |     indent = g_indent_unit * 3 | 
					
						
							| 
									
										
										
										
											2024-04-11 18:54:32 +08:00
										 |  |  |     path = Path(dist_dir) | 
					
						
							| 
									
										
										
										
											2024-04-02 18:10:09 +08:00
										 |  |  |     idx = 1 | 
					
						
							|  |  |  |     for file_path in path.glob("**/*"): | 
					
						
							|  |  |  |         if file_path.is_file(): | 
					
						
							|  |  |  |             if file_path.name.lower() == f"{app_name}.exe".lower(): | 
					
						
							|  |  |  |                 continue | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             subdir = str(file_path.parent.relative_to(path)) | 
					
						
							|  |  |  |             dir_attr = "" | 
					
						
							|  |  |  |             if subdir != ".": | 
					
						
							|  |  |  |                 dir_attr = f'Subdirectory="{subdir}"' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             # Don't generate Component Id and File Id like 'Component_{idx}' and 'File_{idx}' | 
					
						
							|  |  |  |             # because it will cause error | 
					
						
							|  |  |  |             # "Error WIX0130	The primary key 'xxxx' is duplicated in table 'Directory'" | 
					
						
							|  |  |  |             to_insert_lines = f"""
 | 
					
						
							| 
									
										
										
										
											2024-04-16 14:12:39 +08:00
										 |  |  | {indent}<Component Guid="{uuid.uuid4()}" {dir_attr}> | 
					
						
							| 
									
										
										
										
											2024-04-02 18:10:09 +08:00
										 |  |  | {indent}{g_indent_unit}<File Source="{file_path.as_posix()}" KeyPath="yes" Checksum="yes" /> | 
					
						
							|  |  |  | {indent}</Component> | 
					
						
							|  |  |  | """
 | 
					
						
							| 
									
										
										
										
											2024-04-03 14:27:35 +08:00
										 |  |  |             lines.insert(index_start + 1, to_insert_lines[1:]) | 
					
						
							|  |  |  |             index_start += 1 | 
					
						
							| 
									
										
										
										
											2024-04-02 18:10:09 +08:00
										 |  |  |             idx += 1 | 
					
						
							|  |  |  |     return True | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-11 18:54:32 +08:00
										 |  |  | def gen_auto_component(app_name, dist_dir): | 
					
						
							| 
									
										
										
										
											2024-04-03 14:27:35 +08:00
										 |  |  |     return gen_content_between_tags( | 
					
						
							|  |  |  |         "Package/Components/RustDesk.wxs", | 
					
						
							|  |  |  |         "<!--$AutoComonentStart$-->", | 
					
						
							|  |  |  |         "<!--$AutoComponentEnd$-->", | 
					
						
							|  |  |  |         lambda lines, index_start: insert_components_between_tags( | 
					
						
							| 
									
										
										
										
											2024-04-11 18:54:32 +08:00
										 |  |  |             lines, index_start, app_name, dist_dir | 
					
						
							| 
									
										
										
										
											2024-04-03 14:27:35 +08:00
										 |  |  |         ), | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2024-04-02 18:10:09 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-11 18:54:32 +08:00
										 |  |  | def gen_pre_vars(args, dist_dir): | 
					
						
							| 
									
										
										
										
											2024-04-03 14:27:35 +08:00
										 |  |  |     def func(lines, index_start): | 
					
						
							|  |  |  |         upgrade_code = uuid.uuid5(uuid.NAMESPACE_OID, app_name + ".exe") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         indent = g_indent_unit * 1 | 
					
						
							|  |  |  |         to_insert_lines = [ | 
					
						
							| 
									
										
										
										
											2024-04-11 11:51:35 +08:00
										 |  |  |             f'{indent}<?define Version="{g_version}" ?>\n', | 
					
						
							| 
									
										
										
										
											2024-04-03 14:27:35 +08:00
										 |  |  |             f'{indent}<?define Manufacturer="{args.manufacturer}" ?>\n', | 
					
						
							|  |  |  |             f'{indent}<?define Product="{args.app_name}" ?>\n', | 
					
						
							|  |  |  |             f'{indent}<?define Description="{args.app_name} Installer" ?>\n', | 
					
						
							|  |  |  |             f'{indent}<?define ProductLower="{args.app_name.lower()}" ?>\n', | 
					
						
							|  |  |  |             f'{indent}<?define RegKeyRoot=".$(var.ProductLower)" ?>\n', | 
					
						
							| 
									
										
										
										
											2024-04-19 17:57:04 +08:00
										 |  |  |             f'{indent}<?define RegKeyInstall="$(var.RegKeyRoot)\\Install" ?>\n', | 
					
						
							| 
									
										
										
										
											2024-04-11 18:54:32 +08:00
										 |  |  |             f'{indent}<?define BuildDir="{dist_dir}" ?>\n', | 
					
						
							| 
									
										
										
										
											2024-04-11 11:51:35 +08:00
										 |  |  |             f'{indent}<?define BuildDate="{g_build_date}" ?>\n', | 
					
						
							| 
									
										
										
										
											2024-04-03 14:27:35 +08:00
										 |  |  |             "\n", | 
					
						
							|  |  |  |             f"{indent}<!-- The UpgradeCode must be consistent for each product. ! -->\n" | 
					
						
							|  |  |  |             f'{indent}<?define UpgradeCode = "{upgrade_code}" ?>\n', | 
					
						
							|  |  |  |         ] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         for i, line in enumerate(to_insert_lines): | 
					
						
							|  |  |  |             lines.insert(index_start + i + 1, line) | 
					
						
							| 
									
										
										
										
											2024-04-11 11:51:35 +08:00
										 |  |  |         return lines | 
					
						
							| 
									
										
										
										
											2024-04-03 14:27:35 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     return gen_content_between_tags( | 
					
						
							|  |  |  |         "Package/Includes.wxi", "<!--$PreVarsStart$-->", "<!--$PreVarsEnd$-->", func | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2024-04-02 18:10:09 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-15 21:19:46 +08:00
										 |  |  | def replace_app_name_in_langs(app_name): | 
					
						
							| 
									
										
										
										
											2024-04-03 14:27:35 +08:00
										 |  |  |     langs_dir = Path(sys.argv[0]).parent.joinpath("Package/Language") | 
					
						
							| 
									
										
										
										
											2024-04-16 13:09:20 +08:00
										 |  |  |     for file_path in langs_dir.glob("*.wxl"): | 
					
						
							| 
									
										
											  
											
												Refact/msi more install options (#8949)
* refact: msi, more install options
Signed-off-by: fufesou <linlong1266@gmail.com>
* refact: msi, reg values on upgrade/modify
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: msi, silent repair/upgrade, RemoveInstallFolder()
Signed-off-by: fufesou <linlong1266@gmail.com>
* Options support both 1/0 and Y/N
Signed-off-by: fufesou <linlong1266@gmail.com>
* refact: msi, preprocess, open file with explicit encoding
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: msi, read previous options
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: mis, install folder, read previous option
Signed-off-by: fufesou <linlong1266@gmail.com>
* Comment on Control -> Checkbox
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: UI, checkbox options, read previous values
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: shortcuts options, init state
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: shortcuts, init state
Signed-off-by: fufesou <linlong1266@gmail.com>
* Better shortcuts property conditions
Signed-off-by: fufesou <linlong1266@gmail.com>
---------
Signed-off-by: fufesou <linlong1266@gmail.com>
											
										 
											2024-08-05 17:49:48 +08:00
										 |  |  |         with open(file_path, "r", encoding="utf-8") as f: | 
					
						
							| 
									
										
										
										
											2024-04-03 14:27:35 +08:00
										 |  |  |             lines = f.readlines() | 
					
						
							|  |  |  |         for i, line in enumerate(lines): | 
					
						
							|  |  |  |             lines[i] = line.replace("RustDesk", app_name) | 
					
						
							| 
									
										
											  
											
												Refact/msi more install options (#8949)
* refact: msi, more install options
Signed-off-by: fufesou <linlong1266@gmail.com>
* refact: msi, reg values on upgrade/modify
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: msi, silent repair/upgrade, RemoveInstallFolder()
Signed-off-by: fufesou <linlong1266@gmail.com>
* Options support both 1/0 and Y/N
Signed-off-by: fufesou <linlong1266@gmail.com>
* refact: msi, preprocess, open file with explicit encoding
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: msi, read previous options
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: mis, install folder, read previous option
Signed-off-by: fufesou <linlong1266@gmail.com>
* Comment on Control -> Checkbox
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: UI, checkbox options, read previous values
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: shortcuts options, init state
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: shortcuts, init state
Signed-off-by: fufesou <linlong1266@gmail.com>
* Better shortcuts property conditions
Signed-off-by: fufesou <linlong1266@gmail.com>
---------
Signed-off-by: fufesou <linlong1266@gmail.com>
											
										 
											2024-08-05 17:49:48 +08:00
										 |  |  |         with open(file_path, "w", encoding="utf-8") as f: | 
					
						
							| 
									
										
										
										
											2024-04-03 14:27:35 +08:00
										 |  |  |             f.writelines(lines) | 
					
						
							| 
									
										
										
										
											2024-04-02 18:10:09 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-11 11:51:35 +08:00
										 |  |  | def gen_upgrade_info(): | 
					
						
							| 
									
										
										
										
											2024-04-03 14:27:35 +08:00
										 |  |  |     def func(lines, index_start): | 
					
						
							|  |  |  |         indent = g_indent_unit * 3 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-19 18:16:07 +08:00
										 |  |  |         vs = g_version.split(".") | 
					
						
							|  |  |  |         major = vs[0] | 
					
						
							| 
									
										
										
										
											2024-04-03 14:27:35 +08:00
										 |  |  |         upgrade_id = uuid.uuid4() | 
					
						
							|  |  |  |         to_insert_lines = [ | 
					
						
							|  |  |  |             f'{indent}<Upgrade Id="{upgrade_id}">\n', | 
					
						
							| 
									
										
										
										
											2024-04-11 11:51:35 +08:00
										 |  |  |             f'{indent}{g_indent_unit}<UpgradeVersion Property="OLD_VERSION_FOUND" Minimum="{major}.0.0" Maximum="{major}.99.99" IncludeMinimum="yes" IncludeMaximum="yes" OnlyDetect="no" IgnoreRemoveFailure="yes" MigrateFeatures="yes" />\n', | 
					
						
							| 
									
										
										
										
											2024-04-03 14:27:35 +08:00
										 |  |  |             f"{indent}</Upgrade>\n", | 
					
						
							|  |  |  |         ] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         for i, line in enumerate(to_insert_lines): | 
					
						
							|  |  |  |             lines.insert(index_start + i + 1, line) | 
					
						
							|  |  |  |         return lines | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return gen_content_between_tags( | 
					
						
							|  |  |  |         "Package/Fragments/Upgrades.wxs", | 
					
						
							|  |  |  |         "<!--$UpgradeStart$-->", | 
					
						
							|  |  |  |         "<!--$UpgradeEnd$-->", | 
					
						
							|  |  |  |         func, | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2024-04-02 18:10:09 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-03 14:27:35 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-11 11:51:35 +08:00
										 |  |  | def gen_custom_dialog_bitmaps(): | 
					
						
							|  |  |  |     def func(lines, index_start): | 
					
						
							|  |  |  |         indent = g_indent_unit * 2 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # https://wixtoolset.org/docs/tools/wixext/wixui/#customizing-a-dialog-set | 
					
						
							|  |  |  |         vars = [ | 
					
						
							|  |  |  |             "WixUIBannerBmp", | 
					
						
							|  |  |  |             "WixUIDialogBmp", | 
					
						
							|  |  |  |             "WixUIExclamationIco", | 
					
						
							|  |  |  |             "WixUIInfoIco", | 
					
						
							|  |  |  |             "WixUINewIco", | 
					
						
							|  |  |  |             "WixUIUpIco", | 
					
						
							|  |  |  |         ] | 
					
						
							|  |  |  |         to_insert_lines = [] | 
					
						
							|  |  |  |         for var in vars: | 
					
						
							|  |  |  |             if Path(f"Package/Resources/{var}.bmp").exists(): | 
					
						
							|  |  |  |                 to_insert_lines.append( | 
					
						
							|  |  |  |                     f'{indent}<WixVariable Id="{var}" Value="Resources\\{var}.bmp" />\n' | 
					
						
							|  |  |  |                 ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         for i, line in enumerate(to_insert_lines): | 
					
						
							|  |  |  |             lines.insert(index_start + i + 1, line) | 
					
						
							|  |  |  |         return lines | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return gen_content_between_tags( | 
					
						
							|  |  |  |         "Package/Package.wxs", | 
					
						
							|  |  |  |         "<!--$CustomBitmapsStart$-->", | 
					
						
							|  |  |  |         "<!--$CustomBitmapsEnd$-->", | 
					
						
							|  |  |  |         func, | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def gen_custom_ARPSYSTEMCOMPONENT_False(args): | 
					
						
							|  |  |  |     def func(lines, index_start): | 
					
						
							|  |  |  |         indent = g_indent_unit * 2 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         lines_new = [] | 
					
						
							|  |  |  |         lines_new.append( | 
					
						
							|  |  |  |             f"{indent}<!--https://learn.microsoft.com/en-us/windows/win32/msi/arpsystemcomponent?redirectedfrom=MSDN-->\n" | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |         lines_new.append( | 
					
						
							|  |  |  |             f'{indent}<!--<Property Id="ARPSYSTEMCOMPONENT" Value="1" />-->\n\n' | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         lines_new.append( | 
					
						
							|  |  |  |             f"{indent}<!--https://learn.microsoft.com/en-us/windows/win32/msi/property-reference-->\n" | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |         for _, v in g_arpsystemcomponent.items(): | 
					
						
							|  |  |  |             if "msi" in v and "v" in v: | 
					
						
							| 
									
										
										
										
											2024-04-16 14:12:39 +08:00
										 |  |  |                 lines_new.append( | 
					
						
							|  |  |  |                     f'{indent}<Property Id="{v["msi"]}" Value="{v["v"]}" />\n' | 
					
						
							|  |  |  |                 ) | 
					
						
							| 
									
										
										
										
											2024-04-11 11:51:35 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         for i, line in enumerate(lines_new): | 
					
						
							|  |  |  |             lines.insert(index_start + i + 1, line) | 
					
						
							|  |  |  |         return lines | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return gen_content_between_tags( | 
					
						
							|  |  |  |         "Package/Fragments/AddRemoveProperties.wxs", | 
					
						
							|  |  |  |         "<!--$ArpStart$-->", | 
					
						
							|  |  |  |         "<!--$ArpEnd$-->", | 
					
						
							|  |  |  |         func, | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def get_folder_size(folder_path): | 
					
						
							|  |  |  |     total_size = 0 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     folder = Path(folder_path) | 
					
						
							|  |  |  |     for file in folder.glob("**/*"): | 
					
						
							|  |  |  |         if file.is_file(): | 
					
						
							|  |  |  |             total_size += file.stat().st_size | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return total_size | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-11 18:54:32 +08:00
										 |  |  | def gen_custom_ARPSYSTEMCOMPONENT_True(args, dist_dir): | 
					
						
							| 
									
										
										
										
											2024-04-11 11:51:35 +08:00
										 |  |  |     def func(lines, index_start): | 
					
						
							|  |  |  |         indent = g_indent_unit * 5 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         lines_new = [] | 
					
						
							|  |  |  |         lines_new.append( | 
					
						
							|  |  |  |             f"{indent}<!--https://learn.microsoft.com/en-us/windows/win32/msi/property-reference-->\n" | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |         lines_new.append( | 
					
						
							|  |  |  |             f'{indent}<RegistryValue Type="string" Name="DisplayName" Value="{args.app_name}" />\n' | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |         lines_new.append( | 
					
						
							| 
									
										
											  
											
												Refact/msi more install options (#8949)
* refact: msi, more install options
Signed-off-by: fufesou <linlong1266@gmail.com>
* refact: msi, reg values on upgrade/modify
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: msi, silent repair/upgrade, RemoveInstallFolder()
Signed-off-by: fufesou <linlong1266@gmail.com>
* Options support both 1/0 and Y/N
Signed-off-by: fufesou <linlong1266@gmail.com>
* refact: msi, preprocess, open file with explicit encoding
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: msi, read previous options
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: mis, install folder, read previous option
Signed-off-by: fufesou <linlong1266@gmail.com>
* Comment on Control -> Checkbox
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: UI, checkbox options, read previous values
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: shortcuts options, init state
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: shortcuts, init state
Signed-off-by: fufesou <linlong1266@gmail.com>
* Better shortcuts property conditions
Signed-off-by: fufesou <linlong1266@gmail.com>
---------
Signed-off-by: fufesou <linlong1266@gmail.com>
											
										 
											2024-08-05 17:49:48 +08:00
										 |  |  |             f'{indent}<RegistryValue Type="string" Name="DisplayIcon" Value="[INSTALLFOLDER_INNER]{args.app_name}.exe" />\n' | 
					
						
							| 
									
										
										
										
											2024-04-11 11:51:35 +08:00
										 |  |  |         ) | 
					
						
							|  |  |  |         lines_new.append( | 
					
						
							|  |  |  |             f'{indent}<RegistryValue Type="string" Name="DisplayVersion" Value="{g_version}" />\n' | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |         lines_new.append( | 
					
						
							|  |  |  |             f'{indent}<RegistryValue Type="string" Name="Publisher" Value="{args.manufacturer}" />\n' | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |         installDate = datetime.datetime.now().strftime("%Y%m%d") | 
					
						
							|  |  |  |         lines_new.append( | 
					
						
							|  |  |  |             f'{indent}<RegistryValue Type="string" Name="InstallDate" Value="{installDate}" />\n' | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |         lines_new.append( | 
					
						
							| 
									
										
											  
											
												Refact/msi more install options (#8949)
* refact: msi, more install options
Signed-off-by: fufesou <linlong1266@gmail.com>
* refact: msi, reg values on upgrade/modify
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: msi, silent repair/upgrade, RemoveInstallFolder()
Signed-off-by: fufesou <linlong1266@gmail.com>
* Options support both 1/0 and Y/N
Signed-off-by: fufesou <linlong1266@gmail.com>
* refact: msi, preprocess, open file with explicit encoding
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: msi, read previous options
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: mis, install folder, read previous option
Signed-off-by: fufesou <linlong1266@gmail.com>
* Comment on Control -> Checkbox
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: UI, checkbox options, read previous values
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: shortcuts options, init state
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: shortcuts, init state
Signed-off-by: fufesou <linlong1266@gmail.com>
* Better shortcuts property conditions
Signed-off-by: fufesou <linlong1266@gmail.com>
---------
Signed-off-by: fufesou <linlong1266@gmail.com>
											
										 
											2024-08-05 17:49:48 +08:00
										 |  |  |             f'{indent}<RegistryValue Type="string" Name="InstallLocation" Value="[INSTALLFOLDER_INNER]" />\n' | 
					
						
							| 
									
										
										
										
											2024-04-11 11:51:35 +08:00
										 |  |  |         ) | 
					
						
							|  |  |  |         lines_new.append( | 
					
						
							|  |  |  |             f'{indent}<RegistryValue Type="string" Name="InstallSource" Value="[InstallSource]" />\n' | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |         lines_new.append( | 
					
						
							|  |  |  |             f'{indent}<RegistryValue Type="integer" Name="Language" Value="[ProductLanguage]" />\n' | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-11 18:54:32 +08:00
										 |  |  |         estimated_size = get_folder_size(dist_dir) | 
					
						
							| 
									
										
										
										
											2024-04-11 11:51:35 +08:00
										 |  |  |         lines_new.append( | 
					
						
							|  |  |  |             f'{indent}<RegistryValue Type="integer" Name="EstimatedSize" Value="{estimated_size}" />\n' | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         lines_new.append( | 
					
						
							|  |  |  |             f'{indent}<RegistryValue Type="expandable" Name="ModifyPath" Value="MsiExec.exe /X [ProductCode]" />\n' | 
					
						
							|  |  |  |         ) | 
					
						
							| 
									
										
										
										
											2024-04-16 14:12:39 +08:00
										 |  |  |         lines_new.append( | 
					
						
							|  |  |  |             f'{indent}<RegistryValue Type="integer" Id="NoModify" Value="1" />\n' | 
					
						
							|  |  |  |         ) | 
					
						
							| 
									
										
										
										
											2024-04-11 11:51:35 +08:00
										 |  |  |         lines_new.append( | 
					
						
							|  |  |  |             f'{indent}<RegistryValue Type="expandable" Name="UninstallString" Value="MsiExec.exe /X [ProductCode]" />\n' | 
					
						
							|  |  |  |         ) | 
					
						
							| 
									
										
										
										
											2024-04-30 17:42:28 +08:00
										 |  |  |         lines_new.append( | 
					
						
							|  |  |  |             f'{indent}<RegistryValue Type="expandable" Name="QuietUninstallString" Value="MsiExec.exe /qn /X [ProductCode]" />\n' | 
					
						
							|  |  |  |         ) | 
					
						
							| 
									
										
										
										
											2024-04-11 11:51:35 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-19 18:16:07 +08:00
										 |  |  |         vs = g_version.split(".") | 
					
						
							|  |  |  |         major, minor, build = vs[0], vs[1], vs[2] | 
					
						
							| 
									
										
										
										
											2024-04-11 11:51:35 +08:00
										 |  |  |         lines_new.append( | 
					
						
							|  |  |  |             f'{indent}<RegistryValue Type="string" Name="Version" Value="{g_version}" />\n' | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |         lines_new.append( | 
					
						
							|  |  |  |             f'{indent}<RegistryValue Type="integer" Name="VersionMajor" Value="{major}" />\n' | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |         lines_new.append( | 
					
						
							|  |  |  |             f'{indent}<RegistryValue Type="integer" Name="VersionMinor" Value="{minor}" />\n' | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |         lines_new.append( | 
					
						
							|  |  |  |             f'{indent}<RegistryValue Type="integer" Name="VersionBuild" Value="{build}" />\n' | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         lines_new.append( | 
					
						
							|  |  |  |             f'{indent}<RegistryValue Type="integer" Name="WindowsInstaller" Value="1" />\n' | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |         for k, v in g_arpsystemcomponent.items(): | 
					
						
							| 
									
										
										
										
											2024-04-16 14:12:39 +08:00
										 |  |  |             if "v" in v: | 
					
						
							|  |  |  |                 t = v["t"] if "t" in v is None else "string" | 
					
						
							|  |  |  |                 lines_new.append( | 
					
						
							|  |  |  |                     f'{indent}<RegistryValue Type="{t}" Name="{k}" Value="{v["v"]}" />\n' | 
					
						
							|  |  |  |                 ) | 
					
						
							| 
									
										
										
										
											2024-04-11 11:51:35 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         for i, line in enumerate(lines_new): | 
					
						
							|  |  |  |             lines.insert(index_start + i + 1, line) | 
					
						
							|  |  |  |         return lines | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return gen_content_between_tags( | 
					
						
							|  |  |  |         "Package/Components/Regs.wxs", | 
					
						
							|  |  |  |         "<!--$ArpStart$-->", | 
					
						
							|  |  |  |         "<!--$ArpEnd$-->", | 
					
						
							|  |  |  |         func, | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-11 18:54:32 +08:00
										 |  |  | def gen_custom_ARPSYSTEMCOMPONENT(args, dist_dir): | 
					
						
							| 
									
										
										
										
											2024-04-11 11:51:35 +08:00
										 |  |  |     try: | 
					
						
							|  |  |  |         custom_arp = json.loads(args.custom_arp) | 
					
						
							|  |  |  |         g_arpsystemcomponent.update(custom_arp) | 
					
						
							|  |  |  |     except json.JSONDecodeError as e: | 
					
						
							|  |  |  |         print(f"Failed to decode custom arp: {e}") | 
					
						
							|  |  |  |         return False | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if args.arp: | 
					
						
							| 
									
										
										
										
											2024-04-11 18:54:32 +08:00
										 |  |  |         return gen_custom_ARPSYSTEMCOMPONENT_True(args, dist_dir) | 
					
						
							| 
									
										
										
										
											2024-04-11 11:51:35 +08:00
										 |  |  |     else: | 
					
						
							|  |  |  |         return gen_custom_ARPSYSTEMCOMPONENT_False(args) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-03 22:29:30 +08:00
										 |  |  | def gen_conn_type(args): | 
					
						
							| 
									
										
										
										
											2024-08-01 15:08:52 +08:00
										 |  |  |     def func(lines, index_start): | 
					
						
							|  |  |  |         indent = g_indent_unit * 3 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         lines_new = [] | 
					
						
							| 
									
										
										
										
											2024-08-03 22:29:30 +08:00
										 |  |  |         if args.conn_type != "": | 
					
						
							| 
									
										
										
										
											2024-08-01 15:08:52 +08:00
										 |  |  |             lines_new.append( | 
					
						
							| 
									
										
										
										
											2024-08-03 22:29:30 +08:00
										 |  |  |                 f"""{indent}<Property Id="CC_CONNECTION_TYPE" Value="{args.conn_type}" />\n""" | 
					
						
							| 
									
										
										
										
											2024-08-01 15:08:52 +08:00
										 |  |  |             ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         for i, line in enumerate(lines_new): | 
					
						
							|  |  |  |             lines.insert(index_start + i + 1, line) | 
					
						
							|  |  |  |         return lines | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return gen_content_between_tags( | 
					
						
							|  |  |  |         "Package/Fragments/AddRemoveProperties.wxs", | 
					
						
							|  |  |  |         "<!--$CustomClientPropsStart$-->", | 
					
						
							|  |  |  |         "<!--$CustomClientPropsEnd$-->", | 
					
						
							|  |  |  |         func, | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2024-04-11 11:51:35 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-03 14:27:35 +08:00
										 |  |  | def gen_content_between_tags(filename, tag_start, tag_end, func): | 
					
						
							|  |  |  |     target_file = Path(sys.argv[0]).parent.joinpath(filename) | 
					
						
							|  |  |  |     lines, index_start = read_lines_and_start_index(target_file, tag_start, tag_end) | 
					
						
							| 
									
										
										
										
											2024-04-02 18:10:09 +08:00
										 |  |  |     if lines is None: | 
					
						
							|  |  |  |         return False | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-03 14:27:35 +08:00
										 |  |  |     func(lines, index_start) | 
					
						
							| 
									
										
										
										
											2024-04-02 18:10:09 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
											  
											
												Refact/msi more install options (#8949)
* refact: msi, more install options
Signed-off-by: fufesou <linlong1266@gmail.com>
* refact: msi, reg values on upgrade/modify
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: msi, silent repair/upgrade, RemoveInstallFolder()
Signed-off-by: fufesou <linlong1266@gmail.com>
* Options support both 1/0 and Y/N
Signed-off-by: fufesou <linlong1266@gmail.com>
* refact: msi, preprocess, open file with explicit encoding
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: msi, read previous options
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: mis, install folder, read previous option
Signed-off-by: fufesou <linlong1266@gmail.com>
* Comment on Control -> Checkbox
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: UI, checkbox options, read previous values
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: shortcuts options, init state
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: shortcuts, init state
Signed-off-by: fufesou <linlong1266@gmail.com>
* Better shortcuts property conditions
Signed-off-by: fufesou <linlong1266@gmail.com>
---------
Signed-off-by: fufesou <linlong1266@gmail.com>
											
										 
											2024-08-05 17:49:48 +08:00
										 |  |  |     with open(target_file, "w", encoding="utf-8") as f: | 
					
						
							| 
									
										
										
										
											2024-04-02 18:10:09 +08:00
										 |  |  |         f.writelines(lines) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return True | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-25 22:35:51 +08:00
										 |  |  | def prepare_resources(): | 
					
						
							|  |  |  |     icon_src = Path(sys.argv[0]).parent.joinpath("../icon.ico") | 
					
						
							|  |  |  |     icon_dst = Path(sys.argv[0]).parent.joinpath("Package/Resources/icon.ico") | 
					
						
							|  |  |  |     if icon_src.exists(): | 
					
						
							|  |  |  |         icon_dst.parent.mkdir(parents=True, exist_ok=True) | 
					
						
							|  |  |  |         shutil.copy(icon_src, icon_dst) | 
					
						
							|  |  |  |         return True | 
					
						
							|  |  |  |     else: | 
					
						
							|  |  |  |         # unreachable | 
					
						
							|  |  |  |         print(f"Error: icon.ico not found in {icon_src}") | 
					
						
							|  |  |  |         return False | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-19 17:57:04 +08:00
										 |  |  | def init_global_vars(dist_dir, app_name, args): | 
					
						
							|  |  |  |     dist_app = dist_dir.joinpath(app_name + ".exe") | 
					
						
							| 
									
										
										
										
											2024-04-19 18:16:07 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-19 17:57:04 +08:00
										 |  |  |     def read_process_output(args): | 
					
						
							| 
									
										
										
										
											2024-04-19 18:16:07 +08:00
										 |  |  |         process = subprocess.Popen( | 
					
						
							|  |  |  |             f"{dist_app} {args}", | 
					
						
							|  |  |  |             stdout=subprocess.PIPE, | 
					
						
							|  |  |  |             stderr=subprocess.STDOUT, | 
					
						
							|  |  |  |             shell=True, | 
					
						
							|  |  |  |         ) | 
					
						
							| 
									
										
										
										
											2024-04-19 17:57:04 +08:00
										 |  |  |         output, _ = process.communicate() | 
					
						
							| 
									
										
										
										
											2024-04-19 18:16:07 +08:00
										 |  |  |         return output.decode("utf-8").strip() | 
					
						
							| 
									
										
										
										
											2024-04-11 11:51:35 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     global g_version | 
					
						
							|  |  |  |     global g_build_date | 
					
						
							|  |  |  |     g_version = args.version.replace("-", ".") | 
					
						
							|  |  |  |     if g_version == "": | 
					
						
							| 
									
										
										
										
											2024-04-19 18:16:07 +08:00
										 |  |  |         g_version = read_process_output("--version") | 
					
						
							|  |  |  |     version_pattern = re.compile(r"\d+\.\d+\.\d+.*") | 
					
						
							|  |  |  |     if not version_pattern.match(g_version): | 
					
						
							|  |  |  |         print(f"Error: version {g_version} not found in {dist_app}") | 
					
						
							| 
									
										
										
										
											2024-04-11 11:51:35 +08:00
										 |  |  |         return False | 
					
						
							| 
									
										
										
										
											2024-07-22 23:37:25 +08:00
										 |  |  |     if g_version.count(".") == 2: | 
					
						
							|  |  |  |         # https://github.com/dotnet/runtime/blob/5535e31a712343a63f5d7d796cd874e563e5ac14/src/libraries/System.Private.CoreLib/src/System/Version.cs | 
					
						
							|  |  |  |         if args.revision_version < 0 or args.revision_version > 2147483647: | 
					
						
							|  |  |  |             raise ValueError(f"Invalid revision version: {args.revision_version}")     | 
					
						
							|  |  |  |         g_version = f"{g_version}.{args.revision_version}" | 
					
						
							| 
									
										
										
										
											2024-04-11 11:51:35 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-19 18:16:07 +08:00
										 |  |  |     g_build_date = read_process_output("--build-date") | 
					
						
							|  |  |  |     build_date_pattern = re.compile(r"\d{4}-\d{2}-\d{2} \d{2}:\d{2}") | 
					
						
							|  |  |  |     if not build_date_pattern.match(g_build_date): | 
					
						
							|  |  |  |         print(f"Error: build date {g_build_date} not found in {dist_app}") | 
					
						
							| 
									
										
										
										
											2024-04-19 17:57:04 +08:00
										 |  |  |         return False | 
					
						
							| 
									
										
										
										
											2024-04-11 11:51:35 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     return True | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-26 13:49:53 +08:00
										 |  |  | def update_license_file(app_name): | 
					
						
							|  |  |  |     if app_name == "RustDesk": | 
					
						
							|  |  |  |         return | 
					
						
							|  |  |  |     license_file = Path(sys.argv[0]).parent.joinpath("Package/License.rtf") | 
					
						
							| 
									
										
											  
											
												Refact/msi more install options (#8949)
* refact: msi, more install options
Signed-off-by: fufesou <linlong1266@gmail.com>
* refact: msi, reg values on upgrade/modify
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: msi, silent repair/upgrade, RemoveInstallFolder()
Signed-off-by: fufesou <linlong1266@gmail.com>
* Options support both 1/0 and Y/N
Signed-off-by: fufesou <linlong1266@gmail.com>
* refact: msi, preprocess, open file with explicit encoding
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: msi, read previous options
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: mis, install folder, read previous option
Signed-off-by: fufesou <linlong1266@gmail.com>
* Comment on Control -> Checkbox
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: UI, checkbox options, read previous values
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: shortcuts options, init state
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: shortcuts, init state
Signed-off-by: fufesou <linlong1266@gmail.com>
* Better shortcuts property conditions
Signed-off-by: fufesou <linlong1266@gmail.com>
---------
Signed-off-by: fufesou <linlong1266@gmail.com>
											
										 
											2024-08-05 17:49:48 +08:00
										 |  |  |     with open(license_file, "r", encoding="utf-8") as f: | 
					
						
							| 
									
										
										
										
											2024-04-26 13:49:53 +08:00
										 |  |  |         license_content = f.read() | 
					
						
							|  |  |  |     license_content = license_content.replace("website rustdesk.com and other ", "") | 
					
						
							|  |  |  |     license_content = license_content.replace("RustDesk", app_name) | 
					
						
							|  |  |  |     license_content = re.sub("Purslane Ltd", app_name, license_content, flags=re.IGNORECASE) | 
					
						
							| 
									
										
											  
											
												Refact/msi more install options (#8949)
* refact: msi, more install options
Signed-off-by: fufesou <linlong1266@gmail.com>
* refact: msi, reg values on upgrade/modify
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: msi, silent repair/upgrade, RemoveInstallFolder()
Signed-off-by: fufesou <linlong1266@gmail.com>
* Options support both 1/0 and Y/N
Signed-off-by: fufesou <linlong1266@gmail.com>
* refact: msi, preprocess, open file with explicit encoding
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: msi, read previous options
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: mis, install folder, read previous option
Signed-off-by: fufesou <linlong1266@gmail.com>
* Comment on Control -> Checkbox
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: UI, checkbox options, read previous values
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: shortcuts options, init state
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: shortcuts, init state
Signed-off-by: fufesou <linlong1266@gmail.com>
* Better shortcuts property conditions
Signed-off-by: fufesou <linlong1266@gmail.com>
---------
Signed-off-by: fufesou <linlong1266@gmail.com>
											
										 
											2024-08-05 17:49:48 +08:00
										 |  |  |     with open(license_file, "w", encoding="utf-8") as f: | 
					
						
							| 
									
										
										
										
											2024-04-26 13:49:53 +08:00
										 |  |  |         f.write(license_content) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-16 14:12:39 +08:00
										 |  |  | def replace_component_guids_in_wxs(): | 
					
						
							|  |  |  |     langs_dir = Path(sys.argv[0]).parent.joinpath("Package") | 
					
						
							|  |  |  |     for file_path in langs_dir.glob("**/*.wxs"): | 
					
						
							| 
									
										
											  
											
												Refact/msi more install options (#8949)
* refact: msi, more install options
Signed-off-by: fufesou <linlong1266@gmail.com>
* refact: msi, reg values on upgrade/modify
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: msi, silent repair/upgrade, RemoveInstallFolder()
Signed-off-by: fufesou <linlong1266@gmail.com>
* Options support both 1/0 and Y/N
Signed-off-by: fufesou <linlong1266@gmail.com>
* refact: msi, preprocess, open file with explicit encoding
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: msi, read previous options
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: mis, install folder, read previous option
Signed-off-by: fufesou <linlong1266@gmail.com>
* Comment on Control -> Checkbox
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: UI, checkbox options, read previous values
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: shortcuts options, init state
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: shortcuts, init state
Signed-off-by: fufesou <linlong1266@gmail.com>
* Better shortcuts property conditions
Signed-off-by: fufesou <linlong1266@gmail.com>
---------
Signed-off-by: fufesou <linlong1266@gmail.com>
											
										 
											2024-08-05 17:49:48 +08:00
										 |  |  |         with open(file_path, "r", encoding="utf-8") as f: | 
					
						
							| 
									
										
										
										
											2024-04-16 14:12:39 +08:00
										 |  |  |             lines = f.readlines() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # <Component Id="Product.Registry.DefaultIcon" Guid="6DBF2690-0955-4C6A-940F-634DDA503F49"> | 
					
						
							|  |  |  |         for i, line in enumerate(lines): | 
					
						
							|  |  |  |             match = re.search(r'Component.+Guid="([^"]+)"', line) | 
					
						
							|  |  |  |             if match: | 
					
						
							|  |  |  |                 lines[i] = re.sub(r'Guid="[^"]+"', f'Guid="{uuid.uuid4()}"', line) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
											  
											
												Refact/msi more install options (#8949)
* refact: msi, more install options
Signed-off-by: fufesou <linlong1266@gmail.com>
* refact: msi, reg values on upgrade/modify
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: msi, silent repair/upgrade, RemoveInstallFolder()
Signed-off-by: fufesou <linlong1266@gmail.com>
* Options support both 1/0 and Y/N
Signed-off-by: fufesou <linlong1266@gmail.com>
* refact: msi, preprocess, open file with explicit encoding
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: msi, read previous options
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: mis, install folder, read previous option
Signed-off-by: fufesou <linlong1266@gmail.com>
* Comment on Control -> Checkbox
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: UI, checkbox options, read previous values
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: shortcuts options, init state
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: shortcuts, init state
Signed-off-by: fufesou <linlong1266@gmail.com>
* Better shortcuts property conditions
Signed-off-by: fufesou <linlong1266@gmail.com>
---------
Signed-off-by: fufesou <linlong1266@gmail.com>
											
										 
											2024-08-05 17:49:48 +08:00
										 |  |  |         with open(file_path, "w", encoding="utf-8") as f: | 
					
						
							| 
									
										
										
										
											2024-04-16 14:12:39 +08:00
										 |  |  |             f.writelines(lines) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-02 18:10:09 +08:00
										 |  |  | if __name__ == "__main__": | 
					
						
							|  |  |  |     parser = make_parser() | 
					
						
							|  |  |  |     args = parser.parse_args() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     app_name = args.app_name | 
					
						
							| 
									
										
										
										
											2024-04-11 18:54:32 +08:00
										 |  |  |     dist_dir = Path(sys.argv[0]).parent.joinpath(args.dist_dir).resolve() | 
					
						
							| 
									
										
										
										
											2024-04-11 11:51:35 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-25 22:35:51 +08:00
										 |  |  |     if not prepare_resources(): | 
					
						
							|  |  |  |         sys.exit(-1) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-19 17:57:04 +08:00
										 |  |  |     if not init_global_vars(dist_dir, app_name, args): | 
					
						
							| 
									
										
										
										
											2024-04-11 11:51:35 +08:00
										 |  |  |         sys.exit(-1) | 
					
						
							| 
									
										
										
										
											2024-04-02 18:10:09 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-26 13:49:53 +08:00
										 |  |  |     update_license_file(app_name) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-11 18:54:32 +08:00
										 |  |  |     if not gen_pre_vars(args, dist_dir): | 
					
						
							| 
									
										
										
										
											2024-04-02 18:10:09 +08:00
										 |  |  |         sys.exit(-1) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-16 14:12:39 +08:00
										 |  |  |     if app_name != "RustDesk": | 
					
						
							|  |  |  |         replace_component_guids_in_wxs() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-11 11:51:35 +08:00
										 |  |  |     if not gen_upgrade_info(): | 
					
						
							|  |  |  |         sys.exit(-1) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-11 18:54:32 +08:00
										 |  |  |     if not gen_custom_ARPSYSTEMCOMPONENT(args, dist_dir): | 
					
						
							| 
									
										
										
										
											2024-04-03 14:27:35 +08:00
										 |  |  |         sys.exit(-1) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-03 22:29:30 +08:00
										 |  |  |     if not gen_conn_type(args): | 
					
						
							| 
									
										
										
										
											2024-08-01 15:08:52 +08:00
										 |  |  |         sys.exit(-1) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-11 18:54:32 +08:00
										 |  |  |     if not gen_auto_component(app_name, dist_dir): | 
					
						
							| 
									
										
										
										
											2024-04-02 18:10:09 +08:00
										 |  |  |         sys.exit(-1) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-11 11:51:35 +08:00
										 |  |  |     if not gen_custom_dialog_bitmaps(): | 
					
						
							|  |  |  |         sys.exit(-1) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-15 21:19:46 +08:00
										 |  |  |     replace_app_name_in_langs(args.app_name) |