public static void defaultConfigClick(object sender, EventArgs e) { if (MessageBox.Show(ResourceCulture.GetString("FormInfo_RemindMessageText"), ResourceCulture.GetString("FormInfo_remindText"), MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { try { IntPtr coTaskMemAuto = Marshal.StringToCoTaskMemAuto(Application.StartupPath + "\\res\\config_default.xml"); Marshal.AllocHGlobal(Marshal.SizeOf(typeof(HNStruct.HNConfigXML))); IntPtr num1 = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(HNStruct.HNTabletInfo))); Marshal.StructureToPtr((object)HNStruct.globalInfo.tabletInfo, num1, false); IntPtr num2 = HuionDriverDLL.hnx_read_config(ref HNStruct.globalInfo.tabletInfo, coTaskMemAuto); TabletConfigUtils.config = (HNStruct.HNConfigXML)Marshal.PtrToStructure(num2, typeof(HNStruct.HNConfigXML)); new TabletConfigUtils().SetConfig(TabletConfigUtils.config); Marshal.FreeHGlobal(coTaskMemAuto); Marshal.FreeHGlobal(num1); HuionDriverDLL.hnx_free_PHNConfig(num2); } catch (Exception ex) { HuionLog.saveLog("默认配置", ex.Message); } } }
public bool AddUSBEventWatcher(EventArrivedEventHandler usbInsertHandler, EventArrivedEventHandler usbRemoveHandler, TimeSpan withinInterval) { try { ManagementScope scope = new ManagementScope("root\\CIMV2"); scope.Options.EnablePrivileges = true; if (usbInsertHandler != null) { WqlEventQuery wqlEventQuery = new WqlEventQuery("__InstanceCreationEvent", withinInterval, "TargetInstance isa 'Win32_USBControllerDevice'"); this.insertWatcher = new ManagementEventWatcher(scope, (EventQuery)wqlEventQuery); this.insertWatcher.EventArrived += usbInsertHandler; } if (usbRemoveHandler != null) { WqlEventQuery wqlEventQuery = new WqlEventQuery("__InstanceDeletionEvent", withinInterval, "TargetInstance isa 'Win32_USBControllerDevice'"); this.removeWatcher = new ManagementEventWatcher(scope, (EventQuery)wqlEventQuery); this.removeWatcher.EventArrived += usbRemoveHandler; } return(true); } catch (Exception ex) { HuionLog.saveLog("usb", ex.Message); this.RemoveUSBEventWatcher(); return(false); } }
private void checkForegroundWindowTick(object sender, EventArgs e) { IntPtr hwnd = GetForegroundWindow(); int processId = GetWindowProcessID(hwnd); if (processId == 1) { return; } Process process = Process.GetProcessById(processId); try { string processFileName = Path.GetFileName(process.MainModule.FileName); if (!processFileName.Equals(lastForegroundApplication)) { lastForegroundApplication = processFileName; HuionLog.printLog("FocusChanged", processFileName.ToLower()); handleFocusChange(processFileName.ToLower()); } } catch (Win32Exception) { } }
public static void applayClick(object sender, EventArgs e) { try { IntPtr coTaskMemAuto = Marshal.StringToCoTaskMemAuto(Application.StartupPath + "\\res\\config_user.xml"); IntPtr num1 = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(HNStruct.HNConfigXML))); for (int index = 0; index < (int)TabletConfigUtils.config.ctxEkeys[0].ctxMek[0].eks[0].num; ++index) { TabletConfigUtils.config.ctxEkeys[0].ctxMek[0].eks[0].mekid = (char[])null; } TabletConfigUtils.config.ctxEkeys[0].ctxMek[0].eks[0].mekid = (char[])null; TabletConfigUtils.config.ctxEkeys[0].ctxMek[0].eks[1].mekid = (char[])null; Marshal.StructureToPtr((object)TabletConfigUtils.config, num1, false); IntPtr num2 = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(HNStruct.HNTabletInfo))); Marshal.StructureToPtr((object)HNStruct.globalInfo.tabletInfo, num2, false); int num3 = (int)HuionDriverDLL.hnx_save_config(num1, num2, coTaskMemAuto, coTaskMemAuto); HuionDriverDLL.hnd_notify_config_changed(); Marshal.FreeHGlobal(num2); Marshal.FreeHGlobal(num1); Marshal.FreeHGlobal(coTaskMemAuto); } catch (Exception ex) { HuionLog.saveLog("保存接口", ex.Message); } }
private void tsmiItemClick(object sender, EventArgs e) { ToolStripMenuItem toolStripMenuItem = (ToolStripMenuItem)sender; if (toolStripMenuItem == this.tsmiExit) { try { this.Dispose(true); this.Close(); this.ezUSB.RemoveUSBEventWatcher(); Process.GetCurrentProcess().Kill(); } catch (Exception ex) { HuionLog.saveLog("退出程序", ex.Message); } } else { if (toolStripMenuItem != this.tsmiSettings) { return; } this.Show(); FormSettings.showForm(this.Handle, true, 0); } }
private static void Main(string[] args) { HNStruct.OemType = DeployConfig.getOemType(); HuionLog.listenGlobalCrashLog(); ResourceCulture.init(); TimerSession.startListenUserOperation(); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); bool flag = false; try { flag = Utils.isAppRunning(); } catch { Utils.runAsAdmin(true); return; } if (new Mutex(true, "OnlyRun").WaitOne(0, false)) { Application.Run((Form) new HuionTalbet()); } else { if (Utils.isStartup(args) || HuionDriverDLL.PostMessage(HuionDriverDLL.FindWindow((string)null, Fixer4Main.FormTitle()), 1054, IntPtr.Zero, IntPtr.Zero) != 0) { return; } Utils.runAsAdmin(true); } }
private static void onRead() { int num1 = (int)HuionDriverDLL.timeBeginPeriod(1U); while (reading) { HNStruct.HNPenData p = new HNStruct.HNPenData(); try { HuionDriverDLL.hndh_get_cursor(ref p); } catch (Exception ex) { HuionLog.saveLog("Get Touch Info", ex.Message); HuionLog.saveLog("Get Touch Info", ex.StackTrace); } if (p.btn > (byte)0) { if (touchInfoListener != null) { touchInfoListener(p); } IntPtr num2 = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(HNStruct.HNPenData))); Marshal.StructureToPtr((object)p, num2, false); HuionDriverDLL.PostMessage(mHandle, 1064, num2, IntPtr.Zero); Marshal.FreeHGlobal(num2); } Thread.Sleep(1); } int num3 = (int)HuionDriverDLL.timeEndPeriod(1U); }
public static void OpenDevice() { try { DeviceStatusUtils.reconnection = true; if (mDeviceCallback == null) { mDeviceCallback = new DeviceStatusUtils.OpenDeviceCallbcak(new DeviceStatusUtils().openDeviceCallback); } if (HNStruct.globalInfo.bOpenedTablet || !DeviceStatusUtils.reconnection) { return; } string s1 = Application.StartupPath + "\\res\\config_user.xml"; string s2 = Application.StartupPath + "\\res\\layout_tablet.xml"; IntPtr coTaskMemAuto1 = Marshal.StringToCoTaskMemAuto(s1); IntPtr coTaskMemAuto2 = Marshal.StringToCoTaskMemAuto(s2); int num = (int)HuionDriverDLL.hnd_open(mDeviceCallback, coTaskMemAuto1, coTaskMemAuto2); Marshal.FreeCoTaskMem(coTaskMemAuto1); Marshal.FreeCoTaskMem(coTaskMemAuto2); } catch (Exception ex) { HuionLog.saveLog("open devices api", ex.Message); } }
public static void USBEventHandler(object sender, EventArrivedEventArgs e) { if (!USB.isConnectionEvent(e) || !USB.isHNTabletDevice(e)) { return; } HuionLog.printSaveLog("usb event", "Huion device was connected"); int num = HNStruct.globalInfo.bOpenedTablet ? 1 : 0; }
public static uint calibratePressVal(HNStruct.HNConfigXML cfg, uint psVal, uint maxP) { try { switch (cfg.pressFactor) { case -4: int num1 = (int)HuionDriverDLL.hnc_equation_power((double)psVal, 0.125, (double)maxP); return(HuionDriverDLL.hnc_equation_power((double)psVal, 0.125, (double)maxP)); case -3: int num2 = (int)HuionDriverDLL.hnc_equation_power((double)psVal, 0.25, (double)maxP); return(HuionDriverDLL.hnc_equation_power((double)psVal, 0.25, (double)maxP)); case -2: int num3 = (int)HuionDriverDLL.hnc_equation_circle((double)psVal, (double)maxP, (double)maxP, 1); return(HuionDriverDLL.hnc_equation_circle((double)psVal, (double)maxP, (double)maxP, 1)); case -1: int num4 = (int)HuionDriverDLL.hnc_equation_circle((double)psVal, (double)(2U * maxP), (double)maxP, 1); return(HuionDriverDLL.hnc_equation_circle((double)psVal, (double)(2U * maxP), (double)maxP, 1)); case 1: int num5 = (int)HuionDriverDLL.hnc_equation_circle((double)psVal, (double)(2U * maxP), (double)maxP, 0); return(HuionDriverDLL.hnc_equation_circle((double)psVal, (double)(2U * maxP), (double)maxP, 0)); case 2: int num6 = (int)HuionDriverDLL.hnc_equation_circle((double)psVal, (double)maxP, (double)maxP, 0); return(HuionDriverDLL.hnc_equation_circle((double)psVal, (double)maxP, (double)maxP, 0)); case 3: int num7 = (int)HuionDriverDLL.hnc_equation_power((double)psVal, 4.0, (double)maxP); return(HuionDriverDLL.hnc_equation_power((double)psVal, 4.0, (double)maxP)); case 4: int num8 = (int)HuionDriverDLL.hnc_equation_power((double)psVal, 8.0, (double)maxP); return(HuionDriverDLL.hnc_equation_power((double)psVal, 8.0, (double)maxP)); } } catch (Exception ex) { HuionLog.saveLog("calibratePressValue", ex.Message); HuionLog.saveLog("calibratePressValue", ex.StackTrace); } return(psVal); }
public void openDeviceCallback(uint msgVal) { HuionLog.printLog("openDeviceCallback1", "uint msgVal = " + (object)msgVal); if (msgVal == 2U || msgVal == 16U || (msgVal == 17U || msgVal == 18U)) { deviceConfigCallback(msgVal); } else { this.onDelayCallback((object)msgVal); } }
public void checkSceenNum() { try { m = VcpFeature.GetAllMonitors(); this.addColorPress(m); } catch (Exception ex) { HuionLog.saveLog("检测屏幕", ex.Message); } }
private static bool SettingIconChange() { try { return(HuionMessageBox.compareVersion()); } catch (Exception ex) { HuionLog.saveLog(nameof(SettingIconChange), ex.Message); return(false); } }
public static void closeDevice(object obj) { try { DeviceStatusUtils.reconnection = false; HuionDriverDLL.hnd_close(); } catch (Exception ex) { HuionLog.printLog("", ex.Message); HuionLog.printLog("", ex.StackTrace); } }
public static int getPenPressValue() { try { HuionDriverDLL.hndh_get_cursor(ref HNStruct.globalInfo.penData); } catch (Exception ex) { HuionLog.saveLog("get press value", ex.Message); HuionLog.saveLog("get press value", ex.StackTrace); } return((int)HNStruct.globalInfo.penData.ps); }
public static void stopListen() { reading = false; touchInfoListener = (ReadTouchInfoCallback)null; try { HuionDriverDLL.hndh_uninit_cursor(); } catch (Exception ex) { HuionLog.saveLog("stop draw line", ex.Message); HuionLog.saveLog("stop draw line", ex.StackTrace); } }
public static HNStruct.HNPenData getTouchInfo() { HNStruct.HNPenData p = new HNStruct.HNPenData(); try { HuionDriverDLL.hndh_get_cursor(ref p); } catch (Exception ex) { HuionLog.saveLog("Get Touch Info", ex.Message); HuionLog.saveLog("Get Touch Info", ex.StackTrace); } return(p); }
private void cboxScreenNum_SelectionChangeCommitted(object sender, EventArgs e) { try { if (!this.cboxScreenNum.SelectedItem.ToString().Contains("Generic Non-PnP Monitor")) { this.enableContorl(); this.cBoxcolorPress.Text = ""; this.cBoxcolorPress.Items.Clear(); index = this.cboxScreenNum.SelectedIndex; m[index].ColorPresets.ForEach((Action <uint>)(cp => { if (!(this.GetColorPressName(cp) != "Unkown")) { return; } this.cBoxcolorPress.Items.Add((object)this.GetColorPressName(cp)); })); this.cBoxcolorPress.SelectedText = "请选择"; Console.WriteLine("切换屏幕成功"); brigtnessVal = VcpFeature.GetVCPFeature(m[index], HNStruct.VCPFeature.LUMINANCE); contrastVal = VcpFeature.GetVCPFeature(m[index], HNStruct.VCPFeature.CONTRAST); factoryResetVal = VcpFeature.GetVCPFeature(m[index], HNStruct.VCPFeature.RESTORE_FACTORY_DEFAULTS); gainRVal = VcpFeature.GetVCPFeature(m[index], HNStruct.VCPFeature.VIDEO_GAIN_RED); gainGVal = VcpFeature.GetVCPFeature(m[index], HNStruct.VCPFeature.VIDEO_GAIN_GREEN); gainBVal = VcpFeature.GetVCPFeature(m[index], HNStruct.VCPFeature.VIDEO_GAIN_BLUE); blackRVal = VcpFeature.GetVCPFeature(m[index], HNStruct.VCPFeature.VIDEO_BLACK_LEVEL_RED); blackGVal = VcpFeature.GetVCPFeature(m[index], HNStruct.VCPFeature.VIDEO_BLACK_LEVEL_GREEN); blackBVal = VcpFeature.GetVCPFeature(m[index], HNStruct.VCPFeature.VIDEO_BLACK_LEVEL_BLUE); this.trackBarR.Maximum = (int)gainRVal[1]; this.trackBarB.Maximum = (int)gainBVal[1]; this.trackBarG.Maximum = (int)gainGVal[1]; this.tBarBrightness.Maximum = (int)brigtnessVal[1]; this.tBarContract.Maximum = (int)contrastVal[1]; this.tBarBrightness.Value = (int)brigtnessVal[0]; this.tBarContract.Value = (int)contrastVal[0]; } else { this.disControl(); } } catch (Exception ex) { this.disControl(); HuionLog.saveLog("change screen", ex.Message); } }
private static bool localConnectStatus() { int dwFlag = 0; try { return(InternetGetConnectedState(ref dwFlag, 0) && ((dwFlag & 1) != 0 || (dwFlag & 2) != 0 || (dwFlag & 3) != 0)); } catch (Exception ex) { int num = (int)MessageBox.Show(ResourceCulture.GetString("Net_Busy"), ResourceCulture.GetString("FormInfo_remindText"), MessageBoxButtons.OK, MessageBoxIcon.Asterisk); HuionLog.saveLog(nameof(localConnectStatus), ex.Message); return(false); } }
public static void startListen(IntPtr handle) { mHandle = handle; reading = true; HNStruct.HNRect r = new HNStruct.HNRect(); try { HuionDriverDLL.hndh_init_cursor(ref r); } catch (Exception ex) { HuionLog.saveLog("start draw line", ex.Message); HuionLog.saveLog("start draw line", ex.StackTrace); } mReadThread = new Thread(new ThreadStart(onRead)); mReadThread.Start(); }
public static void runAsAdmin(bool single) { ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.UseShellExecute = true; startInfo.WorkingDirectory = Environment.CurrentDirectory; startInfo.FileName = Application.ExecutablePath; startInfo.Verb = "runas"; try { Process.Start(startInfo); Application.Exit(); } catch (Exception ex) { HuionLog.saveLog("run as admin", ex.Message); } }
private void panelWindow_SizeChanged(object sender, EventArgs e) { try { if (!IsUpdate || this.openNum >= 1 || !SettingsUtil.isUpdateReminderEnabled) { return; } Console.WriteLine(this.openNum.ToString()); ++this.openNum; this.notifyIcon1.ShowBalloonTip(3, ResourceCulture.GetString("Update_Remind"), ResourceCulture.GetString("Update_RemindVersion"), ToolTipIcon.Info); IsReminder = true; } catch (Exception ex) { HuionLog.saveLog("更新提示", ex.Message); } }
public static void autoOpenDevice(object obj) { try { string s1 = Application.StartupPath + "\\res\\config_user.xml"; string s2 = Application.StartupPath + "\\res\\layout_tablet.xml"; IntPtr coTaskMemAuto1 = Marshal.StringToCoTaskMemAuto(s1); IntPtr coTaskMemAuto2 = Marshal.StringToCoTaskMemAuto(s2); if (mConfigCallback == null) { mConfigCallback = new OpenDeviceCallbcak(deviceConfigCallback); } int num = (int)HuionDriverDLL.hnd_open(mConfigCallback, coTaskMemAuto1, coTaskMemAuto2); Marshal.FreeCoTaskMem(coTaskMemAuto1); Marshal.FreeCoTaskMem(coTaskMemAuto2); } catch (Exception ex) { HuionLog.saveLog("", ex.Message); HuionLog.saveLog("", ex.StackTrace); } }
private void saveCalibrate(IntPtr ptr) { try { IntPtr num1 = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(HNStruct.HNConfigXML))); Marshal.StructureToPtr((object)TabletConfigUtils.config, num1, true); IntPtr num2 = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(HNStruct.HNTabletInfo))); Marshal.StructureToPtr((object)HNStruct.globalInfo.tabletInfo, num2, true); IntPtr coTaskMemAuto = Marshal.StringToCoTaskMemAuto(sourcePath); HuionDriverDLL.hnc_calibrate_monitor(num2, num1, ptr); int num3 = (int)HuionDriverDLL.hnx_save_config(num1, num2, coTaskMemAuto, coTaskMemAuto); HuionDriverDLL.hnd_notify_config_changed(); Marshal.FreeHGlobal(coTaskMemAuto); Marshal.FreeHGlobal(num2); Marshal.FreeHGlobal(num1); } catch (Exception ex) { HuionLog.printSaveLog("", ex.Message); HuionLog.printSaveLog("", ex.StackTrace); } }
private static void MiddleModule_eventSend(object sender, object msg) { HuionLog.printLog(nameof(MiddleModule_eventSend), "reconnect device"); ThreadPool.QueueUserWorkItem(new WaitCallback(DeviceStatusUtils.autoOpenDevice)); }
private void onDelayCallback(object o) { uint num = (uint)o; string currentDirectory = Environment.CurrentDirectory; try { IntPtr tabletInfo = HuionDriverDLL.hnd_get_tablet_info(); HNStruct.globalInfo.tabletInfo = (HNStruct.HNTabletInfo)Marshal.PtrToStructure(tabletInfo, typeof(HNStruct.HNTabletInfo)); if (HNStruct.globalInfo.tabletInfo.devType != 0U) { Console.Write(HNStruct.globalInfo.tabletInfo.devType.ToString()); HNStruct.OemType = getActualOemType(); switch (HNStruct.OemType) { case OEMType.HUION: HNStruct.globalInfo.bOpenedTablet = TabletConfigUtils.isHuionTablet(HNStruct.globalInfo.tabletInfo.devType); Console.WriteLine(HNStruct.globalInfo.bOpenedTablet.ToString()); if (HNStruct.globalInfo.tabletInfo.devType == 19U) { HNStruct.globalInfo.tabletInfo.maxP = (ushort)4095; break; } break; case OEMType.GAOMON: HNStruct.globalInfo.bOpenedTablet = TabletConfigUtils.isGaomonTablet(HNStruct.globalInfo.tabletInfo.devType); break; case OEMType.YINENG: HNStruct.globalInfo.bOpenedTablet = TabletConfigUtils.isYinengTablet(HNStruct.globalInfo.tabletInfo.devType); break; case OEMType.YOUSHANG: HNStruct.globalInfo.bOpenedTablet = TabletConfigUtils.isYoushangTablet(HNStruct.globalInfo.tabletInfo.devType); break; case OEMType.SHIJUN: HNStruct.globalInfo.bOpenedTablet = TabletConfigUtils.isShijunTablet(HNStruct.globalInfo.tabletInfo.devType); break; case OEMType.KJC: HNStruct.globalInfo.bOpenedTablet = TabletConfigUtils.isKJCTablet(HNStruct.globalInfo.tabletInfo.devType); break; default: HNStruct.globalInfo.bOpenedTablet = false; break; } if (HNStruct.globalInfo.bOpenedTablet) { new TabletConfigUtils().readConfig(); } else { ThreadPool.QueueUserWorkItem(new WaitCallback(TabletConfigUtils.closeDevice)); } MiddleModule.PostMessage((object)this, (object)num); } else { HNStruct.globalInfo.bOpenedTablet = false; MiddleModule.PostMessage((object)this, (object)0); } } catch (Exception ex) { HuionLog.printSaveLog("open device callback", ex.Message); HuionLog.printSaveLog("当前路径", currentDirectory); HuionLog.printSaveLog("open device callback", ex.StackTrace); HNStruct.globalInfo.bOpenedTablet = false; MiddleModule.PostMessage((object)this, (object)0); } }
private void handleFocusChange(string processFileName) { if (!HNStruct.globalInfo.bOpenedTablet) { // Too early, driver not loaded return; } if (this.currentSettings != null && (processFileName.Equals(Path.GetFileName(Process.GetCurrentProcess().MainModule.FileName.ToLower())) || SettingsUtil.excludedApplications.Contains(processFileName))) { // Excluded app return; } HNStruct.PerAppSetting appSetting; if (this.perAppSettings.ContainsKey(processFileName) && this.perAppSettings[processFileName].enabled) { appSetting = this.perAppSettings[processFileName]; } else if (this.perAppSettingsDefault.HasValue && this.perAppSettingsDefault.Value.enabled) { appSetting = this.perAppSettingsDefault.Value; } else { // No setting found return; } if (appSetting.profile.Equals(this.currentSettings)) { HuionLog.printLog("FocusChanged", "Error: already active"); // already active return; } string path = Path.GetFullPath(Path.Combine(this.perAppSettingsProfileDir, appSetting.profile)); if (!File.Exists(path)) { HuionLog.printLog("FocusChanged", "Error: file not found"); return; } HuionLog.printLog("FocusChanged", "Info: loading profile"); IntPtr coTaskMemAuto = Marshal.StringToCoTaskMemAuto(path); Marshal.AllocHGlobal(Marshal.SizeOf(typeof(HNStruct.HNConfigXML))); IntPtr num = HuionDriverDLL.hnx_read_config(ref HNStruct.globalInfo.tabletInfo, coTaskMemAuto); TabletConfigUtils.config = (HNStruct.HNConfigXML)Marshal.PtrToStructure(num, typeof(HNStruct.HNConfigXML)); new TabletConfigUtils().SetConfig(TabletConfigUtils.config); Marshal.FreeHGlobal(coTaskMemAuto); Marshal.FreeHGlobal(num); currentSettings = appSetting.profile; Fixer4Main.applayClick(null, null); HuionLog.printLog("FocusChanged", "Info: profile loaded"); this.notifyIcon1.ShowBalloonTip(3, "Profile switched", Path.GetFileNameWithoutExtension(appSetting.profile), ToolTipIcon.Info); this.notifyIcon1.Text = $"{ResourceCulture.GetString("FormHuionTabletNotifyIconText")}" + $" ({Path.GetFileNameWithoutExtension(appSetting.profile)})"; // Refresh Info if (this.panelWindow.Controls.Count > 0) { this.mTabType = TabType.TabWorkArea; this.buttonInfo_Click(null, null); } this.ResumeLayout(false); }
public static void CreateSettingsXml() { if (File.Exists("SettingsFile.xml")) { return; } XmlDocument xmlDocument = new XmlDocument(); HuionKeyEventArgs defaultUiShortcut = DefaultUIShortcut; try { XmlDeclaration xmlDeclaration = xmlDocument.CreateXmlDeclaration("1.0", "utf-8", (string)null); xmlDocument.AppendChild((XmlNode)xmlDeclaration); XmlElement element1 = xmlDocument.CreateElement("Settings"); xmlDocument.AppendChild((XmlNode)element1); XmlElement element2 = xmlDocument.CreateElement("Autorun"); element2.SetAttribute("value", "1"); element1.AppendChild((XmlNode)element2); XmlElement updateReminder = xmlDocument.CreateElement("UpdateReminder"); updateReminder.SetAttribute("enabled", "0"); element1.AppendChild((XmlNode)updateReminder); XmlElement perAppSettingsElement = xmlDocument.CreateElement("PerAppSettings"); perAppSettingsElement.SetAttribute("enabled", "1"); string defaultProfileDir = Path.GetFullPath(Environment.ExpandEnvironmentVariables("%userprofile%\\.Huion Tablet\\profiles")); Directory.CreateDirectory(defaultProfileDir); perAppSettingsElement.SetAttribute("profileDir", defaultProfileDir); perAppSettingsElement.SetAttribute("manualMode", "0"); XmlComment comment = xmlDocument.CreateComment(" App and Default tags will be ignored if manualMode=\"0\" "); perAppSettingsElement.AppendChild(comment); XmlElement perAppSettingSampleElement = xmlDocument.CreateElement("App"); perAppSettingSampleElement.SetAttribute("enabled", "0"); perAppSettingSampleElement.SetAttribute("processFileName", "sample.exe"); perAppSettingSampleElement.SetAttribute("profile", "sample.xml"); perAppSettingsElement.AppendChild((XmlNode)perAppSettingSampleElement); XmlElement perAppSettingDefaultElement = xmlDocument.CreateElement("Default"); perAppSettingDefaultElement.SetAttribute("enabled", "0"); perAppSettingDefaultElement.SetAttribute("profile", "sample.xml"); perAppSettingsElement.AppendChild((XmlNode)perAppSettingDefaultElement); element1.AppendChild((XmlNode)perAppSettingsElement); XmlElement element3 = xmlDocument.CreateElement("Shortcuts"); element1.AppendChild((XmlNode)element3); XmlElement element4 = xmlDocument.CreateElement("ShowUI"); element3.AppendChild((XmlNode)element4); element4.SetAttribute("ctrl", defaultUiShortcut.Control ? "1" : "0"); element4.SetAttribute("alt", defaultUiShortcut.Alt ? "1" : "0"); element4.SetAttribute("win", defaultUiShortcut.Window ? "1" : "0"); element4.SetAttribute("shift", defaultUiShortcut.Shift ? "1" : "0"); element4.SetAttribute("key", string.Concat((object)defaultUiShortcut.KeyCode)); xmlDocument.Save("SettingsFile.xml"); } catch (Exception ex) { HuionLog.printSaveLog("Read UI Shortcut", ex.Message); HuionLog.printSaveLog("Read UI Shortcut", ex.StackTrace); } }