├── app_tauri ├── src │ ├── App.css │ ├── vite-env.d.ts │ ├── components │ │ ├── IconAdd.tsx │ │ ├── IconEdit.tsx │ │ ├── ThemeSwitcher.tsx │ │ ├── IconTrash.tsx │ │ ├── BuildPanel.tsx │ │ ├── FunctionPanel.tsx │ │ └── FormOfMethods.tsx │ ├── main.tsx │ ├── App.tsx │ ├── store.ts │ └── assets │ │ └── react.svg ├── src-tauri │ ├── build.rs │ ├── icons │ │ ├── icon.ico │ │ ├── icon.png │ │ ├── 32x32.png │ │ ├── icon.icns │ │ ├── 128x128.png │ │ ├── StoreLogo.png │ │ ├── 128x128@2x.png │ │ ├── Square30x30Logo.png │ │ ├── Square44x44Logo.png │ │ ├── Square71x71Logo.png │ │ ├── Square89x89Logo.png │ │ ├── Square107x107Logo.png │ │ ├── Square142x142Logo.png │ │ ├── Square150x150Logo.png │ │ ├── Square284x284Logo.png │ │ └── Square310x310Logo.png │ ├── src │ │ ├── main.rs │ │ ├── dto.rs │ │ ├── file_op.rs │ │ └── lib.rs │ ├── capabilities │ │ └── default.json │ ├── tauri.conf.json │ └── Cargo.toml ├── tsconfig.node.json ├── README.md ├── postcss.config.cjs ├── index.html ├── tsconfig.json ├── vite.config.ts ├── package.json └── public │ ├── vite.svg │ └── tauri.svg ├── source ├── one-comp-gen.exe └── base_template │ ├── cpp │ ├── lib │ │ ├── common.h │ │ └── common.cpp │ ├── source │ │ ├── AddInNative.rc │ │ ├── AddInNative.def │ │ ├── impl │ │ │ ├── rust.h │ │ │ ├── test.h │ │ │ └── test.cpp │ │ ├── version.script │ │ ├── stdafx.cpp │ │ ├── stdafx.h │ │ ├── dllmain.cpp │ │ ├── MacOSXBundleInfo.plist.in │ │ ├── Info.plist.in │ │ ├── CMakeLists.txt │ │ ├── AddInNative.h │ │ └── AddInNative.cpp │ └── include │ │ ├── ComponentBase.h │ │ ├── addinlib.h │ │ ├── IAndroidComponentHelper.h │ │ ├── mobile.h │ │ ├── IMemoryManager.h │ │ ├── com.h │ │ ├── MANIFEST.xsd │ │ ├── AddInDefBase.h │ │ ├── addin.idl │ │ └── types.h │ ├── ПрименениеВнешнейКомпоннентыВ1С.epf │ └── rust │ ├── src │ ├── struct_dto.rs │ ├── impl_test.rs │ ├── lib.rs │ └── interaction_with_cpp.rs │ ├── Cargo.toml │ └── Cargo.lock ├── .gitignore ├── LICENSE └── README.md /app_tauri/src/App.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /app_tauri/src/vite-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /app_tauri/src-tauri/build.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | tauri_build::build() 3 | } 4 | -------------------------------------------------------------------------------- /source/one-comp-gen.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kovalevdmv/onec_comp_gen/HEAD/source/one-comp-gen.exe -------------------------------------------------------------------------------- /app_tauri/src-tauri/icons/icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kovalevdmv/onec_comp_gen/HEAD/app_tauri/src-tauri/icons/icon.ico -------------------------------------------------------------------------------- /app_tauri/src-tauri/icons/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kovalevdmv/onec_comp_gen/HEAD/app_tauri/src-tauri/icons/icon.png -------------------------------------------------------------------------------- /app_tauri/src-tauri/icons/32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kovalevdmv/onec_comp_gen/HEAD/app_tauri/src-tauri/icons/32x32.png -------------------------------------------------------------------------------- /app_tauri/src-tauri/icons/icon.icns: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kovalevdmv/onec_comp_gen/HEAD/app_tauri/src-tauri/icons/icon.icns -------------------------------------------------------------------------------- /app_tauri/src-tauri/icons/128x128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kovalevdmv/onec_comp_gen/HEAD/app_tauri/src-tauri/icons/128x128.png -------------------------------------------------------------------------------- /app_tauri/src-tauri/icons/StoreLogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kovalevdmv/onec_comp_gen/HEAD/app_tauri/src-tauri/icons/StoreLogo.png -------------------------------------------------------------------------------- /source/base_template/cpp/lib/common.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kovalevdmv/onec_comp_gen/HEAD/source/base_template/cpp/lib/common.h -------------------------------------------------------------------------------- /app_tauri/src-tauri/icons/128x128@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kovalevdmv/onec_comp_gen/HEAD/app_tauri/src-tauri/icons/128x128@2x.png -------------------------------------------------------------------------------- /app_tauri/src-tauri/icons/Square30x30Logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kovalevdmv/onec_comp_gen/HEAD/app_tauri/src-tauri/icons/Square30x30Logo.png -------------------------------------------------------------------------------- /app_tauri/src-tauri/icons/Square44x44Logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kovalevdmv/onec_comp_gen/HEAD/app_tauri/src-tauri/icons/Square44x44Logo.png -------------------------------------------------------------------------------- /app_tauri/src-tauri/icons/Square71x71Logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kovalevdmv/onec_comp_gen/HEAD/app_tauri/src-tauri/icons/Square71x71Logo.png -------------------------------------------------------------------------------- /app_tauri/src-tauri/icons/Square89x89Logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kovalevdmv/onec_comp_gen/HEAD/app_tauri/src-tauri/icons/Square89x89Logo.png -------------------------------------------------------------------------------- /source/base_template/cpp/source/AddInNative.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kovalevdmv/onec_comp_gen/HEAD/source/base_template/cpp/source/AddInNative.rc -------------------------------------------------------------------------------- /app_tauri/src-tauri/icons/Square107x107Logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kovalevdmv/onec_comp_gen/HEAD/app_tauri/src-tauri/icons/Square107x107Logo.png -------------------------------------------------------------------------------- /app_tauri/src-tauri/icons/Square142x142Logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kovalevdmv/onec_comp_gen/HEAD/app_tauri/src-tauri/icons/Square142x142Logo.png -------------------------------------------------------------------------------- /app_tauri/src-tauri/icons/Square150x150Logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kovalevdmv/onec_comp_gen/HEAD/app_tauri/src-tauri/icons/Square150x150Logo.png -------------------------------------------------------------------------------- /app_tauri/src-tauri/icons/Square284x284Logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kovalevdmv/onec_comp_gen/HEAD/app_tauri/src-tauri/icons/Square284x284Logo.png -------------------------------------------------------------------------------- /app_tauri/src-tauri/icons/Square310x310Logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kovalevdmv/onec_comp_gen/HEAD/app_tauri/src-tauri/icons/Square310x310Logo.png -------------------------------------------------------------------------------- /source/base_template/cpp/include/ComponentBase.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kovalevdmv/onec_comp_gen/HEAD/source/base_template/cpp/include/ComponentBase.h -------------------------------------------------------------------------------- /source/base_template/ПрименениеВнешнейКомпоннентыВ1С.epf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kovalevdmv/onec_comp_gen/HEAD/source/base_template/ПрименениеВнешнейКомпоннентыВ1С.epf -------------------------------------------------------------------------------- /source/base_template/cpp/source/AddInNative.def: -------------------------------------------------------------------------------- 1 | LIBRARY "AddInNative.dll" 2 | 3 | EXPORTS 4 | GetClassObject 5 | DestroyObject 6 | GetClassNames 7 | SetPlatformCapabilities 8 | GetAttachType 9 | -------------------------------------------------------------------------------- /source/base_template/cpp/include/addinlib.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | enum AddInComponentType 4 | { 5 | eAddInCom = 1, 6 | eAddInNative, 7 | eAddInJava, 8 | eAddInvalid = -1 9 | }; 10 | -------------------------------------------------------------------------------- /source/base_template/cpp/source/impl/rust.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | extern "C" const char* test__call_from_cpp(const char* addr, float f, bool b); 3 | //ВставкаМетодов 4 | extern "C" const char* free_mem_after_cpp(const char* ptr); -------------------------------------------------------------------------------- /source/base_template/cpp/source/impl/test.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "../lib/common.h"; 3 | 4 | bool test(const long lMethodNum, tVariant* pvarRetValue, tVariant* paParams, const long lSizeArray, IMemoryManager* m_iMemory); -------------------------------------------------------------------------------- /app_tauri/src-tauri/src/main.rs: -------------------------------------------------------------------------------- 1 | // Prevents additional console window on Windows in release, DO NOT REMOVE!! 2 | #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] 3 | 4 | fn main() { 5 | onec_comp_gen_lib::run() 6 | } 7 | -------------------------------------------------------------------------------- /source/base_template/rust/src/struct_dto.rs: -------------------------------------------------------------------------------- 1 | use serde::{Deserialize, Serialize}; 2 | 3 | #[derive(Serialize, Deserialize)] 4 | pub struct Error { 5 | #[serde(rename = "Тип")] 6 | pub _type: String, 7 | #[serde(rename = "Текст")] 8 | pub text: String, 9 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /app_tauri/node_modules 2 | /app_tauri/dist 3 | /app_tauri/src-tauri/target 4 | /app_tauri/src-tauri/gen/schemas 5 | /source/base_template/cpp/source/.vs 6 | /source/base_template/cpp/source/out 7 | /source/base_template/rust/target 8 | /source/new_component 9 | .vs -------------------------------------------------------------------------------- /app_tauri/tsconfig.node.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "composite": true, 4 | "skipLibCheck": true, 5 | "module": "ESNext", 6 | "moduleResolution": "bundler", 7 | "allowSyntheticDefaultImports": true 8 | }, 9 | "include": ["vite.config.ts"] 10 | } 11 | -------------------------------------------------------------------------------- /app_tauri/src-tauri/capabilities/default.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "../gen/schemas/desktop-schema.json", 3 | "identifier": "default", 4 | "description": "Capability for the main window", 5 | "windows": ["main"], 6 | "permissions": [ 7 | "core:default", 8 | "shell:allow-open" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /source/base_template/rust/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "rust_1c" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | [lib] 7 | crate-type = ["staticlib"] 8 | 9 | [profile.release] 10 | lto = true 11 | 12 | [dependencies] 13 | serde = {version = "1.0.198", features = ["derive"]} 14 | serde_json = "1.0.116" -------------------------------------------------------------------------------- /source/base_template/cpp/source/version.script: -------------------------------------------------------------------------------- 1 | { 2 | global: 3 | *DllMain*; 4 | *GetClassObject*; 5 | *DestroyObject*; 6 | *GetClassNames*; 7 | *SetPlatformCapabilities*; 8 | *GetAttachType*; 9 | local: 10 | *; 11 | }; 12 | -------------------------------------------------------------------------------- /source/base_template/cpp/source/stdafx.cpp: -------------------------------------------------------------------------------- 1 | // stdafx.cpp : source file that includes just the standard includes 2 | // AddInNative.pch will be the pre-compiled header 3 | // stdafx.obj will contain the pre-compiled type information 4 | 5 | #include "stdafx.h" 6 | 7 | // TODO: reference any additional headers you need in STDAFX.H 8 | // and not in this file 9 | -------------------------------------------------------------------------------- /source/base_template/rust/src/impl_test.rs: -------------------------------------------------------------------------------- 1 | use std::ffi::{c_char, CString}; 2 | use crate::interaction_with_cpp::{cchar_to_string, str_to_cchar}; 3 | 4 | //+++Заменить 5 | pub extern "C" fn main(addr: *const c_char, fl: f32, bl: bool) -> *const c_char { 6 | let part = cchar_to_string(addr) + "+ rust" + &fl.to_string() + &bl.to_string(); 7 | str_to_cchar(&part) 8 | } 9 | //--- -------------------------------------------------------------------------------- /app_tauri/README.md: -------------------------------------------------------------------------------- 1 | # Tauri + React + Typescript 2 | 3 | This template should help get you started developing with Tauri, React and Typescript in Vite. 4 | 5 | ## Recommended IDE Setup 6 | 7 | - [VS Code](https://code.visualstudio.com/) + [Tauri](https://marketplace.visualstudio.com/items?itemName=tauri-apps.tauri-vscode) + [rust-analyzer](https://marketplace.visualstudio.com/items?itemName=rust-lang.rust-analyzer) 8 | -------------------------------------------------------------------------------- /app_tauri/postcss.config.cjs: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: { 3 | 'postcss-preset-mantine': {}, 4 | 'postcss-simple-vars': { 5 | variables: { 6 | 'mantine-breakpoint-xs': '36em', 7 | 'mantine-breakpoint-sm': '48em', 8 | 'mantine-breakpoint-md': '62em', 9 | 'mantine-breakpoint-lg': '75em', 10 | 'mantine-breakpoint-xl': '88em', 11 | }, 12 | }, 13 | }, 14 | }; -------------------------------------------------------------------------------- /app_tauri/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Tauri + React + Typescript 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /source/base_template/cpp/source/stdafx.h: -------------------------------------------------------------------------------- 1 | // stdafx.h : include file for standard system include files, 2 | // or project specific include files that are used frequently, but 3 | // are changed infrequently 4 | // 5 | #ifndef __STDAFX_H__ 6 | #define __STDAFX_H__ 7 | 8 | #ifdef _WINDOWS 9 | #include 10 | #endif //_WINDOWS 11 | 12 | #if defined(__linux__) || defined(__APPLE__) 13 | #define LINUX_OR_MACOS 14 | #endif 15 | 16 | #endif //__STDAFX_H__ 17 | -------------------------------------------------------------------------------- /source/base_template/rust/src/lib.rs: -------------------------------------------------------------------------------- 1 | mod interaction_with_cpp; 2 | mod impl_test; 3 | //ВставкаМодулей 4 | mod struct_dto; 5 | 6 | use interaction_with_cpp::{cchar_to_string, str_to_cchar}; 7 | use std::ffi::{c_char, CString}; 8 | 9 | #[no_mangle] 10 | pub extern "C" fn free_mem_after_cpp(ptr: *mut c_char) -> () { 11 | unsafe { 12 | let _ = CString::from_raw(ptr); 13 | } 14 | } 15 | 16 | #[no_mangle] 17 | pub extern "C" fn test__call_from_cpp(addr: *const c_char, fl: f32, bl: bool) -> *const c_char { 18 | impl_test::main(addr, fl, bl) 19 | } 20 | 21 | //ВставкаМетодов -------------------------------------------------------------------------------- /app_tauri/src/components/IconAdd.tsx: -------------------------------------------------------------------------------- 1 | export default function IconAdd() { 2 | return ( 3 | 14 | 15 | 16 | 17 | 18 | 19 | ); 20 | } 21 | -------------------------------------------------------------------------------- /source/base_template/cpp/include/IAndroidComponentHelper.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Warning!!! 3 | * DO NOT ALTER THIS FILE! 4 | */ 5 | 6 | #ifndef __IANDROIDCOMPONENTHELPER_H__ 7 | #define __IANDROIDCOMPONENTHELPER_H__ 8 | 9 | #include "types.h" 10 | 11 | #if defined(__ANDROID__) 12 | #include 13 | 14 | struct IAndroidComponentHelper : 15 | public IInterface 16 | { 17 | virtual jobject ADDIN_API GetActivity() = 0; 18 | 19 | virtual jclass ADDIN_API FindClass(const WCHAR_T* className) = 0; 20 | }; 21 | 22 | #endif //__ANDROID__ 23 | 24 | #endif //__IANDROIDCOMPONENTHELPER_H__ 25 | -------------------------------------------------------------------------------- /app_tauri/src/main.tsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import ReactDOM from "react-dom/client"; 3 | import App from "./App"; 4 | 5 | import "@mantine/core/styles.css"; 6 | 7 | import { createTheme, MantineProvider } from "@mantine/core"; 8 | 9 | const theme = createTheme({ 10 | fontFamily: 'Montserrat, sans-serif', 11 | defaultRadius: 'md', 12 | }); 13 | 14 | ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render( 15 | 16 | 17 | 18 | 19 | 20 | ); 21 | -------------------------------------------------------------------------------- /source/base_template/cpp/source/dllmain.cpp: -------------------------------------------------------------------------------- 1 | // dllmain.cpp : Defines the entry point for the DLL application. 2 | #include "stdafx.h" 3 | #if !defined(__linux__) && !defined(__APPLE__) 4 | BOOL APIENTRY DllMain( HMODULE hModule, 5 | DWORD ul_reason_for_call, 6 | LPVOID lpReserved 7 | ) 8 | { 9 | switch (ul_reason_for_call) 10 | { 11 | case DLL_PROCESS_ATTACH: 12 | case DLL_THREAD_ATTACH: 13 | case DLL_THREAD_DETACH: 14 | case DLL_PROCESS_DETACH: 15 | break; 16 | } 17 | return TRUE; 18 | } 19 | #endif //__linux__ 20 | -------------------------------------------------------------------------------- /source/base_template/rust/src/interaction_with_cpp.rs: -------------------------------------------------------------------------------- 1 | 2 | 3 | use std::ffi::{c_char, CStr, CString}; 4 | use serde::de::DeserializeOwned; 5 | 6 | use crate::struct_dto::Error; 7 | 8 | 9 | pub fn str_to_cchar(text: &str) -> *const c_char { 10 | CString::new(text).unwrap().into_raw() 11 | } 12 | 13 | #[no_mangle] 14 | pub fn cchar_to_string(text: *const c_char) -> String { 15 | let text_str = unsafe { CStr::from_ptr(text).to_str().unwrap().to_string() }; 16 | text_str 17 | } 18 | 19 | fn create_error_object(error_text: &str) -> Error { 20 | Error { 21 | _type: String::from("error"), 22 | text: error_text.to_string(), 23 | } 24 | } 25 | 26 | -------------------------------------------------------------------------------- /app_tauri/src/components/IconEdit.tsx: -------------------------------------------------------------------------------- 1 | export default function IconEdit() { 2 | return ( 3 | 15 | 16 | 17 | 18 | 19 | 20 | ); 21 | } 22 | -------------------------------------------------------------------------------- /source/base_template/cpp/include/mobile.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #if defined(__ANDROID__) 4 | 5 | #define MOBILE_PLATFORM_ANDROID 1 6 | 7 | #elif defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) 8 | 9 | #define MOBILE_PLATFORM_IOS 1 10 | 11 | #elif defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_PC_APP) 12 | 13 | #define MOBILE_PLATFORM_WINRT 1 14 | 15 | #endif 16 | 17 | #include "types.h" 18 | 19 | #if defined(MOBILE_PLATFORM_IOS) 20 | 21 | extern "C" VOID RegisterLibrary(LPCSTR, LPCVOID, LPCVOID); 22 | 23 | #define DECLARE_DLL(name, fnTable) \ 24 | namespace { static struct s { s() { RegisterLibrary(name, NULL, fnTable); }} s; } 25 | 26 | #endif //MOBILE_PLATFORM_IOS 27 | 28 | -------------------------------------------------------------------------------- /app_tauri/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ES2020", 4 | "useDefineForClassFields": true, 5 | "lib": ["ES2020", "DOM", "DOM.Iterable"], 6 | "module": "ESNext", 7 | "skipLibCheck": true, 8 | 9 | /* Bundler mode */ 10 | "moduleResolution": "bundler", 11 | "allowImportingTsExtensions": true, 12 | "resolveJsonModule": true, 13 | "isolatedModules": true, 14 | "noEmit": true, 15 | "jsx": "react-jsx", 16 | 17 | /* Linting */ 18 | "strict": true, 19 | "noUnusedLocals": true, 20 | "noUnusedParameters": true, 21 | "noFallthroughCasesInSwitch": true 22 | }, 23 | "include": ["src"], 24 | "references": [{ "path": "./tsconfig.node.json" }] 25 | } 26 | -------------------------------------------------------------------------------- /app_tauri/src/components/ThemeSwitcher.tsx: -------------------------------------------------------------------------------- 1 | import {useComputedColorScheme,useMantineColorScheme, ActionIcon} from "@mantine/core"; 2 | import { IconSunMoon} from "@tabler/icons-react"; 3 | 4 | export default function ThemeSwitcher() { 5 | 6 | const { setColorScheme } = useMantineColorScheme(); 7 | const computedColorScheme = useComputedColorScheme("light", { 8 | getInitialValueInEffect: true, 9 | }); 10 | 11 | return ( 12 | 14 | setColorScheme(computedColorScheme === "light" ? "dark" : "light") 15 | } 16 | variant="subtle" 17 | size="sm" 18 | color="gray" 19 | > 20 | 21 | 22 | ); 23 | 24 | } 25 | -------------------------------------------------------------------------------- /app_tauri/src/components/IconTrash.tsx: -------------------------------------------------------------------------------- 1 | export default function IconTrash() { 2 | return ( 3 | 4 | ) 5 | }; -------------------------------------------------------------------------------- /app_tauri/src-tauri/tauri.conf.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://schema.tauri.app/config/2", 3 | "productName": "onec_comp_gen", 4 | "version": "0.52.0", 5 | "identifier": "com.onec.comp.gen.app", 6 | "build": { 7 | "beforeDevCommand": "npm run dev", 8 | "devUrl": "http://localhost:3000", 9 | "beforeBuildCommand": "npm run build", 10 | "frontendDist": "../dist" 11 | }, 12 | "app": { 13 | "windows": [ 14 | { 15 | "title": "onec_comp_gen v.0.52.beta", 16 | "width": 800, 17 | "height": 700 18 | } 19 | ], 20 | "security": { 21 | "csp": null 22 | } 23 | }, 24 | "bundle": { 25 | "active": true, 26 | "targets": "all", 27 | "icon": [ 28 | "icons/32x32.png", 29 | "icons/128x128.png", 30 | "icons/128x128@2x.png", 31 | "icons/icon.icns", 32 | "icons/icon.ico" 33 | ] 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /source/base_template/cpp/source/impl/test.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "test.h" 3 | #include "rust.h" 4 | 5 | bool test(const long lMethodNum, tVariant* pvarRetValue, tVariant* paParams, const long lSizeArray, IMemoryManager* m_iMemory) 6 | { 7 | //+++НачалоПримера 8 | std::string parm_for_rust = get_method_param_as_utf8(paParams, 0); 9 | float f = get_method_param_as_number(paParams, 1); 10 | bool b = get_method_param_as_bool(paParams, 2); 11 | //--- 12 | 13 | //+++Получение параметров метода 14 | //ВставкаКодаПолученияПараметровМетода 15 | //--- 16 | 17 | //+++Вызов метода Rust 18 | const char* res = test__call_from_cpp(parm_for_rust.c_str(), f, b); 19 | std::u16string part = utf8_to_utf16(res); 20 | set_return_val_for_1c_as_utf16(pvarRetValue, part, m_iMemory); 21 | //--- 22 | 23 | free_mem_after_cpp(res);//Освободить память выделенные в Rust, когда она больше не нужна на стороне cpp 24 | 25 | return true; 26 | 27 | } -------------------------------------------------------------------------------- /app_tauri/vite.config.ts: -------------------------------------------------------------------------------- 1 | import { defineConfig } from "vite"; 2 | import react from "@vitejs/plugin-react"; 3 | 4 | // @ts-expect-error process is a nodejs global 5 | const host = process.env.TAURI_DEV_HOST; 6 | 7 | // https://vitejs.dev/config/ 8 | export default defineConfig(async () => ({ 9 | plugins: [react()], 10 | 11 | // Vite options tailored for Tauri development and only applied in `tauri dev` or `tauri build` 12 | // 13 | // 1. prevent vite from obscuring rust errors 14 | clearScreen: false, 15 | // 2. tauri expects a fixed port, fail if that port is not available 16 | server: { 17 | port: 3000, 18 | strictPort: true, 19 | host: host || false, 20 | hmr: host 21 | ? { 22 | protocol: "ws", 23 | host, 24 | port: 3001, 25 | } 26 | : undefined, 27 | watch: { 28 | // 3. tell vite to ignore watching `src-tauri` 29 | ignored: ["**/src-tauri/**"], 30 | }, 31 | }, 32 | })); 33 | -------------------------------------------------------------------------------- /app_tauri/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "onec_comp_gen", 3 | "private": true, 4 | "version": "0.1.0", 5 | "type": "module", 6 | "scripts": { 7 | "dev": "vite", 8 | "build": "tsc && vite build", 9 | "preview": "vite preview", 10 | "tauri": "tauri" 11 | }, 12 | "dependencies": { 13 | "@mantine/core": "^7.14.3", 14 | "@mantine/hooks": "^7.14.3", 15 | "@tabler/icons-react": "^3.23.0", 16 | "@tauri-apps/api": "^2", 17 | "@tauri-apps/plugin-shell": "^2", 18 | "install": "^0.13.0", 19 | "npm": "^10.9.1", 20 | "react": "^18.2.0", 21 | "react-dom": "^18.2.0", 22 | "react-icons": "^5.3.0", 23 | "zustand": "^5.0.1" 24 | }, 25 | "devDependencies": { 26 | "@tauri-apps/cli": "^2", 27 | "@types/react": "^18.2.15", 28 | "@types/react-dom": "^18.2.7", 29 | "@vitejs/plugin-react": "^4.2.1", 30 | "postcss": "^8.4.49", 31 | "postcss-preset-mantine": "^1.17.0", 32 | "postcss-simple-vars": "^7.0.1", 33 | "typescript": "^5.2.2", 34 | "vite": "^5.3.1" 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /app_tauri/src-tauri/src/dto.rs: -------------------------------------------------------------------------------- 1 | use serde::{Deserialize, Serialize}; 2 | 3 | #[derive(Serialize, Deserialize)] 4 | pub struct Params { 5 | uuid: String, 6 | pub name: String, 7 | #[serde(rename = "type")] 8 | pub _type: String, 9 | } 10 | 11 | #[derive(Serialize, Deserialize)] 12 | pub struct Method { 13 | uuid: String, 14 | pub name: String, 15 | #[serde(rename = "nameEng")] 16 | pub name_eng: String, 17 | pub params: Vec, 18 | #[serde(rename = "hasReturn")] 19 | pub has_return: bool, 20 | #[serde(rename = "ReturnType")] 21 | return_type: Option, 22 | #[serde(rename = "callRustMethod")] 23 | pub call_rust_method: bool, 24 | } 25 | 26 | #[derive(Serialize, Deserialize)] 27 | pub struct Props { 28 | uuid: String, 29 | name: String, 30 | #[serde(rename = "canWrite")] 31 | can_write: bool, 32 | #[serde(rename = "canRead")] 33 | can_read: bool, 34 | } 35 | 36 | #[derive(Serialize, Deserialize)] 37 | pub struct State { 38 | pub methods: Vec, 39 | pub props: Vec, 40 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 kovalevdmv 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /source/base_template/cpp/include/IMemoryManager.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Warning!!! 3 | * DO NOT ALTER THIS FILE! 4 | */ 5 | 6 | 7 | #ifndef __IMEMORY_MANAGER_H__ 8 | #define __IMEMORY_MANAGER_H__ 9 | 10 | /////////////////////////////////////////////////////////////////////////////// 11 | /** 12 | * The given class allocates and releases memory for a component 13 | */ 14 | /// Interface representing memory manager. 15 | class IMemoryManager 16 | { 17 | public: 18 | virtual ~IMemoryManager() {} 19 | /// Allocates memory of specified size 20 | /** 21 | * @param pMemory - the double pointer to variable, that will hold newly 22 | * allocated block of memory of NULL if allocation fails. 23 | * @param ulCountByte - memory size 24 | * @return the result of 25 | */ 26 | virtual bool ADDIN_API AllocMemory (void** pMemory, unsigned long ulCountByte) = 0; 27 | /// Releases memory 28 | /** 29 | * @param pMemory - The double pointer to the memory block being released 30 | */ 31 | virtual void ADDIN_API FreeMemory (void** pMemory) = 0; 32 | }; 33 | 34 | #endif //__IMEMORY_MANAGER_H__ 35 | -------------------------------------------------------------------------------- /app_tauri/src-tauri/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "one-comp-gen" 3 | version = "0.1.0" 4 | description = "A Tauri App" 5 | authors = ["kovalevdv"] 6 | edition = "2021" 7 | 8 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 9 | 10 | [lib] 11 | # The `_lib` suffix may seem redundant but it is necessary 12 | # to make the lib name unique and wouldn't conflict with the bin name. 13 | # This seems to be only an issue on Windows, see https://github.com/rust-lang/cargo/issues/8519 14 | name = "onec_comp_gen_lib" 15 | crate-type = ["staticlib", "cdylib", "rlib"] 16 | 17 | [build-dependencies] 18 | tauri-build = { version = "2", features = [] } 19 | 20 | [dependencies] 21 | tauri = { version = "2", features = [] } 22 | tauri-plugin-shell = "2" 23 | serde = { version = "1", features = ["derive"] } 24 | serde_json = "1" 25 | regex = "1.5" 26 | 27 | 28 | [profile.release] 29 | panic = "abort" # Strip expensive panic clean-up logic 30 | codegen-units = 1 # Compile crates one after another so the compiler can optimize better 31 | lto = true # Enables link to optimizations 32 | opt-level = "s" # Optimize for binary size 33 | strip = true # Remove debug symbols 34 | -------------------------------------------------------------------------------- /app_tauri/src/App.tsx: -------------------------------------------------------------------------------- 1 | import { Box, Container, Flex, Tabs } from "@mantine/core"; 2 | import "./App.css"; 3 | import FunctionPanel from "./components/FunctionPanel"; 4 | import ThemeSwitcher from "./components/ThemeSwitcher"; 5 | import BuildPanel from "./components/BuildPanel"; 6 | 7 | 8 | export default function App() { 9 | return ( 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | Функции 19 | Процедуры 20 | Сборка 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 |
39 | ); 40 | } 41 | -------------------------------------------------------------------------------- /source/base_template/cpp/source/MacOSXBundleInfo.plist.in: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleExecutable 8 | ${MACOSX_BUNDLE_EXECUTABLE_NAME} 9 | CFBundleGetInfoString 10 | ${MACOSX_BUNDLE_INFO_STRING} 11 | CFBundleIconFile 12 | ${MACOSX_BUNDLE_ICON_FILE} 13 | CFBundleIdentifier 14 | ${MACOSX_BUNDLE_GUI_IDENTIFIER} 15 | CFBundleInfoDictionaryVersion 16 | 6.0 17 | CFBundleLongVersionString 18 | ${MACOSX_BUNDLE_LONG_VERSION_STRING} 19 | CFBundleName 20 | ${MACOSX_BUNDLE_BUNDLE_NAME} 21 | CFBundlePackageType 22 | BNDL 23 | CFBundleShortVersionString 24 | ${MACOSX_BUNDLE_SHORT_VERSION_STRING} 25 | CFBundleSignature 26 | ???? 27 | CFBundleVersion 28 | ${MACOSX_BUNDLE_BUNDLE_VERSION} 29 | CSResourcesFileMapped 30 | 31 | NSHumanReadableCopyright 32 | ${MACOSX_BUNDLE_COPYRIGHT} 33 | 34 | 35 | -------------------------------------------------------------------------------- /app_tauri/public/vite.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /source/base_template/cpp/source/Info.plist.in: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleExecutable 8 | 1CEAdnWebNPAPISafOSX 9 | CFBundleGetInfoString 10 | 1CEAdnWebNPAPI 11 | CFBundleIconFile 12 | 13 | CFBundleIdentifier 14 | @MYCOMPANY@.ExtCompAdapter 15 | CFBundleInfoDictionaryVersion 16 | 6.0 17 | CFBundleLongVersionString 18 | 19 | CFBundleName 20 | @ADN_NAME@ 21 | CFBundlePackageType 22 | BRPL 23 | CFBundleShortVersionString 24 | 25 | CFBundleSignature 26 | ???? 27 | CFBundleVersion 28 | 29 | CSResourcesFileMapped 30 | 31 | NSHumanReadableCopyright 32 | "MACOSX_BUNDLE_COPYRIGHT@. 33 | WebPluginDescription 34 | @MYCOMPANY@ @ADN_NAME@ 35 | WebPluginMIMETypes 36 | 37 | @MIMETYPE@ 38 | 39 | WebPluginTypeDescription 40 | @MYCOMPANY@ @ADN_NAME@ 41 | 42 | 43 | WebPluginName 44 | @MYCOMPANY@ @ADN_NAME@ 45 | 46 | 47 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Конструктор внешних компонент для 1С C++/Rust 2 | 3 | Конструктор упрощает процесс разработки за счет удобного добавления всех нужных функций и процедур в графическом режиме, с указанием их параметров и типов параметров. На выходе приложение генерирует коготовый код на С++ и Rust и позволяет сразу приступить к реализации, без настройку API компоненты вручную. 4 | 5 | Также конструктор можно использовать для интеграции библиотек на Rust в компоненту на С++. На С++ можно написать только прослойку для взаимодействия компоненты и платформы, а вся основная логика будет реализована в библиотеке на Rust. Но при этом, если Rust не нужен, конструктор может сгенерировать код только для С++ (за создание метода на rust отвечает флаг "Вызов Rust метода" при добавлении метода в конструкторе). 6 | 7 | ## Сборка 8 | 1. Установить nodejs и среду для сборки rust 9 | 2. Из каталога `onec_comp_gen\app_tauri\src-tauri` выполнить 10 | ``` 11 | npm run tauri build 12 | ``` 13 | Собранные файлы в каталоге `onec_comp_gen\app_tauri\src-tauri\target\release` 14 | Так же готовая сборка для текущей версии в разделе "релизы" 15 | ## Использование 16 | Скопировать собранный исполняемый файл из каталога `onec_comp_gen\app_tauri\src-tauri\target\release` в каталог `onec_comp_gen\source` и запустить 17 | 18 | # Сборка компоненты под linux 19 | В каталоге cpp/source выполнить 20 | ``` 21 | cmake . && make 22 | ``` 23 | 24 | [Статья на infostart.ru](https://infostart.ru/1c/2252892/) 25 | 26 | [Видео инструкция для конструктора](https://t.me/FastAbout1s/69) 27 | 28 | [Общая методика разработки внешних компонент по технологи native api (видео)](https://t.me/FastAbout1s/51) 29 | 30 | -------------------------------------------------------------------------------- /app_tauri/src/components/BuildPanel.tsx: -------------------------------------------------------------------------------- 1 | import { Button, Flex, Input, Notification } from "@mantine/core"; 2 | import useStore from "../store"; 3 | import { invoke } from "@tauri-apps/api/core"; 4 | import React, { useEffect, useState } from "react"; 5 | 6 | export default function BuildPanel() { 7 | const [buildPath, setBuildPath] = useState(""); 8 | const [return_build, setReturn_build] = React.useState(""); 9 | 10 | async function build() { 11 | let res = (await invoke("build", { 12 | path: buildPath, 13 | state: JSON.stringify({ 14 | methods: [...useStore.getState().methods], 15 | props: [...useStore.getState().props], 16 | }), 17 | })) as String; 18 | 19 | console.log(res); 20 | 21 | setReturn_build(res); 22 | } 23 | 24 | useEffect(() => { 25 | if (!buildPath) { 26 | invoke("current_dir").then((path) => { 27 | setBuildPath(path); 28 | }) 29 | } 30 | }, []); 31 | 32 | return ( 33 | <> 34 | {!!return_build && ( 35 | setReturn_build("")} 37 | closeButtonProps={{ "aria-label": "Hide notification" }} 38 | > 39 | {return_build} 40 | 41 | )} 42 | 43 | 44 | 45 | setBuildPath(e.target.value)} 49 | > 50 | 51 | 52 | 53 | 54 | ); 55 | } 56 | -------------------------------------------------------------------------------- /app_tauri/src/store.ts: -------------------------------------------------------------------------------- 1 | import { create } from "zustand"; 2 | 3 | export interface Params { 4 | uuid: string; 5 | name: string; 6 | type: string; 7 | } 8 | 9 | interface Method { 10 | uuid: string; 11 | name: string; 12 | nameEng: string; 13 | params: Params[]; 14 | hasReturn: boolean; 15 | ReturnType?: string; 16 | callRustMethod: boolean; 17 | } 18 | 19 | interface Props { 20 | uuid: string; 21 | name: string; 22 | canWrite: boolean; 23 | canRead: boolean; 24 | } 25 | 26 | interface State { 27 | methods: Method[]; 28 | props: Props[]; 29 | // actions 30 | addMethod: (method: Method) => void; 31 | saveMethod: (method: Method) => void; 32 | addProp: (prop: Props) => void; 33 | deleteMethod: (uuid: string) => void; 34 | deleteParam: (methodUuid: string, paramUuid: string) => void; 35 | } 36 | 37 | const useStore = create()((set) => ({ 38 | methods: [], 39 | props: [], 40 | addMethod: (method: Method) => 41 | set((state) => ({ methods: [...state.methods, method] })), 42 | saveMethod: (method: Method) => 43 | set((state) => ({ 44 | methods: state.methods.map((m) => (m.uuid === method.uuid ? method : m)), 45 | })), 46 | addProp: (prop: Props) => set((state) => ({ props: [...state.props, prop] })), 47 | deleteMethod: (uuid: string) => 48 | set((state) => ({ methods: state.methods.filter((m) => m.uuid !== uuid) })), 49 | deleteParam: (methodUuid: string, paramUuid: string) => 50 | set((state) => ({ 51 | methods: state.methods.map((method) => 52 | method.uuid === methodUuid 53 | ? { 54 | ...method, 55 | params: method.params.filter((param) => param.uuid !== paramUuid), 56 | } 57 | : method 58 | ), 59 | })), 60 | })); 61 | 62 | export default useStore; 63 | -------------------------------------------------------------------------------- /app_tauri/src-tauri/src/file_op.rs: -------------------------------------------------------------------------------- 1 | use std::fs; 2 | use std::io; 3 | use std::path::Path; 4 | 5 | use regex::Regex; 6 | 7 | pub fn copy_directory(source: String, destination: String) -> io::Result<()> { 8 | // Create destination directory if it doesn't exist 9 | if !Path::new(&destination).exists() { 10 | fs::create_dir_all(&destination)?; 11 | } 12 | 13 | // Read source directory entries 14 | for entry in fs::read_dir(&source)? { 15 | let entry = entry?; 16 | let entry_path = entry.path(); 17 | let file_name = entry.file_name(); 18 | let destination_path = Path::new(&destination).join(file_name); 19 | 20 | if entry_path.is_dir() { 21 | // Recursively copy subdirectories 22 | copy_directory( 23 | entry_path.to_string_lossy().to_string(), 24 | destination_path.to_string_lossy().to_string() 25 | )?; 26 | } else { 27 | // Copy files 28 | fs::copy(&entry_path, &destination_path)?; 29 | } 30 | } 31 | 32 | Ok(()) 33 | } 34 | 35 | 36 | pub fn replace_text_in_file(file_path: &String, target_text: String, new_text: String) -> io::Result<()> { 37 | let content = fs::read_to_string(&file_path)?; 38 | let new_content = content.replace(&target_text, &new_text); 39 | fs::write(&file_path, new_content)?; 40 | 41 | Ok(()) 42 | } 43 | 44 | pub fn replace_text_in_file_regex(file_path: &String, pattern: &str, new_text: &str) -> io::Result<()> { 45 | let content = fs::read_to_string(file_path)?; 46 | let regex = Regex::new(pattern) 47 | .map_err(|e| io::Error::new(io::ErrorKind::InvalidInput, e))?; 48 | let new_content = regex.replace_all(&content, new_text); 49 | fs::write(file_path, new_content.as_bytes())?; 50 | 51 | Ok(()) 52 | } 53 | 54 | pub fn exists_base_template(file_path: String) -> bool { 55 | Path::new(&file_path).exists() 56 | } -------------------------------------------------------------------------------- /app_tauri/public/tauri.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /source/base_template/cpp/source/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | CMAKE_MINIMUM_REQUIRED(VERSION 3.6 FATAL_ERROR) 2 | 3 | foreach(policy CMP0068) 4 | if(POLICY ${policy}) 5 | cmake_policy(SET ${policy} NEW) 6 | endif() 7 | endforeach() 8 | 9 | PROJECT(AddInNative CXX) 10 | 11 | IF(WIN32) 12 | ENABLE_LANGUAGE(RC) 13 | ENDIF() 14 | #----------------------------------------------------------------------------------------------------------------# 15 | #--source files------------------- 16 | SET(AddInNative_SRC 17 | AddInNative.cpp 18 | dllmain.cpp 19 | stdafx.cpp 20 | stdafx.h 21 | ../lib/common.cpp 22 | impl/test.cpp 23 | #ВставкаCPPФайлов 24 | ) 25 | if (WIN32) 26 | LIST(APPEND AddInNative_SRC AddInNative.rc AddInNative.def) 27 | endif() 28 | #--source files end--------------- 29 | set(ADN_NAME ${PROJECT_NAME}) 30 | set(MECONPANY "MyCompany") 31 | #----------------------------------------------------------------------------------------------------------------# 32 | include_directories(${CMAKE_SOURCE_DIR}/../include) 33 | 34 | SET (CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} ${CMAKE_SOURCE_DIR}) 35 | 36 | if (UNIX) 37 | else() 38 | add_definitions(-DUNICODE -DWIN32 -D_USRDLL -D_CRT_SECURE_NO_WARNINGS -D_CRT_SECURE_NO_DEPRECATE -DADDINCPP_EXPORTS) 39 | endif() 40 | 41 | add_library(${PROJECT_NAME} SHARED ${AddInNative_SRC}) 42 | target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) 43 | 44 | if (WIN32) 45 | target_precompile_headers(${PROJECT_NAME} PUBLIC stdafx.h) 46 | endif() 47 | 48 | set_target_properties( ${PROJECT_NAME} PROPERTIES 49 | POSITION_INDEPENDENT_CODE ON 50 | CXX_STANDARD 11 51 | CXX_STANDARD_REQUIRED ON 52 | ) 53 | IF (UNIX AND NOT APPLE) 54 | set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "-Wl,--no-undefined -Xlinker --version-script -Xlinker ${CMAKE_CURRENT_SOURCE_DIR}/version.script" ) 55 | ENDIF() 56 | 57 | if (WIN32) 58 | target_link_libraries(AddInNative PRIVATE ${CMAKE_SOURCE_DIR}/../../rust/target/debug/rust_1c.lib 59 | ntdll 60 | Ws2_32 61 | Crypt32 62 | Secur32 63 | Bcrypt 64 | Userenv 65 | ) 66 | else() 67 | target_link_libraries(AddInNative PRIVATE ${CMAKE_SOURCE_DIR}/../../rust/target/debug/librust_1c.a -static-libstdc++) 68 | endif() 69 | 70 | # Integrate Rust build into the CMake build system 71 | add_custom_target(RustBuild ALL 72 | COMMAND cargo build 73 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/../../rust/ 74 | COMMENT "Building Rust project with Cargo" 75 | ) 76 | 77 | # Ensure that the Rust library is built before AddInNative 78 | add_dependencies(${PROJECT_NAME} RustBuild) -------------------------------------------------------------------------------- /source/base_template/rust/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 3 4 | 5 | [[package]] 6 | name = "itoa" 7 | version = "1.0.14" 8 | source = "registry+https://github.com/rust-lang/crates.io-index" 9 | checksum = "d75a2a4b1b190afb6f5425f10f6a8f959d2ea0b9c2b1d79553551850539e4674" 10 | 11 | [[package]] 12 | name = "memchr" 13 | version = "2.7.4" 14 | source = "registry+https://github.com/rust-lang/crates.io-index" 15 | checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" 16 | 17 | [[package]] 18 | name = "proc-macro2" 19 | version = "1.0.92" 20 | source = "registry+https://github.com/rust-lang/crates.io-index" 21 | checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0" 22 | dependencies = [ 23 | "unicode-ident", 24 | ] 25 | 26 | [[package]] 27 | name = "quote" 28 | version = "1.0.37" 29 | source = "registry+https://github.com/rust-lang/crates.io-index" 30 | checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" 31 | dependencies = [ 32 | "proc-macro2", 33 | ] 34 | 35 | [[package]] 36 | name = "rust_1c" 37 | version = "0.1.0" 38 | dependencies = [ 39 | "serde", 40 | "serde_json", 41 | ] 42 | 43 | [[package]] 44 | name = "ryu" 45 | version = "1.0.18" 46 | source = "registry+https://github.com/rust-lang/crates.io-index" 47 | checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" 48 | 49 | [[package]] 50 | name = "serde" 51 | version = "1.0.215" 52 | source = "registry+https://github.com/rust-lang/crates.io-index" 53 | checksum = "6513c1ad0b11a9376da888e3e0baa0077f1aed55c17f50e7b2397136129fb88f" 54 | dependencies = [ 55 | "serde_derive", 56 | ] 57 | 58 | [[package]] 59 | name = "serde_derive" 60 | version = "1.0.215" 61 | source = "registry+https://github.com/rust-lang/crates.io-index" 62 | checksum = "ad1e866f866923f252f05c889987993144fb74e722403468a4ebd70c3cd756c0" 63 | dependencies = [ 64 | "proc-macro2", 65 | "quote", 66 | "syn", 67 | ] 68 | 69 | [[package]] 70 | name = "serde_json" 71 | version = "1.0.133" 72 | source = "registry+https://github.com/rust-lang/crates.io-index" 73 | checksum = "c7fceb2473b9166b2294ef05efcb65a3db80803f0b03ef86a5fc88a2b85ee377" 74 | dependencies = [ 75 | "itoa", 76 | "memchr", 77 | "ryu", 78 | "serde", 79 | ] 80 | 81 | [[package]] 82 | name = "syn" 83 | version = "2.0.90" 84 | source = "registry+https://github.com/rust-lang/crates.io-index" 85 | checksum = "919d3b74a5dd0ccd15aeb8f93e7006bd9e14c295087c9896a110f490752bcf31" 86 | dependencies = [ 87 | "proc-macro2", 88 | "quote", 89 | "unicode-ident", 90 | ] 91 | 92 | [[package]] 93 | name = "unicode-ident" 94 | version = "1.0.14" 95 | source = "registry+https://github.com/rust-lang/crates.io-index" 96 | checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83" 97 | -------------------------------------------------------------------------------- /source/base_template/cpp/source/AddInNative.h: -------------------------------------------------------------------------------- 1 | #ifndef __ADDINNATIVE_H__ 2 | #define __ADDINNATIVE_H__ 3 | 4 | #include "ComponentBase.h" 5 | #include "AddInDefBase.h" 6 | #include "IMemoryManager.h" 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include 13 | #include 14 | 15 | #include "impl/test.h" 16 | 17 | 18 | /////////////////////////////////////////////////////////////////////////////// 19 | // class CAddInNative 20 | class CAddInNative : public IComponentBase 21 | { 22 | public: 23 | enum Props 24 | { 25 | TestProp, 26 | //ДляВставкиСвойств 27 | eLastProp // Always last 28 | }; 29 | 30 | enum Methods 31 | { 32 | Test, 33 | //ДляВставкиМетодов 34 | eLastMethod // Always last 35 | 36 | }; 37 | 38 | CAddInNative(void); 39 | virtual ~CAddInNative(); 40 | // IInitDoneBase 41 | virtual bool ADDIN_API Init(void*) override; 42 | virtual bool ADDIN_API setMemManager(void* mem) override; 43 | virtual long ADDIN_API GetInfo() override; 44 | virtual void ADDIN_API Done() override; 45 | // ILanguageExtenderBase 46 | virtual bool ADDIN_API RegisterExtensionAs(WCHAR_T**) override; 47 | virtual long ADDIN_API GetNProps() override; 48 | virtual long ADDIN_API FindProp(const WCHAR_T* wsPropName) override; 49 | virtual const WCHAR_T* ADDIN_API GetPropName(long lPropNum, long lPropAlias) override; 50 | virtual bool ADDIN_API GetPropVal(const long lPropNum, tVariant* pvarPropVal) override; 51 | virtual bool ADDIN_API SetPropVal(const long lPropNum, tVariant* varPropVal) override; 52 | virtual bool ADDIN_API IsPropReadable(const long lPropNum) override; 53 | virtual bool ADDIN_API IsPropWritable(const long lPropNum) override; 54 | virtual long ADDIN_API GetNMethods() override; 55 | virtual long ADDIN_API FindMethod(const WCHAR_T* wsMethodName) override; 56 | virtual const WCHAR_T* ADDIN_API GetMethodName(const long lMethodNum, 57 | const long lMethodAlias) override; 58 | virtual long ADDIN_API GetNParams(const long lMethodNum) override; 59 | virtual bool ADDIN_API GetParamDefValue(const long lMethodNum, const long lParamNum, 60 | tVariant *pvarParamDefValue) override; 61 | virtual bool ADDIN_API HasRetVal(const long lMethodNum) override; 62 | virtual bool ADDIN_API CallAsProc(const long lMethodNum, 63 | tVariant* paParams, const long lSizeArray) override; 64 | virtual bool ADDIN_API CallAsFunc(const long lMethodNum, 65 | tVariant* pvarRetValue, tVariant* paParams, const long lSizeArray) override; 66 | // LocaleBase 67 | virtual void ADDIN_API SetLocale(const WCHAR_T* loc) override; 68 | // UserLanguageBase 69 | virtual void ADDIN_API SetUserInterfaceLanguageCode(const WCHAR_T* lang) override; 70 | 71 | private: 72 | // Attributes 73 | long findName(wchar_t* names[], const wchar_t* name, const uint32_t size) const; 74 | IMemoryManager* m_iMemory; 75 | IAddInDefBase* m_iConnect; 76 | wchar_t* pTestProp = 0; 77 | }; 78 | #endif //__ADDINNATIVE_H__ 79 | 80 | -------------------------------------------------------------------------------- /app_tauri/src/assets/react.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /app_tauri/src/components/FunctionPanel.tsx: -------------------------------------------------------------------------------- 1 | import useStore from "../store"; 2 | import FormOfMethods, { useFormOfMethods } from "./FormOfMethods"; 3 | import { ActionIcon, Badge, Box, Flex, Table, Tooltip } from "@mantine/core"; 4 | import IconAdd from "./IconAdd"; 5 | import IconTrash from "./IconTrash"; 6 | import IconEdit from "./IconEdit"; 7 | 8 | interface Props { 9 | isFunction: boolean; 10 | } 11 | 12 | export default function FunctionPanel({ isFunction }: Props) { 13 | const methods = useStore((state) => state.methods); 14 | const deleteMethod = useStore((state) => state.deleteMethod); 15 | 16 | const formOfMethods = useFormOfMethods(); 17 | 18 | function addMethod() { 19 | formOfMethods.setUUID(""); 20 | formOfMethods.toggleOpen(); 21 | } 22 | 23 | function EditMethod(uuid: string) { 24 | formOfMethods.setUUID(uuid); 25 | formOfMethods.toggleOpen(); 26 | } 27 | 28 | function DeleteMethod(uuid: string): void { 29 | deleteMethod(uuid); 30 | } 31 | 32 | return ( 33 | <> 34 | 35 | {formOfMethods.open && ( 36 | 37 | )} 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | Имя 47 | Имя (eng) 48 | Параметры 49 | {isFunction && Тип возврата} 50 | Действия 51 | 52 | 53 | 54 | {methods 55 | .filter((item) => item.hasReturn == isFunction) 56 | .map((item) => ( 57 | EditMethod(item.uuid)} 60 | > 61 | {item.name} 62 | {item.nameEng} 63 | 64 | 65 | {item.callRustMethod && ( 66 | 67 | 68 | rust 69 | 70 | 71 | )} 72 | 73 | {item.params.map((par) => ( 74 | {`${par.name}:${par.type}`} 79 | ))} 80 | 81 | 82 | {isFunction && {item.ReturnType}} 83 | 84 | 85 | 86 | 87 | DeleteMethod(item.uuid)} 92 | > 93 | 94 | 95 | 96 | 97 | EditMethod(item.uuid)} 101 | > 102 | 103 | 104 | 105 | 106 | 107 | 108 | ))} 109 | 110 |
111 |
112 | 113 | ); 114 | } 115 | -------------------------------------------------------------------------------- /source/base_template/cpp/include/com.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __COM_H__ 3 | #define __COM_H__ 4 | 5 | #if defined(__linux__) || defined(__APPLE__) || defined(__ANDROID__) 6 | 7 | #ifdef __ANDROID__ 8 | 9 | typedef struct { 10 | unsigned int Data1; 11 | unsigned short Data2; 12 | unsigned short Data3; 13 | unsigned char Data4[ 8 ]; 14 | } uuid_t; 15 | 16 | #else 17 | #include 18 | #endif //__ANDROID__ 19 | 20 | #ifndef __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ // iOS 21 | #include 22 | #endif //!__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ 23 | 24 | #pragma GCC system_header 25 | 26 | typedef long HRESULT; 27 | 28 | #ifdef __GNUC__ 29 | #define STDMETHODCALLTYPE __attribute__ ((__stdcall__)) 30 | #define DECLSPEC_NOTHROW __attribute__ ((nothrow)) 31 | #define STDMETHOD(method) virtual DECLSPEC_NOTHROW HRESULT STDMETHODCALLTYPE method 32 | #else 33 | #define STDMETHODCALLTYPE 34 | #endif 35 | 36 | #define __stdcall STDMETHODCALLTYPE 37 | #define near 38 | #define far 39 | #define CONST const 40 | #define FAR far 41 | 42 | typedef unsigned long DWORD; 43 | #ifndef __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ // iOS 44 | typedef int BOOL; 45 | #elif defined(__LP64__) 46 | typedef bool BOOL; 47 | #else 48 | typedef signed char BOOL; 49 | #endif //!__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ 50 | 51 | typedef void VOID; 52 | typedef short SHORT; 53 | typedef unsigned char BYTE; 54 | typedef unsigned short WORD; 55 | typedef float FLOAT; 56 | typedef FLOAT *PFLOAT; 57 | typedef BOOL near *PBOOL; 58 | typedef BOOL far *LPBOOL; 59 | typedef BYTE near *PBYTE; 60 | typedef BYTE far *LPBYTE; 61 | typedef int near *PINT; 62 | typedef int far *LPINT; 63 | typedef WORD near *PWORD; 64 | typedef WORD far *LPWORD; 65 | typedef long far *LPLONG; 66 | typedef DWORD near *PDWORD; 67 | typedef DWORD far *LPDWORD; 68 | typedef void far *LPVOID; 69 | typedef CONST void far *LPCVOID; 70 | typedef wchar_t *BSTR; 71 | typedef long SCODE; 72 | typedef int INT; 73 | typedef unsigned int UINT; 74 | typedef unsigned int *PUINT; 75 | typedef wchar_t WCHAR; 76 | typedef wchar_t OLECHAR; 77 | typedef wchar_t *LPOLESTR; 78 | typedef const wchar_t *LPCOLESTR; 79 | typedef DWORD LCID; 80 | typedef PDWORD PLCID; 81 | typedef long LONG; 82 | typedef unsigned long ULONG; 83 | typedef long long LONGLONG; 84 | typedef unsigned long long ULONGLONG; 85 | typedef LONG DISPID; 86 | typedef double DOUBLE; 87 | typedef double DATE; 88 | typedef short VARIANT_BOOL; 89 | typedef void *PVOID; 90 | typedef char CHAR; 91 | typedef CONST CHAR *LPCSTR; 92 | typedef unsigned short USHORT; 93 | typedef void *HMODULE; 94 | #define OLESTR(str) L##str 95 | 96 | typedef uuid_t GUID; 97 | typedef uuid_t IID; 98 | typedef uuid_t UUID; 99 | #define REFIID const IID & 100 | #define MAX_PATH 260 101 | 102 | #define IsEqualIID(x,y) uuid_compare((x),(y)) 103 | #ifdef __GNUC__ 104 | #define LoadLibraryA(x) dlopen((x), RTLD_LAZY) 105 | #define FreeLibrary(x) dlclose((x)) 106 | #define GetProcAddress(x, y) dlsym((x), (y)) 107 | #endif //__GNUC__ 108 | 109 | #define E_FAIL 0x80004005L 110 | #define S_OK 0L 111 | #define S_FALSE 1L 112 | #define E_NOINTERFACE 0x80004002L 113 | #define E_NOTIMPL 0x80004001L 114 | #define E_INVALIDARG 0x80070057L 115 | #define E_UNEXPECTED 0x8000FFFFL 116 | #define E_OUTOFMEMORY 0x8007000EL 117 | #define DISP_E_UNKNOWNNAME 0x80020006L 118 | #define DISPID_UNKNOWN ( -1 ) 119 | #define TRUE 1 120 | #define FALSE 0 121 | 122 | typedef long ITypeInfo; 123 | 124 | #if defined (__GNUC__) && !defined (NONAMELESSUNION) 125 | __extension__ /* no named members */ 126 | #endif 127 | union tCY { 128 | __extension__ struct 129 | { 130 | unsigned long Lo; 131 | long Hi; 132 | }; 133 | long long int64; 134 | }; 135 | typedef union tagCY CY; 136 | #define CLSIDFromString(x,y) uuid_parse((x),(unsigned char*)(y)) 137 | 138 | #endif //defined(__linux__) || defined(__APPLE__) 139 | 140 | #endif //__COM_H__ 141 | -------------------------------------------------------------------------------- /source/base_template/cpp/include/MANIFEST.xsd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Bundle description 6 | 7 | 8 | 9 | 10 | 11 | 12 | Name component 13 | 14 | 15 | 16 | 17 | 18 | 19 | Platform type 20 | 21 | 22 | 23 | 24 | File name 25 | 26 | 27 | 28 | 29 | Component type 30 | 31 | 32 | 33 | 34 | Object name 35 | 36 | 37 | 38 | 39 | Architecture 40 | 41 | 42 | 43 | 44 | Client type 45 | 46 | 47 | 48 | 49 | Client version 50 | 51 | 52 | 53 | 54 | Build type 55 | 56 | 57 | 58 | 59 | Code type 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | -------------------------------------------------------------------------------- /source/base_template/cpp/include/AddInDefBase.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Warning!!! 3 | * DO NOT ALTER THIS FILE! 4 | */ 5 | 6 | #ifndef __ADAPTER_DEF_H__ 7 | #define __ADAPTER_DEF_H__ 8 | #include "types.h" 9 | 10 | struct IInterface 11 | { 12 | }; 13 | 14 | 15 | enum Interfaces 16 | { 17 | eIMsgBox = 0, 18 | eIPlatformInfo, 19 | #if defined(__ANDROID__) 20 | eIAndroidComponentHelper, 21 | #endif 22 | eIAttachedInfo, 23 | }; 24 | 25 | //////////////////////////////////////////////////////////////////////////////// 26 | /** 27 | * This class serves as representation of a platform for external 28 | * components External components use it to communicate with a platform. 29 | * 30 | */ 31 | /// Base interface for object components. 32 | class IAddInDefBase 33 | { 34 | public: 35 | virtual ~IAddInDefBase() {} 36 | /// Adds the error message 37 | /** 38 | * @param wcode - error code 39 | * @param source - source of error 40 | * @param descr - description of error 41 | * @param scode - error code (HRESULT) 42 | * @return the result of 43 | */ 44 | virtual bool ADDIN_API AddError(unsigned short wcode, const WCHAR_T* source, 45 | const WCHAR_T* descr, long scode) = 0; 46 | 47 | /// Reads a property value 48 | /** 49 | * @param wszPropName -property name 50 | * @param pVal - value being returned 51 | * @param pErrCode - error code (if any error occured) 52 | * @param errDescriptor - error description (if any error occured) 53 | * @return the result of read. 54 | */ 55 | virtual bool ADDIN_API Read(WCHAR_T* wszPropName, 56 | tVariant* pVal, 57 | long *pErrCode, 58 | WCHAR_T** errDescriptor) = 0; 59 | /// Writes a property value 60 | /** 61 | * @param wszPropName - property name 62 | * @param pVar - new property value 63 | * @return the result of write. 64 | */ 65 | virtual bool ADDIN_API Write(WCHAR_T* wszPropName, 66 | tVariant *pVar) = 0; 67 | 68 | ///Registers profile components 69 | /** 70 | * @param wszProfileName - profile name 71 | * @return the result of 72 | */ 73 | virtual bool ADDIN_API RegisterProfileAs(WCHAR_T* wszProfileName) = 0; 74 | 75 | /// Changes the depth of event buffer 76 | /** 77 | * @param lDepth - new depth of event buffer 78 | * @return the result of 79 | */ 80 | virtual bool ADDIN_API SetEventBufferDepth(long lDepth) = 0; 81 | /// Returns the depth of event buffer 82 | /** 83 | * @return the depth of event buffer 84 | */ 85 | virtual long ADDIN_API GetEventBufferDepth() = 0; 86 | /// Registers external event 87 | /** 88 | * @param wszSource - source of event 89 | * @param wszMessage - event message 90 | * @param wszData - message parameters 91 | * @return the result of 92 | */ 93 | virtual bool ADDIN_API ExternalEvent(WCHAR_T* wszSource, 94 | WCHAR_T* wszMessage, 95 | WCHAR_T* wszData) = 0; 96 | /// Clears event buffer 97 | /** 98 | */ 99 | virtual void ADDIN_API CleanEventBuffer() = 0; 100 | 101 | /// Sets status line contents 102 | /** 103 | * @param wszStatusLine - new status line contents 104 | * @return the result of 105 | */ 106 | virtual bool ADDIN_API SetStatusLine(WCHAR_T* wszStatusLine) = 0; 107 | /// Resets the status line contents 108 | /** 109 | * @return the result of 110 | */ 111 | virtual void ADDIN_API ResetStatusLine() = 0; 112 | }; 113 | 114 | class IAddInDefBaseEx : 115 | public IAddInDefBase 116 | { 117 | public: 118 | virtual ~IAddInDefBaseEx() {} 119 | 120 | virtual IInterface* ADDIN_API GetInterface(Interfaces iface) = 0; 121 | }; 122 | 123 | struct IMsgBox : 124 | public IInterface 125 | { 126 | virtual bool ADDIN_API Confirm(const WCHAR_T* queryText, tVariant* retVal) = 0; 127 | 128 | virtual bool ADDIN_API Alert(const WCHAR_T* text) = 0; 129 | }; 130 | 131 | struct IPlatformInfo : 132 | public IInterface 133 | { 134 | enum AppType 135 | { 136 | eAppUnknown = -1, 137 | eAppThinClient = 0, 138 | eAppThickClient, 139 | eAppWebClient, 140 | eAppServer, 141 | eAppExtConn, 142 | eAppMobileClient, 143 | eAppMobileServer, 144 | }; 145 | 146 | struct AppInfo 147 | { 148 | const WCHAR_T* AppVersion; 149 | const WCHAR_T* UserAgentInformation; 150 | AppType Application; 151 | }; 152 | 153 | virtual const AppInfo* ADDIN_API GetPlatformInfo() = 0; 154 | }; 155 | struct IAttachedInfo : 156 | public IInterface 157 | { 158 | enum AttachedType 159 | { 160 | eAttachedIsolated = 0, 161 | eAttachedNotIsolated, 162 | }; 163 | virtual const AttachedType ADDIN_API GetAttachedInfo() = 0; 164 | }; 165 | #endif //__ADAPTER_DEF_H__ 166 | -------------------------------------------------------------------------------- /source/base_template/cpp/lib/common.cpp: -------------------------------------------------------------------------------- 1 | #include "common.h" 2 | #include 3 | #include 4 | #include 5 | 6 | #ifdef _WIN32 7 | #include 8 | #else 9 | #include 10 | #endif 11 | 12 | void set_return_val_for_1c_as_utf16(tVariant* pvarRetValue, std::u16string val, IMemoryManager* m_iMemory) 13 | { 14 | TV_VT(pvarRetValue) = VTYPE_PWSTR; 15 | 16 | size_t length = val.length() + 1; 17 | 18 | if (m_iMemory && m_iMemory->AllocMemory((void**)&(pvarRetValue->pwstrVal), length * sizeof(char16_t))) 19 | { 20 | memcpy(pvarRetValue->pwstrVal, val.c_str(), length * sizeof(char16_t)); 21 | pvarRetValue->wstrLen = length - 1; 22 | } 23 | } 24 | 25 | std::u16string utf8_to_utf16(const std::string& utf8) 26 | { 27 | #ifdef _WIN32 28 | if (utf8.empty()) { 29 | return std::u16string(); 30 | } 31 | int size_needed = MultiByteToWideChar(CP_UTF8, 0, &utf8[0], (int)utf8.size(), NULL, 0); 32 | std::u16string utf16(size_needed, 0); 33 | MultiByteToWideChar(CP_UTF8, 0, &utf8[0], (int)utf8.size(), (LPWSTR)&utf16[0], size_needed); 34 | return utf16; 35 | #else 36 | if (utf8.empty()) { 37 | return u""; 38 | } 39 | 40 | iconv_t cd = iconv_open("UTF-16LE", "UTF-8"); 41 | if (cd == (iconv_t)-1) { 42 | throw std::runtime_error("iconv_open failed"); 43 | } 44 | 45 | char* in_buf = const_cast(utf8.c_str()); 46 | size_t in_bytes_left = utf8.size(); 47 | 48 | // Allocate a buffer for the output. It might be larger than needed. 49 | size_t out_buf_size = utf8.length() * sizeof(char16_t) + sizeof(char16_t); 50 | std::vector out_buf(out_buf_size); 51 | char* out_ptr = reinterpret_cast(out_buf.data()); 52 | size_t out_bytes_left = out_buf_size * sizeof(char16_t); 53 | 54 | if (iconv(cd, &in_buf, &in_bytes_left, &out_ptr, &out_bytes_left) == (size_t)-1) { 55 | iconv_close(cd); 56 | throw std::runtime_error("iconv failed"); 57 | } 58 | 59 | iconv_close(cd); 60 | 61 | return std::u16string(out_buf.data()); 62 | #endif 63 | } 64 | 65 | std::string utf16_to_utf8(const std::u16string& utf16) 66 | { 67 | #ifdef _WIN32 68 | if (utf16.empty()) { 69 | return std::string(); 70 | } 71 | int size_needed = WideCharToMultiByte(CP_UTF8, 0, (LPCWSTR)utf16.c_str(), (int)utf16.size(), NULL, 0, NULL, NULL); 72 | std::string utf8(size_needed, 0); 73 | WideCharToMultiByte(CP_UTF8, 0, (LPCWSTR)utf16.c_str(), (int)utf16.size(), &utf8[0], size_needed, NULL, NULL); 74 | return utf8; 75 | #else 76 | if (utf16.empty()) { 77 | return ""; 78 | } 79 | 80 | iconv_t cd = iconv_open("UTF-8", "UTF-16LE"); 81 | if (cd == (iconv_t)-1) { 82 | throw std::runtime_error("iconv_open failed"); 83 | } 84 | 85 | char* in_buf = const_cast(reinterpret_cast(utf16.c_str())); 86 | size_t in_bytes_left = utf16.size() * sizeof(char16_t); 87 | 88 | size_t out_buf_size = utf16.length() * 4 + 1; 89 | std::vector out_buf(out_buf_size); 90 | char* out_ptr = out_buf.data(); 91 | size_t out_bytes_left = out_buf_size; 92 | 93 | if (iconv(cd, &in_buf, &in_bytes_left, &out_ptr, &out_bytes_left) == (size_t)-1) { 94 | iconv_close(cd); 95 | throw std::runtime_error("iconv failed"); 96 | } 97 | 98 | iconv_close(cd); 99 | 100 | return std::string(out_buf.data()); 101 | #endif 102 | } 103 | 104 | //+++ 105 | std::string method_param_to_utf8(tVariant* paParams, int number_param) { 106 | char16_t* param_utf16_pointer = paParams[number_param].pwstrVal; 107 | std::string param_utf8 = utf16_to_utf8(param_utf16_pointer); 108 | 109 | return param_utf8; 110 | } 111 | 112 | std::u16string get_method_param_as_utf16(tVariant* paParams, int number_param) { 113 | 114 | std::u16string param_utf16(paParams[number_param].pwstrVal); 115 | return param_utf16; 116 | } 117 | 118 | std::string get_method_param_as_utf8(tVariant* paParams, int number_param) { 119 | char16_t* param_utf16_pointer = paParams[number_param].pwstrVal; 120 | std::string param_utf8 = utf16_to_utf8(param_utf16_pointer); 121 | return param_utf8; 122 | } 123 | 124 | float get_method_param_as_float(tVariant* paParams, int number_param) { 125 | double param_double = paParams[number_param].dblVal; 126 | return param_double; 127 | } 128 | 129 | int get_method_param_as_int(tVariant* paParams, int number_param) { 130 | double param_int = paParams[number_param].lVal; 131 | return param_int; 132 | } 133 | 134 | bool get_method_param_as_bool(tVariant* paParams, int number_param) { 135 | return paParams[number_param].bVal; 136 | } 137 | 138 | float get_method_param_as_number(tVariant* paParams, int number_param) { 139 | float val = get_method_param_as_float(paParams, number_param); 140 | if (val==0) 141 | val = get_method_param_as_int(paParams, number_param); 142 | return val; 143 | } 144 | 145 | //--- -------------------------------------------------------------------------------- /source/base_template/cpp/include/addin.idl: -------------------------------------------------------------------------------- 1 | import "oaidl.idl"; 2 | import "ocidl.idl"; 3 | 4 | [ 5 | object, 6 | uuid(AB634001-F13D-11d0-A459-004095E1DAEA), 7 | helpstring("IInitDone Interface"), 8 | pointer_default(unique) 9 | ] 10 | interface IInitDone : IUnknown 11 | { 12 | [helpstring("method Init")] HRESULT Init([in] IDispatch *pConnection); 13 | [helpstring("method Done")] HRESULT Done(); 14 | [helpstring("method GetInfo")] HRESULT GetInfo([in,out] SAFEARRAY (VARIANT) *pInfo); 15 | }; 16 | 17 | [ 18 | object, 19 | uuid(AB634002-F13D-11d0-A459-004095E1DAEA), 20 | helpstring("IPropertyProfile Interface"), 21 | pointer_default(unique) 22 | ] 23 | interface IPropertyProfile : IPropertyBag 24 | { 25 | [helpstring("method RegisterProfileAs")] HRESULT RegisterProfileAs(BSTR bstrProfileName); 26 | }; 27 | 28 | [ 29 | object, 30 | uuid(ab634004-f13d-11d0-a459-004095e1daea), 31 | helpstring("IAsyncEvent Interface"), 32 | pointer_default(unique) 33 | ] 34 | interface IAsyncEvent : IUnknown 35 | { 36 | [helpstring("method SetEventBufferDepth")] HRESULT SetEventBufferDepth(long lDepth); 37 | [helpstring("method GetEventBufferDepth")] HRESULT GetEventBufferDepth(long *plDepth); 38 | [helpstring("method ExternalEvent")] HRESULT ExternalEvent(BSTR bstrSource, BSTR bstrMessage, BSTR bstrData); 39 | [helpstring("method CleanBuffer")] HRESULT CleanBuffer(); 40 | }; 41 | [ 42 | object, 43 | uuid(E88A191E-8F52-4261-9FAE-FF7AA84F5D7E), 44 | helpstring("ILocale Interface"), 45 | pointer_default(unique) 46 | ] 47 | interface ILocale : IUnknown 48 | { 49 | [helpstring("method SetLocale")] HRESULT SetLocale(BSTR bstrLocale); 50 | 51 | }; 52 | [ 53 | object, 54 | uuid(AB634003-F13D-11d0-A459-004095E1DAEA), 55 | helpstring("ILanguageExtender Interface"), 56 | pointer_default(unique) 57 | ] 58 | interface ILanguageExtender : IUnknown 59 | { 60 | [helpstring("method RegisterExtensionAs")] HRESULT RegisterExtensionAs([in,out]BSTR *bstrExtensionName); 61 | [helpstring("method GetNProps")] HRESULT GetNProps([in,out]long *plProps); 62 | [helpstring("method FindProp")] HRESULT FindProp([in]BSTR bstrPropName,[in,out]long *plPropNum); 63 | [helpstring("method GetPropName")] HRESULT GetPropName([in]long lPropNum,[in]long lPropAlias,[in,out]BSTR *pbstrPropName); 64 | [helpstring("method GetPropVal")] HRESULT GetPropVal([in]long lPropNum,[in,out]VARIANT *pvarPropVal); 65 | [helpstring("method SetPropVal")] HRESULT SetPropVal([in]long lPropNum,[in]VARIANT *varPropVal); 66 | [helpstring("method IsPropReadable")] HRESULT IsPropReadable([in]long lPropNum,[in,out]BOOL *pboolPropRead); 67 | [helpstring("method IsPropWritable")] HRESULT IsPropWritable([in]long lPropNum,[in,out]BOOL *pboolPropWrite); 68 | 69 | [helpstring("method GetNMethods")] HRESULT GetNMethods([in,out]long *plMethods); 70 | [helpstring("method FindMethod")] HRESULT FindMethod(BSTR bstrMethodName,[in,out]long *plMethodNum); 71 | [helpstring("method GetMethodName")] HRESULT GetMethodName([in]long lMethodNum,[in]long lMethodAlias,[in,out]BSTR *pbstrMethodName); 72 | [helpstring("method GetNParams")] HRESULT GetNParams([in]long lMethodNum,[in,out]long *plParams); 73 | [helpstring("method GetParamDefValue")] HRESULT GetParamDefValue([in]long lMethodNum,[in]long lParamNum,[in,out]VARIANT *pvarParamDefValue); 74 | [helpstring("method HasRetVal")] HRESULT HasRetVal([in]long lMethodNum,[in,out]BOOL *pboolRetValue); 75 | [helpstring("method CallAsProc")] HRESULT CallAsProc([in]long lMethodNum,[in,out] SAFEARRAY (VARIANT) *paParams); 76 | [helpstring("method CallAsFunc")] HRESULT CallAsFunc([in]long lMethodNum,[in,out] VARIANT *pvarRetValue,[in,out] SAFEARRAY (VARIANT) *paParams); 77 | }; 78 | 79 | [ 80 | object, 81 | uuid(ab634005-f13d-11d0-a459-004095e1daea), 82 | helpstring("IStatusLine Interface"), 83 | pointer_default(unique) 84 | ] 85 | interface IStatusLine : IUnknown 86 | { 87 | [helpstring("method SetStatusLine")] HRESULT SetStatusLine(BSTR bstrStatusLine); 88 | [helpstring("method ResetStatusLine")] HRESULT ResetStatusLine(); 89 | }; 90 | 91 | [ 92 | object, 93 | uuid(efe19ea0-09e4-11d2-a601-008048da00de), 94 | helpstring("IExtWndsSupport Interface"), 95 | pointer_default(unique) 96 | ] 97 | interface IExtWndsSupport : IUnknown 98 | { 99 | [helpstring("method GetAppMainFrame")] HRESULT GetAppMainFrame([in,out]HWND *hwnd); 100 | [helpstring("method GetAppMDIFrame")] HRESULT GetAppMDIFrame([in,out]HWND *hwnd); 101 | [helpstring("method CreateAddInWindow")] HRESULT CreateAddInWindow([in]BSTR bstrProgID, [in]BSTR bstrWindowName, [in]long dwStyles, [in]long dwExStyles, [in]RECT *rctl, [in]long Flags, [in,out]HWND *pHwnd, [in,out]IDispatch **pDisp); 102 | }; 103 | 104 | [ 105 | object, 106 | uuid(3C2136B5-B35A-4FAC-9AC3-F77F361E9467), 107 | helpstring("IMsgBox Interface"), 108 | pointer_default(unique) 109 | ] 110 | interface IMsgBox : IUnknown 111 | { 112 | [helpstring("method Confirm")] HRESULT Confirm([in]BSTR queryText, [out,retval]VARIANT *retVal); 113 | [helpstring("method Alert")] HRESULT Alert([in] BSTR text); 114 | 115 | }; 116 | typedef [v1_enum] enum _AppType { 117 | eAppUnknown = -1, 118 | eAppThinClient = 0, 119 | eAppThickClient, 120 | eAppWebClient, 121 | eAppServer, 122 | eAppExtConn, 123 | eAppMobileClient, 124 | eAppMobileServer, 125 | } AppType; 126 | typedef struct _AppInfo { 127 | BSTR AppVersion; 128 | BSTR UserAgentInformation; 129 | const AppType Application; 130 | } AppInfo; 131 | [ 132 | object, 133 | uuid(AAABE126-2230-4a7d-9DDA-8987FD2A62BA), 134 | helpstring("IPlatformInfo Interface"), 135 | pointer_default(unique) 136 | ] 137 | interface IPlatformInfo : IUnknown 138 | { 139 | [helpstring("method GetPlatformInfo")] HRESULT GetPlatformInfo([out]AppInfo** info); 140 | 141 | }; 142 | typedef [v1_enum] enum _AttachedType { 143 | eAttachedIsolated = 0, 144 | eAttachedNotIsolated, 145 | } AttachedType; 146 | [ 147 | object, 148 | uuid(6C269247-815E-42D9-9B17-5F17DF11B98F), 149 | helpstring("IAttachedInfo Interface"), 150 | pointer_default(unique) 151 | ] 152 | interface IAttachedInfo : IUnknown 153 | { 154 | [helpstring("method GetAttachedInfo")] HRESULT GetAttachedInfo([out]AttachedType* con_type); 155 | }; -------------------------------------------------------------------------------- /source/base_template/cpp/include/types.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __CON_TYPES_H__ 3 | #define __CON_TYPES_H__ 4 | 5 | #if defined(_WINDOWS) || defined(WINAPI_FAMILY) 6 | #include 7 | #endif 8 | 9 | #if defined(WINAPI_FAMILY) 10 | #include 11 | #endif 12 | 13 | #if __GNUC__ >=3 14 | #pragma GCC system_header 15 | #endif 16 | 17 | #include "com.h" 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #define EXTERN_C extern "C" 24 | 25 | #ifdef __GNUC__ 26 | #define _ANONYMOUS_UNION __extension__ 27 | #define _ANONYMOUS_STRUCT __extension__ 28 | #else 29 | #define _ANONYMOUS_UNION 30 | #define _ANONYMOUS_STRUCT 31 | #endif //__GNUC__ 32 | 33 | #ifdef NONAMELESSUNION 34 | #define __VARIANT_NAME_1 u 35 | #define __VARIANT_NAME_2 iface 36 | #define __VARIANT_NAME_3 str 37 | #define __VARIANT_NAME_4 wstr 38 | #else 39 | #define __VARIANT_NAME_1 40 | #define __VARIANT_NAME_2 41 | #define __VARIANT_NAME_3 42 | #define __VARIANT_NAME_4 43 | #endif //NONAMELESSUNION 44 | 45 | #define RESULT_FROM_ERRNO(x) ((long)(x) <= 0 ? ((long)(x)) \ 46 | : ((long) (((x) & 0x0000FFFF) | (BASE_ERRNO << 16) | 0x80000000))) 47 | 48 | #define ADDIN_E_NONE 1000 49 | #define ADDIN_E_ORDINARY 1001 50 | #define ADDIN_E_ATTENTION 1002 51 | #define ADDIN_E_IMPORTANT 1003 52 | #define ADDIN_E_VERY_IMPORTANT 1004 53 | #define ADDIN_E_INFO 1005 54 | #define ADDIN_E_FAIL 1006 55 | #define ADDIN_E_MSGBOX_ATTENTION 1007 56 | #define ADDIN_E_MSGBOX_INFO 1008 57 | #define ADDIN_E_MSGBOX_FAIL 1009 58 | 59 | #ifndef ADDIN_API 60 | #ifdef _WINDOWS 61 | #define ADDIN_API __stdcall 62 | #else 63 | //#define ADDIN_API __attribute__ ((__stdcall__)) 64 | #define ADDIN_API 65 | #endif //_WINDOWS 66 | #endif //ADDIN_API 67 | 68 | #include 69 | 70 | #ifdef _WINDOWS 71 | #define WCHAR_T char16_t 72 | #else 73 | #define WCHAR_T char16_t 74 | #endif //_WINDOWS 75 | typedef unsigned short TYPEVAR; 76 | enum ENUMVAR 77 | { 78 | VTYPE_EMPTY = 0, 79 | VTYPE_NULL, 80 | VTYPE_I2, //int16_t 81 | VTYPE_I4, //int32_t 82 | VTYPE_R4, //float 83 | VTYPE_R8, //double 84 | VTYPE_DATE, //DATE (double) 85 | VTYPE_TM, //struct tm 86 | VTYPE_PSTR, //struct str string 87 | VTYPE_INTERFACE, //struct iface 88 | VTYPE_ERROR, //int32_t errCode 89 | VTYPE_BOOL, //bool 90 | VTYPE_VARIANT, //struct _tVariant * 91 | VTYPE_I1, //int8_t 92 | VTYPE_UI1, //uint8_t 93 | VTYPE_UI2, //uint16_t 94 | VTYPE_UI4, //uint32_t 95 | VTYPE_I8, //int64_t 96 | VTYPE_UI8, //uint64_t 97 | VTYPE_INT, //int Depends on architecture 98 | VTYPE_UINT, //unsigned int Depends on architecture 99 | VTYPE_HRESULT, //long hRes 100 | VTYPE_PWSTR, //struct wstr 101 | VTYPE_BLOB, //means in struct str binary data contain 102 | VTYPE_CLSID, //UUID 103 | VTYPE_STR_BLOB = 0xfff, 104 | VTYPE_VECTOR = 0x1000, 105 | VTYPE_ARRAY = 0x2000, 106 | VTYPE_BYREF = 0x4000, //Only with struct _tVariant * 107 | VTYPE_RESERVED = 0x8000, 108 | VTYPE_ILLEGAL = 0xffff, 109 | VTYPE_ILLEGALMASKED = 0xfff, 110 | VTYPE_TYPEMASK = 0xfff 111 | } ; 112 | #if defined (__GNUC__) && !defined (NONAMELESSUNION) 113 | __extension__ /* no named members */ 114 | #endif 115 | struct _tVariant 116 | { 117 | _ANONYMOUS_UNION union 118 | { 119 | int8_t i8Val; 120 | int16_t shortVal; 121 | int32_t lVal; 122 | int intVal; 123 | unsigned int uintVal; 124 | int64_t llVal; 125 | uint8_t ui8Val; 126 | uint16_t ushortVal; 127 | uint32_t ulVal; 128 | uint64_t ullVal; 129 | int32_t errCode; 130 | long hRes; 131 | float fltVal; 132 | double dblVal; 133 | bool bVal; 134 | char chVal; 135 | wchar_t wchVal; 136 | DATE date; 137 | IID IDVal; 138 | struct _tVariant *pvarVal; 139 | struct tm tmVal; 140 | _ANONYMOUS_STRUCT struct 141 | { 142 | void* pInterfaceVal; 143 | IID InterfaceID; 144 | } __VARIANT_NAME_2/*iface*/; 145 | _ANONYMOUS_STRUCT struct 146 | { 147 | char* pstrVal; 148 | uint32_t strLen; //count of bytes 149 | } __VARIANT_NAME_3/*str*/; 150 | _ANONYMOUS_STRUCT struct 151 | { 152 | WCHAR_T* pwstrVal; 153 | uint32_t wstrLen; //count of symbol 154 | } __VARIANT_NAME_4/*wstr*/; 155 | } __VARIANT_NAME_1; 156 | uint32_t cbElements; //Dimension for an one-dimensional array in pvarVal 157 | TYPEVAR vt; 158 | }; 159 | typedef struct _tVariant tVariant; 160 | typedef tVariant tVariantArg; 161 | 162 | 163 | #if defined(NONAMELESSUNION) 164 | #define TV_JOIN(X, Y) ((X)->u.Y) 165 | #else 166 | #define TV_JOIN(X, Y) ((X)->Y) 167 | #endif 168 | 169 | #define TV_VT(X) ((X)->vt) 170 | #define TV_ISBYREF(X) (TV_VT(X)&VT_BYREF) 171 | #define TV_ISARRAY(X) (TV_VT(X)&VT_ARRAY) 172 | #define TV_ISVECTOR(X) (TV_VT(X)&VT_VECTOR) 173 | #define TV_NONE(X) TV_I2(X) 174 | 175 | #define TV_UI1(X) TV_JOIN(X, ui8Val) 176 | #define TV_I2(X) TV_JOIN(X, shortVal) 177 | #define TV_I4(X) TV_JOIN(X, lVal) 178 | #define TV_I8(X) TV_JOIN(X, llVal) 179 | #define TV_R4(X) TV_JOIN(X, fltVal) 180 | #define TV_R8(X) TV_JOIN(X, dblVal) 181 | #define TV_I1(X) TV_JOIN(X, i8Val) 182 | #define TV_UI2(X) TV_JOIN(X, ushortVal) 183 | #define TV_UI4(X) TV_JOIN(X, ulVal) 184 | #define TV_UI8(X) TV_JOIN(X, ullVal) 185 | #define TV_INT(X) TV_JOIN(X, intVal) 186 | #define TV_UINT(X) TV_JOIN(X, uintVal) 187 | 188 | #ifdef _WIN64 189 | #define TV_INT_PTR(X) TV_JOIN(X, llVal) 190 | #define TV_UINT_PTR(X) TV_JOIN(X, ullVal) 191 | #else 192 | #define TV_INT_PTR(X) TV_JOIN(X, lVal) 193 | #define TV_UINT_PTR(X) TV_JOIN(X, ulVal) 194 | #endif 195 | 196 | 197 | #define TV_DATE(X) TV_JOIN(X, date) 198 | #define TV_STR(X) TV_JOIN(X, pstrVal) 199 | #define TV_WSTR(X) TV_JOIN(X, pwstrVal) 200 | #define TV_BOOL(X) TV_JOIN(X, bVal) 201 | #define TV_UNKNOWN(X) TV_JOIN(X, pInterfaceVal) 202 | #define TV_VARIANTREF(X) TV_JOIN(X, pvarVal) 203 | 204 | void tVarInit(tVariant* tvar); 205 | 206 | inline 207 | void tVarInit(tVariant* tvar) 208 | { 209 | assert(tvar != NULL); 210 | memset(tvar, 0, sizeof(tVariant)); 211 | TV_VT(tvar) = VTYPE_EMPTY; 212 | } 213 | //----------------------------------------------------------------------------// 214 | // static setter functions... 215 | 216 | #define DATA_SET_BEGIN(data_) \ 217 | tVarInit(data_); 218 | 219 | #define DATA_SET_END(data_, type_) \ 220 | TV_VT(data_) = type_; 221 | 222 | 223 | #define DATA_SET(data_, type_, member_, value_) \ 224 | DATA_SET_BEGIN(data_) \ 225 | TV_JOIN(data_, member_) = value_; \ 226 | DATA_SET_END(data_, type_) 227 | 228 | #define DATA_SET_WITH_CAST(data_, type_, member_, cast_, value_) \ 229 | DATA_SET_BEGIN(data_) \ 230 | TV_JOIN(data_, member_) = cast_ value_; \ 231 | DATA_SET_END(data_, type_) 232 | 233 | #endif //__CON_TYPES_H__ 234 | -------------------------------------------------------------------------------- /app_tauri/src/components/FormOfMethods.tsx: -------------------------------------------------------------------------------- 1 | import { useEffect, useState } from "react"; 2 | import "../App.css"; 3 | import { 4 | ActionIcon, 5 | Button, 6 | Checkbox, 7 | Divider, 8 | Flex, 9 | Input, 10 | Modal, 11 | Select, 12 | Table, 13 | Tooltip, 14 | } from "@mantine/core"; 15 | import useStore, { Params } from "../store"; 16 | import IconAdd from "./IconAdd"; 17 | import IconTrash from "./IconTrash"; 18 | 19 | interface Props { 20 | open: boolean; 21 | toggleOpen: () => void; 22 | uuid?: string; 23 | isFunction: boolean; 24 | } 25 | 26 | export function useFormOfMethods() { 27 | const [open, setOpen] = useState(false); 28 | const [uuid, setUUID] = useState(""); 29 | 30 | function toggleOpen() { 31 | setOpen(!open); 32 | } 33 | 34 | function cb() { 35 | toggleOpen(); 36 | } 37 | 38 | return { open, toggleOpen, cb, setUUID, uuid }; 39 | } 40 | 41 | export default function FormOfMethods({ 42 | open, 43 | toggleOpen, 44 | uuid, 45 | isFunction, 46 | }: Props) { 47 | const [method, setMethod] = useState(""); 48 | const [methodEng, setMethodEng] = useState(""); 49 | const [params, setParams] = useState([]); 50 | const addMethod = useStore((state) => state.addMethod); 51 | const saveMethod = useStore((state) => state.saveMethod); 52 | const methods = useStore((state) => state.methods); 53 | const [returnType, setReturnType] = useState(""); 54 | const [hasReturn, setHasReturn] = useState(false); 55 | const [callRustMethod, setCallRustMethod] = useState(false); 56 | 57 | function onCancel() { 58 | toggleOpen(); 59 | } 60 | 61 | function onSave() { 62 | if (uuid) { 63 | saveMethod({ 64 | uuid: uuid, 65 | name: method, 66 | nameEng: methodEng, 67 | params: [...params], 68 | ReturnType: returnType, 69 | hasReturn: hasReturn, 70 | callRustMethod: callRustMethod, 71 | }); 72 | 73 | toggleOpen(); 74 | 75 | return; 76 | } 77 | 78 | addMethod({ 79 | uuid: crypto.randomUUID(), 80 | name: method, 81 | nameEng: methodEng, 82 | params: [...params], 83 | ReturnType: returnType, 84 | hasReturn: hasReturn, 85 | callRustMethod: callRustMethod, 86 | }); 87 | 88 | toggleOpen(); 89 | } 90 | 91 | useEffect(() => { 92 | setMethod( 93 | methods.find((method) => method.uuid === uuid)?.name || 94 | `method${methods.length + 1}` 95 | ); 96 | 97 | setMethodEng( 98 | methods.find((method) => method.uuid === uuid)?.nameEng || 99 | `methodEng${methods.length + 1}` 100 | ); 101 | 102 | setReturnType( 103 | methods.find((method) => method.uuid === uuid)?.ReturnType || "string" 104 | ); 105 | 106 | setParams(methods.find((method) => method.uuid === uuid)?.params || []); 107 | 108 | setHasReturn( 109 | methods.find((method) => method.uuid === uuid)?.hasReturn || isFunction 110 | ); 111 | 112 | if (uuid) { 113 | setCallRustMethod( 114 | methods.find((method) => method.uuid === uuid)?.callRustMethod || false 115 | ); 116 | } else { 117 | setCallRustMethod(true); 118 | } 119 | }, []); 120 | 121 | function onChangeType(selectedValue: string | null, uuid: string) { 122 | if (!selectedValue) return; 123 | setParams( 124 | params.map((item) => 125 | item.uuid === uuid ? { ...item, type: selectedValue } : item 126 | ) 127 | ); 128 | } 129 | 130 | function onChangeReturnType(selectedValue: string | null) { 131 | if (!selectedValue) return; 132 | setReturnType(selectedValue); 133 | } 134 | 135 | function addParam(): void { 136 | setParams([ 137 | ...params, 138 | { 139 | uuid: crypto.randomUUID(), 140 | name: `param${params.length + 1}`, 141 | type: "string", 142 | }, 143 | ]); 144 | } 145 | 146 | function setParamName(value: string, uuid: string) { 147 | setParams( 148 | params.map((item) => 149 | item.uuid === uuid ? { ...item, name: value } : item 150 | ) 151 | ); 152 | } 153 | 154 | function DeleteParam(uuid: string): void { 155 | setParams(params.filter((param) => param.uuid !== uuid)); 156 | } 157 | 158 | return ( 159 | 166 | 167 | 168 | 169 | setMethod(e.target.value)} 172 | variant="filled" 173 | /> 174 | 175 | 176 | 177 | setMethodEng(e.target.value)} 180 | variant="filled" 181 | /> 182 | 183 | 184 | setCallRustMethod(e.target.checked)} 187 | label="Вызов Rust метода (FFI)" 188 | mt={10} 189 | /> 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | Имя 203 | Тип 204 | 205 | 206 | 207 | 208 | {params.map((i) => ( 209 | 210 | 211 | setParamName(e.target.value, i.uuid)} 215 | /> 216 | 217 | 218 | 225 | 226 | 227 | 228 | { 233 | DeleteParam(i.uuid); 234 | }} 235 | > 236 | 237 | 238 | 239 | 240 | 241 | ))} 242 | 243 |
244 | 245 | setHasReturn(e.target.checked)} 248 | label="Возвращает значение" 249 | mt={10} 250 | /> 251 | 252 | {hasReturn && ( 253 | 254 | 261 | 262 | )} 263 | 264 | 265 | 266 | 267 | 268 |
269 |
270 | ); 271 | } 272 | -------------------------------------------------------------------------------- /source/base_template/cpp/source/AddInNative.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "stdafx.h" 3 | 4 | 5 | #if defined( __linux__ ) || defined(__APPLE__) 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #endif 12 | 13 | #include 14 | #include "AddInNative.h" 15 | #include 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | #include "../lib/common.h" 23 | 24 | #include "impl/test.h" 25 | //includeВставкаЗаголовковМетодов 26 | 27 | 28 | static wchar_t* g_PropNames[] = { L"TestProp" }; 29 | static wchar_t* g_PropNamesRu[] = { L"ТестовоеСвойство" }; 30 | 31 | static wchar_t* g_MethodNamesRu[] = { 32 | L"Тест", 33 | /*ФайлCPPМетодыНаРусскомЯзыке*/}; 34 | 35 | static wchar_t* g_MethodNames[] = { 36 | L"Test", 37 | /*ФайлCPPМетодыНаАнглийскомЯзыке*/ }; 38 | 39 | static const WCHAR_T g_kClassNames[] = u"CAddInNative"; //|OtherClass1|OtherClass2"; 40 | 41 | uint32_t convToShortWchar(WCHAR_T** Dest, const wchar_t* Source, size_t len = 0); 42 | uint32_t convFromShortWchar(wchar_t** Dest, const WCHAR_T* Source, uint32_t len = 0); 43 | uint32_t getLenShortWcharStr(const WCHAR_T* Source); 44 | static AppCapabilities g_capabilities = eAppCapabilitiesInvalid; 45 | static std::u16string s_names(g_kClassNames); 46 | 47 | 48 | 49 | //---------------------------------------------------------------------------// 50 | long GetClassObject(const WCHAR_T* wsName, IComponentBase** pInterface) 51 | { 52 | if (!*pInterface) 53 | { 54 | *pInterface = new CAddInNative(); 55 | return (long)*pInterface; 56 | } 57 | return 0; 58 | } 59 | //---------------------------------------------------------------------------// 60 | AppCapabilities SetPlatformCapabilities(const AppCapabilities capabilities) 61 | { 62 | g_capabilities = capabilities; 63 | return eAppCapabilitiesLast; 64 | } 65 | //---------------------------------------------------------------------------// 66 | AttachType GetAttachType() 67 | { 68 | return eCanAttachAny; 69 | } 70 | //---------------------------------------------------------------------------// 71 | long DestroyObject(IComponentBase** pIntf) 72 | { 73 | if (!*pIntf) 74 | return -1; 75 | 76 | delete* pIntf; 77 | *pIntf = 0; 78 | return 0; 79 | } 80 | //---------------------------------------------------------------------------// 81 | const WCHAR_T* GetClassNames() 82 | { 83 | return s_names.c_str(); 84 | } 85 | //---------------------------------------------------------------------------// 86 | //CAddInNative 87 | CAddInNative::CAddInNative() 88 | { 89 | } 90 | //---------------------------------------------------------------------------// 91 | CAddInNative::~CAddInNative() 92 | { 93 | } 94 | //---------------------------------------------------------------------------// 95 | bool CAddInNative::Init(void* pConnection) 96 | { 97 | m_iConnect = (IAddInDefBase*)pConnection; 98 | return m_iConnect != NULL; 99 | } 100 | //---------------------------------------------------------------------------// 101 | long CAddInNative::GetInfo() 102 | { 103 | return 2000; 104 | } 105 | //---------------------------------------------------------------------------// 106 | void CAddInNative::Done() 107 | { 108 | } 109 | ///////////////////////////////////////////////////////////////////////////// 110 | // ILanguageExtenderBase 111 | //---------------------------------------------------------------------------// 112 | bool CAddInNative::RegisterExtensionAs(WCHAR_T** wsExtensionName) 113 | { 114 | 115 | wchar_t* wsExtension = L"My"; 116 | int iActualSize = ::wcslen(wsExtension) + 1; 117 | 118 | if (m_iMemory) 119 | { 120 | if (m_iMemory->AllocMemory((void**)wsExtensionName, iActualSize * sizeof(WCHAR_T))) 121 | ::convToShortWchar(wsExtensionName, wsExtension, iActualSize); 122 | return true; 123 | } 124 | 125 | return false; 126 | } 127 | //---------------------------------------------------------------------------// 128 | bool CAddInNative::setMemManager(void* mem) 129 | { 130 | m_iMemory = (IMemoryManager*)mem; 131 | return m_iMemory != 0; 132 | } 133 | //---------------------------------------------------------------------------// 134 | long CAddInNative::GetNProps() 135 | { 136 | return eLastProp; 137 | } 138 | //---------------------------------------------------------------------------// 139 | long CAddInNative::FindProp(const WCHAR_T* wsPropName) 140 | { 141 | long plPropNum = -1; 142 | wchar_t* propName = 0; 143 | 144 | ::convFromShortWchar(&propName, wsPropName); 145 | plPropNum = findName(g_PropNames, propName, eLastProp); 146 | 147 | if (plPropNum == -1) 148 | plPropNum = findName(g_PropNamesRu, propName, eLastProp); 149 | 150 | delete[] propName; 151 | 152 | return plPropNum; 153 | } 154 | //---------------------------------------------------------------------------// 155 | const WCHAR_T* CAddInNative::GetPropName(long lPropNum, long lPropAlias) 156 | { 157 | if (lPropNum >= eLastProp) 158 | return NULL; 159 | 160 | wchar_t* wsCurrentName = NULL; 161 | WCHAR_T* wsPropName = NULL; 162 | size_t iActualSize = 0; 163 | 164 | switch (lPropAlias) 165 | { 166 | case 0: // First language 167 | wsCurrentName = (wchar_t*)g_PropNames[lPropNum]; 168 | break; 169 | case 1: // Second language 170 | wsCurrentName = (wchar_t*)g_PropNamesRu[lPropNum]; 171 | break; 172 | default: 173 | return 0; 174 | } 175 | 176 | iActualSize = wcslen(wsCurrentName) + 1; 177 | 178 | if (m_iMemory && wsCurrentName) 179 | { 180 | if (m_iMemory->AllocMemory((void**)&wsPropName, (unsigned)iActualSize * sizeof(WCHAR_T))) 181 | ::convToShortWchar(&wsPropName, wsCurrentName, iActualSize); 182 | } 183 | 184 | return wsPropName; 185 | } 186 | //---------------------------------------------------------------------------// 187 | bool CAddInNative::GetPropVal(const long lPropNum, tVariant* pvarPropVal) 188 | { 189 | switch (lPropNum) 190 | { 191 | case TestProp: 192 | { 193 | if (m_iMemory) 194 | { 195 | TV_VT(pvarPropVal) = VTYPE_PWSTR; 196 | auto iActualSize = ::wcslen(pTestProp); 197 | 198 | if (m_iMemory->AllocMemory((void**)&(pvarPropVal->pwstrVal), iActualSize * sizeof(WCHAR_T))) 199 | { 200 | ::convToShortWchar(&(pvarPropVal->pwstrVal), pTestProp, iActualSize); 201 | pvarPropVal->wstrLen = iActualSize; 202 | } 203 | 204 | } 205 | else 206 | TV_VT(pvarPropVal) = VTYPE_EMPTY; 207 | } 208 | break; 209 | default: 210 | return false; 211 | } 212 | 213 | return true; 214 | } 215 | //---------------------------------------------------------------------------// 216 | bool CAddInNative::SetPropVal(const long lPropNum, tVariant* varPropVal) 217 | { 218 | switch (lPropNum) 219 | { 220 | case TestProp: 221 | ::convFromShortWchar(&pTestProp, TV_WSTR(varPropVal)); 222 | break; 223 | default: 224 | return false; 225 | } 226 | 227 | return true; 228 | } 229 | //---------------------------------------------------------------------------// 230 | bool CAddInNative::IsPropReadable(const long lPropNum) 231 | { 232 | switch (lPropNum) 233 | { 234 | case TestProp: 235 | return true; 236 | default: 237 | return false; 238 | } 239 | 240 | return false; 241 | } 242 | //---------------------------------------------------------------------------// 243 | bool CAddInNative::IsPropWritable(const long lPropNum) 244 | { 245 | switch (lPropNum) 246 | { 247 | case TestProp: 248 | return true; 249 | default: 250 | return false; 251 | } 252 | 253 | return false; 254 | } 255 | //---------------------------------------------------------------------------// 256 | long CAddInNative::GetNMethods() 257 | { 258 | return eLastMethod; 259 | } 260 | //---------------------------------------------------------------------------// 261 | long CAddInNative::FindMethod(const WCHAR_T* wsMethodName) 262 | { 263 | long plMethodNum = -1; 264 | wchar_t* name = 0; 265 | 266 | ::convFromShortWchar(&name, wsMethodName); 267 | 268 | plMethodNum = findName(g_MethodNames, name, eLastMethod); 269 | 270 | if (plMethodNum == -1) 271 | plMethodNum = findName(g_MethodNamesRu, name, eLastMethod); 272 | 273 | return plMethodNum; 274 | } 275 | //---------------------------------------------------------------------------// 276 | const WCHAR_T* CAddInNative::GetMethodName(const long lMethodNum, const long lMethodAlias) 277 | { 278 | if (lMethodNum >= eLastMethod) 279 | return NULL; 280 | 281 | wchar_t* wsCurrentName = NULL; 282 | WCHAR_T* wsMethodName = NULL; 283 | int iActualSize = 0; 284 | 285 | switch (lMethodAlias) 286 | { 287 | case 0: // First language 288 | wsCurrentName = g_MethodNames[lMethodNum]; 289 | break; 290 | case 1: // Second language 291 | wsCurrentName = g_MethodNamesRu[lMethodNum]; 292 | break; 293 | default: 294 | return 0; 295 | } 296 | 297 | iActualSize = wcslen(wsCurrentName) + 1; 298 | 299 | if (m_iMemory && wsCurrentName) 300 | { 301 | if (m_iMemory->AllocMemory((void**)&wsMethodName, iActualSize * sizeof(WCHAR_T))) 302 | ::convToShortWchar(&wsMethodName, wsCurrentName, iActualSize); 303 | } 304 | 305 | return wsMethodName; 306 | } 307 | //---------------------------------------------------------------------------// 308 | long CAddInNative::GetNParams(const long lMethodNum) 309 | { 310 | switch (lMethodNum) 311 | { 312 | case Test: 313 | { 314 | return 3; 315 | } 316 | //GetNParamsДляВставки 317 | default: 318 | return 0; 319 | } 320 | 321 | return 0; 322 | } 323 | //---------------------------------------------------------------------------// 324 | bool CAddInNative::GetParamDefValue(const long lMethodNum, const long lParamNum, 325 | tVariant *pvarParamDefValue) 326 | { 327 | return false; 328 | } 329 | //---------------------------------------------------------------------------// 330 | bool CAddInNative::HasRetVal(const long lMethodNum) 331 | { 332 | switch (lMethodNum) 333 | { 334 | case Test: 335 | return true; 336 | //HasRetValДляВставки 337 | default: 338 | return false; 339 | } 340 | 341 | return false; 342 | } 343 | //---------------------------------------------------------------------------// 344 | bool CAddInNative::CallAsProc(const long lMethodNum, 345 | tVariant* paParams, const long lSizeArray) 346 | { 347 | return true; 348 | } 349 | //---------------------------------------------------------------------------// 350 | bool CAddInNative::CallAsFunc(const long lMethodNum, tVariant* pvarRetValue, tVariant* paParams, const long lSizeArray) 351 | { 352 | 353 | switch (lMethodNum) 354 | { 355 | case Test: 356 | return test(lMethodNum, pvarRetValue, paParams, lSizeArray, m_iMemory); 357 | //CallAsFuncДляВставки 358 | default: 359 | return false; 360 | } 361 | 362 | return false; 363 | } 364 | 365 | //---------------------------------------------------------------------------// 366 | void CAddInNative::SetLocale(const WCHAR_T* loc) 367 | { 368 | } 369 | //---------------------------------------------------------------------------// 370 | void ADDIN_API CAddInNative::SetUserInterfaceLanguageCode(const WCHAR_T * lang) 371 | { 372 | } 373 | 374 | //---------------------------------------------------------------------------// 375 | uint32_t convToShortWchar(WCHAR_T** Dest, const wchar_t* Source, size_t len) 376 | { 377 | if (!len) 378 | len = ::wcslen(Source) + 1; 379 | 380 | if (!*Dest) 381 | *Dest = new WCHAR_T[len]; 382 | 383 | WCHAR_T* tmpShort = *Dest; 384 | wchar_t* tmpWChar = (wchar_t*)Source; 385 | uint32_t res = 0; 386 | 387 | ::memset(*Dest, 0, len * sizeof(WCHAR_T)); 388 | #ifdef __linux__ 389 | size_t succeed = (size_t)-1; 390 | size_t f = len * sizeof(wchar_t), t = len * sizeof(WCHAR_T); 391 | const char* fromCode = sizeof(wchar_t) == 2 ? "UTF-16" : "UTF-32"; 392 | iconv_t cd = iconv_open("UTF-16LE", fromCode); 393 | if (cd != (iconv_t)-1) 394 | { 395 | succeed = iconv(cd, (char**)&tmpWChar, &f, (char**)&tmpShort, &t); 396 | iconv_close(cd); 397 | if (succeed != (size_t)-1) 398 | return (uint32_t)succeed; 399 | } 400 | #endif //__linux__ 401 | for (; len; --len, ++res, ++tmpWChar, ++tmpShort) 402 | { 403 | *tmpShort = (WCHAR_T)*tmpWChar; 404 | } 405 | 406 | return res; 407 | } 408 | //---------------------------------------------------------------------------// 409 | uint32_t convFromShortWchar(wchar_t** Dest, const WCHAR_T* Source, uint32_t len) 410 | { 411 | if (!len) 412 | len = getLenShortWcharStr(Source) + 1; 413 | 414 | if (!*Dest) 415 | *Dest = new wchar_t[len]; 416 | 417 | wchar_t* tmpWChar = *Dest; 418 | WCHAR_T* tmpShort = (WCHAR_T*)Source; 419 | uint32_t res = 0; 420 | 421 | ::memset(*Dest, 0, len * sizeof(wchar_t)); 422 | #if defined( __linux__ ) || defined(__APPLE__) 423 | size_t succeed = (size_t)-1; 424 | const char* fromCode = sizeof(wchar_t) == 2 ? "UTF-16" : "UTF-32"; 425 | size_t f = len * sizeof(WCHAR_T), t = len * sizeof(wchar_t); 426 | iconv_t cd = iconv_open("UTF-32LE", fromCode); 427 | if (cd != (iconv_t)-1) 428 | { 429 | succeed = iconv(cd, (char**)&tmpShort, &f, (char**)&tmpWChar, &t); 430 | iconv_close(cd); 431 | if(succeed != (size_t)-1) 432 | return (uint32_t)succeed; 433 | } 434 | #endif 435 | for (; len; --len, ++res, ++tmpWChar, ++tmpShort) 436 | { 437 | *tmpWChar = (wchar_t)*tmpShort; 438 | } 439 | 440 | return res; 441 | } 442 | //---------------------------------------------------------------------------// 443 | uint32_t getLenShortWcharStr(const WCHAR_T* Source) 444 | { 445 | uint32_t res = 0; 446 | WCHAR_T *tmpShort = (WCHAR_T*)Source; 447 | 448 | while (*tmpShort++) 449 | ++res; 450 | 451 | return res; 452 | } 453 | //---------------------------------------------------------------------------// 454 | 455 | 456 | long CAddInNative::findName(wchar_t* names[], const wchar_t* name, 457 | const uint32_t size) const 458 | { 459 | long ret = -1; 460 | for (uint32_t i = 0; i < size; i++) 461 | { 462 | if (!wcscmp(names[i], name)) 463 | { 464 | ret = i; 465 | break; 466 | } 467 | } 468 | return ret; 469 | } 470 | 471 | //---------------------------------------------------------------------------// 472 | 473 | -------------------------------------------------------------------------------- /app_tauri/src-tauri/src/lib.rs: -------------------------------------------------------------------------------- 1 | mod dto; 2 | mod file_op; 3 | use dto::{Method, State}; 4 | use file_op::{copy_directory, replace_text_in_file, replace_text_in_file_regex, exists_base_template}; 5 | use std::{env, fs, io, vec}; 6 | use tauri::http::method; 7 | 8 | fn copy_base_template(source_dir: &str, destination_dir: &str) -> io::Result<()> { 9 | println!( 10 | "Copying directory '{}' to '{}'...", 11 | source_dir, destination_dir 12 | ); 13 | 14 | copy_directory(source_dir.to_string(), destination_dir.to_string())?; 15 | 16 | Ok(()) 17 | } 18 | 19 | fn replace_in_class(dist: &String, state: &State) -> io::Result<()> { 20 | let file_path = dist.to_owned() + "\\cpp\\source\\AddInNative.h"; 21 | let target_text = "//ДляВставкиМетодов"; 22 | 23 | let methods_string = state 24 | .methods 25 | .iter() 26 | .map(|method| format!("{}_enum", method.name_eng.as_str())) 27 | .collect::>() 28 | .join(",\n\t\t") 29 | + ","; 30 | 31 | replace_text_in_file(&file_path, target_text.to_string(), methods_string)?; 32 | 33 | Ok(()) 34 | } 35 | 36 | fn replace_in_make_file(dist: &String, state: &State) -> io::Result<()> { 37 | let file_path = dist.to_owned() + "\\cpp\\source\\CMakeLists.txt"; 38 | let target_text = "#ВставкаCPPФайлов"; 39 | 40 | let cpp_files_string = state 41 | .methods 42 | .iter() 43 | .map(|method| "impl/".to_owned() + method.name_eng.as_str() + ".cpp") 44 | .collect::>() 45 | .join("\n\t"); 46 | 47 | replace_text_in_file(&file_path, target_text.to_string(), cpp_files_string)?; 48 | 49 | Ok(()) 50 | } 51 | 52 | fn replace_in_main_cpp(dist: &String, state: &State) -> io::Result<()> { 53 | let file_path = dist.to_owned() + "\\cpp\\source\\AddInNative.cpp"; 54 | let target_text = "/*ФайлCPPМетодыНаРусскомЯзыке*/"; 55 | 56 | let methods_string = state 57 | .methods 58 | .iter() 59 | .map(|method| format!("L\"{}\"", method.name.as_str())) 60 | .collect::>() 61 | .join(",\n\t") 62 | + ",\n"; 63 | 64 | replace_text_in_file(&file_path, target_text.to_string(), methods_string)?; 65 | 66 | let file_path = dist.to_owned() + "\\cpp\\source\\AddInNative.cpp"; 67 | let target_text = "/*ФайлCPPМетодыНаАнглийскомЯзыке*/"; 68 | 69 | let methods_string = state 70 | .methods 71 | .iter() 72 | .map(|method| format!("L\"{}\"", method.name_eng.as_str())) 73 | .collect::>() 74 | .join(",\n\t") 75 | + ",\n"; 76 | 77 | replace_text_in_file(&file_path, target_text.to_string(), methods_string)?; 78 | 79 | let target_text = "//GetNParamsДляВставки"; 80 | 81 | let methods_string = state 82 | .methods 83 | .iter() 84 | .map(|method| { 85 | format!( 86 | "case {}: return {};", 87 | format!("{}_enum", method.name_eng.as_str()), 88 | method.params.len() 89 | ) 90 | }) 91 | .collect::>() 92 | .join("\n\t"); 93 | 94 | replace_text_in_file(&file_path, target_text.to_string(), methods_string)?; 95 | 96 | let target_text = "//HasRetValДляВставки"; 97 | 98 | let methods_string = state 99 | .methods 100 | .iter() 101 | .map(|method| { 102 | format!( 103 | "case {}: return {};", 104 | format!("{}_enum", method.name_eng.as_str()), 105 | method.has_return 106 | ) 107 | }) 108 | .collect::>() 109 | .join("\n\t"); 110 | 111 | replace_text_in_file(&file_path, target_text.to_string(), methods_string)?; 112 | 113 | let target_text = "//CallAsFuncДляВставки"; 114 | 115 | let methods_string = state 116 | .methods 117 | .iter() 118 | .map(|method| { 119 | format!( 120 | "case {}: return {}(lMethodNum, pvarRetValue, paParams, lSizeArray, m_iMemory);", 121 | format!("{}_enum", method.name_eng.as_str()), 122 | method.name_eng.as_str() 123 | ) 124 | }) 125 | .collect::>() 126 | .join("\n\t"); 127 | 128 | replace_text_in_file(&file_path, target_text.to_string(), methods_string)?; 129 | 130 | let target_text = "//includeВставкаЗаголовковМетодов"; 131 | 132 | let methods_string = state 133 | .methods 134 | .iter() 135 | .map(|method| format!("#include \"impl/{}.h\"", method.name_eng.as_str())) 136 | .collect::>() 137 | .join("\n"); 138 | 139 | replace_text_in_file(&file_path, target_text.to_string(), methods_string)?; 140 | 141 | Ok(()) 142 | } 143 | 144 | fn fill_params_methods(file_path: &String, state: &State, method: &Method) -> io::Result<()> { 145 | let mut get_params: Vec = vec![]; 146 | 147 | method.params.iter().enumerate().for_each(|(index, param)| { 148 | if param._type == "string" { 149 | get_params.push( 150 | format!( 151 | "std::string {} = get_method_param_as_utf8(paParams, {});", 152 | param.name, index 153 | ) 154 | .to_string(), 155 | ); 156 | } 157 | if param._type == "number" { 158 | get_params.push( 159 | format!( 160 | "float {} = get_method_param_as_number(paParams, {});", 161 | param.name, index 162 | ) 163 | .to_string(), 164 | ); 165 | } 166 | if param._type == "bool" { 167 | get_params.push( 168 | format!( 169 | "bool {} = get_method_param_as_bool(paParams, {});", 170 | param.name, index 171 | ) 172 | .to_string(), 173 | ); 174 | } 175 | }); 176 | 177 | let replace_str = get_params.join("\n\t"); 178 | replace_text_in_file( 179 | file_path, 180 | "//ВставкаКодаПолученияПараметровМетода".to_string(), 181 | replace_str, 182 | )?; 183 | 184 | replace_text_in_file_regex(file_path, r"//\+\+\+НачалоПримера[\S\s\n]*?//---", "")?; 185 | 186 | if !method.call_rust_method { 187 | replace_text_in_file( 188 | file_path, 189 | "free_mem_after_cpp(res);//Освободить память выделенные в Rust, когда она больше не нужна на стороне cpp".to_string(), 190 | "".to_string(), 191 | )?; 192 | 193 | replace_text_in_file_regex( 194 | file_path, 195 | r"//\+\+\+Вызов метода Rust[\S\s\n]*?//---", 196 | "set_return_val_for_1c_as_utf16(pvarRetValue, u\"returned value\", m_iMemory);", 197 | )?; 198 | } 199 | 200 | if method.call_rust_method { 201 | let mut rust_params: Vec = vec![]; 202 | 203 | method.params.iter().for_each(|param| { 204 | if param._type == "string" { 205 | rust_params.push(param.name.to_string() + ".c_str()"); 206 | } else { 207 | rust_params.push(param.name.to_string()); 208 | } 209 | }); 210 | 211 | replace_text_in_file( 212 | &file_path, 213 | "const char* res = test__call_from_cpp(parm_for_rust.c_str(), f, b);".to_string(), 214 | format!( 215 | "const char* res = {}__call_from_cpp({});", 216 | method.name_eng.as_str(), 217 | rust_params.join(", ").to_string() 218 | ), 219 | )?; 220 | } 221 | 222 | Ok(()) 223 | } 224 | 225 | fn fill_for_rust_header(file_path: &String, state: &State) -> io::Result<()> { 226 | let mut methods: Vec = vec![]; 227 | 228 | state.methods.iter().for_each(|method| { 229 | let mut params: Vec = vec![]; 230 | 231 | method.params.iter().for_each(|param| { 232 | if param._type == "string" { 233 | params.push(format!("const char* {}", param.name).to_string()); 234 | } 235 | if param._type == "number" { 236 | params.push(format!("float {}", param.name).to_string()); 237 | } 238 | if param._type == "bool" { 239 | params.push(format!("bool {}", param.name).to_string()); 240 | } 241 | }); 242 | 243 | let cur_method = format!( 244 | "extern \"C\" const char* {}__call_from_cpp({});", 245 | method.name_eng.as_str(), 246 | params.join(", ") 247 | ); 248 | 249 | methods.push(cur_method.clone()); 250 | }); 251 | 252 | replace_text_in_file( 253 | file_path, 254 | "//ВставкаМетодов".to_string(), 255 | methods.join("\n").to_string(), 256 | )?; 257 | 258 | Ok(()) 259 | } 260 | 261 | fn copy_cpp_files_for_each_method(dist: &String, state: &State) -> io::Result<()> { 262 | state.methods.iter().try_for_each(|method| { 263 | let source = dist.to_owned() + "\\cpp\\source\\impl\\test.cpp"; 264 | let dist = dist.to_owned() + "\\cpp\\source\\impl\\" + method.name_eng.as_str() + ".cpp"; 265 | println!("Copying file '{}' to '{}'...", source, dist); 266 | fs::copy(source, &dist)?; 267 | let method_name = method.name_eng.as_str().to_owned() + "("; 268 | replace_text_in_file( 269 | &dist.to_string(), 270 | "test(".to_string(), 271 | method_name.to_string(), 272 | )?; 273 | fill_params_methods(&dist.to_string(), &state, method)?; 274 | Ok::<(), io::Error>(()) 275 | })?; 276 | 277 | state.methods.iter().try_for_each(|method| { 278 | let source = dist.to_owned() + "\\cpp\\source\\impl\\test.h"; 279 | let dist = dist.to_owned() + "\\cpp\\source\\impl\\" + method.name_eng.as_str() + ".h"; 280 | println!("Copying file '{}' to '{}'...", source, dist); 281 | fs::copy(source, &dist)?; 282 | let method_name = method.name_eng.as_str().to_owned() + "("; 283 | replace_text_in_file( 284 | &dist.to_string(), 285 | "test(".to_string(), 286 | method_name.to_string(), 287 | )?; 288 | Ok::<(), io::Error>(()) 289 | })?; 290 | 291 | let source = dist.to_owned() + "\\cpp\\source\\impl\\rust.h"; 292 | fill_for_rust_header(&source, &state)?; 293 | 294 | Ok(()) 295 | } 296 | 297 | fn copy_rs_files_for_each_method(dist: &String, state: &State) -> io::Result<()> { 298 | state 299 | .methods 300 | .iter() 301 | .filter(|method| method.call_rust_method) 302 | .try_for_each(|method| { 303 | let source = format!("{}\\rust\\src\\impl_test.rs", dist); 304 | println!("1_{}", source); 305 | let dist = format!("{}\\rust\\src\\impl_{}.rs", dist, method.name_eng); 306 | println!("Copying file '{}' to '{}'...", source, dist); 307 | fs::copy(source, &dist)?; 308 | let method_name = method.name_eng.as_str().to_owned() + "("; 309 | replace_text_in_file( 310 | &dist.to_string(), 311 | "test(".to_string(), 312 | method_name.to_string(), 313 | )?; 314 | 315 | let mut params: Vec = vec![]; 316 | 317 | method.params.iter().for_each(|param| { 318 | if param._type == "string" { 319 | params.push(format!("{}: *const c_char", param.name)); 320 | } 321 | if param._type == "number" { 322 | params.push(format!("{}: f32", param.name)); 323 | } 324 | if param._type == "bool" { 325 | params.push(format!("{}: bool", param.name)); 326 | } 327 | }); 328 | let new_text = format!( 329 | r#"pub extern "C" fn main({}) -> *const c_char {{ 330 | str_to_cchar("returned value from rust") 331 | }}"#, 332 | params.join(", ") 333 | ); 334 | replace_text_in_file_regex(&dist, r"//\+\+\+Заменить[\S\s\n]*?//---", &new_text)?; 335 | 336 | Ok::<(), io::Error>(()) 337 | })?; 338 | 339 | // заменить в lib.rs 340 | let mut mods: Vec = vec![]; 341 | 342 | state 343 | .methods 344 | .iter() 345 | .filter(|method| method.call_rust_method) 346 | .for_each(|method| { 347 | mods.push(format!("mod impl_{};", method.name_eng)); 348 | }); 349 | 350 | let file_path = format!("{}\\rust\\src\\lib.rs", dist); 351 | replace_text_in_file(&file_path, "//ВставкаМодулей".to_string(), mods.join("\n"))?; 352 | 353 | //ВставкаМетодов 354 | 355 | let mut methods: Vec = vec![]; 356 | 357 | state 358 | .methods 359 | .iter() 360 | .filter(|method| method.call_rust_method) 361 | .for_each(|method| { 362 | let mut params: Vec = vec![]; 363 | let mut params_without_types: Vec = vec![]; 364 | method.params.iter().for_each(|param| { 365 | params_without_types.push(param.name.to_string()); 366 | if param._type == "string" { 367 | params.push(format!("{}: *const c_char", param.name)); 368 | } 369 | if param._type == "number" { 370 | params.push(format!("{}: f32", param.name)); 371 | } 372 | if param._type == "bool" { 373 | params.push(format!("{}: bool", param.name)); 374 | } 375 | }); 376 | 377 | let code = format!( 378 | r###"#[no_mangle] 379 | pub extern "C" fn {}__call_from_cpp({}) -> *const c_char {{ 380 | impl_{}::main({}) 381 | }}"###, 382 | method.name_eng, 383 | params.join(", "), 384 | method.name_eng, 385 | params_without_types.join(", "), 386 | ); 387 | methods.push(code); 388 | }); 389 | 390 | let file_path = format!("{}\\rust\\src\\lib.rs", dist); 391 | replace_text_in_file(&file_path, "//ВставкаМетодов".to_string(), methods.join("\n"))?; 392 | 393 | Ok(()) 394 | } 395 | 396 | fn copy_file_and_replace(path: String, state: State) -> io::Result<()> { 397 | let source = path.to_owned() + "\\base_template"; 398 | let dist = path.to_owned() + "\\new_component"; 399 | 400 | copy_base_template(source.as_str(), dist.as_str())?; 401 | 402 | replace_in_class(&dist, &state)?; 403 | 404 | replace_in_main_cpp(&dist, &state)?; 405 | 406 | copy_cpp_files_for_each_method(&dist, &state)?; 407 | 408 | copy_rs_files_for_each_method(&dist, &state)?; 409 | 410 | replace_in_make_file(&dist, &state)?; 411 | 412 | Ok(()) 413 | } 414 | 415 | // Learn more about Tauri commands at https://tauri.app/develop/calling-rust/ 416 | #[tauri::command] 417 | fn build(path: &str, state: &str) -> String { 418 | println!("state {}", state); 419 | 420 | let state_struct = match serde_json::from_str::(state) { 421 | Ok(state) => state, 422 | Err(e) => { 423 | println!("error {}", e); 424 | return e.to_string(); 425 | } 426 | }; 427 | 428 | let source = path.to_owned() + "\\base_template"; 429 | if !exists_base_template(source.to_string()){ 430 | return "В каталоге с конструтором должен находится каталог base_template. Это базой шаблон. Он не найден. Скопируйте его в этот каталог из релиза или из папки source в репозитории.".to_string(); 431 | } 432 | 433 | match copy_file_and_replace(path.to_string(), state_struct) { 434 | Ok(()) => "Завершилось успешно!".to_string(), 435 | Err(e) => e.to_string(), 436 | } 437 | } 438 | 439 | #[tauri::command] 440 | fn current_dir() -> String { 441 | 442 | match env::current_dir() { 443 | Ok(path) => path.display().to_string(), 444 | Err(e) => e.to_string(), 445 | } 446 | 447 | } 448 | 449 | #[cfg_attr(mobile, tauri::mobile_entry_point)] 450 | pub fn run() { 451 | tauri::Builder::default() 452 | .plugin(tauri_plugin_shell::init()) 453 | .invoke_handler(tauri::generate_handler![build,current_dir]) 454 | .run(tauri::generate_context!()) 455 | .expect("error while running tauri application"); 456 | } --------------------------------------------------------------------------------