public void ReadOptions(string file) { if (!File.Exists(file)) { return; } FileStream fini = new FileStream(file, FileMode.Open); StreamReader srini = new StreamReader(fini); string sLine = ""; string sName = "", sPara = ""; while (sLine != null) { sLine = srini.ReadLine(); if ( sLine != null && sLine != "" && sLine.Substring(0, 1) != "-" && sLine.Substring(0, 1) != "%" && sLine.Substring(0, 1) != "'" && sLine.Substring(0, 1) != "/" && sLine.Substring(0, 1) != "!" && sLine.Substring(0, 1) != "[" && sLine.Substring(0, 1) != "#" && sLine.Contains("=") && !sLine.Substring(sLine.IndexOf("=") + 1).Contains("=") ) { sName = sLine.Substring(0, sLine.IndexOf("=")); sName = sName.Trim(); sName = sName.ToUpper(); sPara = sLine.Substring(sLine.IndexOf("=") + 1); sPara = sPara.Trim(); if (sName.StartsWith("PEN")) { int penid = 0; if (int.TryParse(sName.Substring(3, 1), out penid)) { if (sName.EndsWith("_ENABLED")) { if (sPara.ToUpper() == "TRUE" || sPara == "1" || sPara.ToUpper() == "ON") { PenEnabled[penid] = true; } else if (sPara.ToUpper() == "FALSE" || sPara == "0" || sPara.ToUpper() == "OFF") { PenEnabled[penid] = false; } } int penc = 0; if (int.TryParse(sPara, out penc)) { if (sName.EndsWith("_RED") && penc >= 0 && penc <= 255) { PenAttr[penid].Color = Color.FromArgb(penc, PenAttr[penid].Color.G, PenAttr[penid].Color.B); } else if (sName.EndsWith("_GREEN") && penc >= 0 && penc <= 255) { PenAttr[penid].Color = Color.FromArgb(PenAttr[penid].Color.R, penc, PenAttr[penid].Color.B); } else if (sName.EndsWith("_BLUE") && penc >= 0 && penc <= 255) { PenAttr[penid].Color = Color.FromArgb(PenAttr[penid].Color.R, PenAttr[penid].Color.G, penc); } else if (sName.EndsWith("_ALPHA") && penc >= 0 && penc <= 255) { PenAttr[penid].Transparency = (byte)(255 - penc); } else if (sName.EndsWith("_WIDTH") && penc >= 30 && penc <= 3000) { PenAttr[penid].Width = penc; } } if (sName.EndsWith("_HOTKEY")) { Hotkey_Pens[penid].Parse(sPara); } } } int tempi = 0; switch (sName) { case "HOTKEY_GLOBAL": Hotkey_Global.Parse(sPara); break; case "HOTKEY_ERASER": Hotkey_Eraser.Parse(sPara); break; case "HOTKEY_INKVISIBLE": Hotkey_InkVisible.Parse(sPara); break; case "HOTKEY_POINTER": Hotkey_Pointer.Parse(sPara); break; case "HOTKEY_PAN": Hotkey_Pan.Parse(sPara); break; case "HOTKEY_UNDO": Hotkey_Undo.Parse(sPara); break; case "HOTKEY_REDO": Hotkey_Redo.Parse(sPara); break; case "HOTKEY_SNAPSHOT": Hotkey_Snap.Parse(sPara); break; case "HOTKEY_CLEAR": Hotkey_Clear.Parse(sPara); break; case "WHITE_TRAY_ICON": if (sPara.ToUpper() == "TRUE" || sPara == "1" || sPara.ToUpper() == "ON") { WhiteTrayIcon = true; } else { WhiteTrayIcon = false; } break; case "SNAPSHOT_PATH": SnapshotBasePath = sPara; if (!SnapshotBasePath.EndsWith("/") && !SnapshotBasePath.EndsWith("\\")) { SnapshotBasePath += "/"; } break; case "ERASER_ICON": if (sPara.ToUpper() == "FALSE" || sPara == "0" || sPara.ToUpper() == "OFF") { EraserEnabled = false; } break; case "POINTER_ICON": if (sPara.ToUpper() == "FALSE" || sPara == "0" || sPara.ToUpper() == "OFF") { PointerEnabled = false; } break; case "PEN_WIDTH_ICON": if (sPara.ToUpper() == "FALSE" || sPara == "0" || sPara.ToUpper() == "OFF") { PenWidthEnabled = false; } else if (sPara.ToUpper() == "TRUE" || sPara == "1" || sPara.ToUpper() == "ON") { PenWidthEnabled = true; } break; case "SNAPSHOT_ICON": if (sPara.ToUpper() == "FALSE" || sPara == "0" || sPara.ToUpper() == "OFF") { SnapEnabled = false; } break; case "CLOSE_ON_SNAP": if (sPara.ToUpper() == "FALSE" || sPara == "0" || sPara.ToUpper() == "OFF") { CloseOnSnap = false; } break; case "UNDO_ICON": if (sPara.ToUpper() == "FALSE" || sPara == "0" || sPara.ToUpper() == "OFF") { UndoEnabled = false; } break; case "CLEAR_ICON": if (sPara.ToUpper() == "FALSE" || sPara == "0" || sPara.ToUpper() == "OFF") { ClearEnabled = false; } break; case "PAN_ICON": if (sPara.ToUpper() == "FALSE" || sPara == "0" || sPara.ToUpper() == "OFF") { PanEnabled = false; } break; case "INKVISIBLE_ICON": if (sPara.ToUpper() == "FALSE" || sPara == "0" || sPara.ToUpper() == "OFF") { InkVisibleEnabled = false; } break; case "ALLOW_DRAGGING_TOOLBAR": if (sPara.ToUpper() == "FALSE" || sPara == "0" || sPara.ToUpper() == "OFF") { AllowDraggingToolbar = false; } break; case "ALLOW_HOTKEY_IN_POINTER_MODE": if (sPara.ToUpper() == "FALSE" || sPara == "0" || sPara.ToUpper() == "OFF") { AllowHotkeyInPointerMode = false; } break; case "TOOLBAR_LEFT": if (int.TryParse(sPara, out tempi)) { gpButtonsLeft = tempi; } break; case "TOOLBAR_TOP": if (int.TryParse(sPara, out tempi)) { gpButtonsTop = tempi; } break; case "CANVAS_CURSOR": if (sPara == "0") { CanvasCursor = 0; } else if (sPara == "1") { CanvasCursor = 1; } break; } } } fini.Close(); }
public void ReadOptions(string file) { Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture; if (!File.Exists(file)) { file = AppDomain.CurrentDomain.BaseDirectory + file; } if (!File.Exists(file)) { return; } FileStream fini = new FileStream(file, FileMode.Open); StreamReader srini = new StreamReader(fini); string sLine = string.Empty; string sName = string.Empty, sPara = string.Empty; while (sLine != null) { sLine = srini.ReadLine(); if ( sLine != null && sLine != string.Empty && sLine.Substring(0, 1) != "-" && sLine.Substring(0, 1) != "%" && sLine.Substring(0, 1) != "'" && sLine.Substring(0, 1) != "/" && sLine.Substring(0, 1) != "!" && sLine.Substring(0, 1) != "[" && sLine.Substring(0, 1) != "#" && sLine.Contains("=") && !sLine.Substring(sLine.IndexOf("=") + 1).Contains("=") ) { sName = sLine.Substring(0, sLine.IndexOf("=")); sName = sName.Trim(); sName = sName.ToUpper(); sPara = sLine.Substring(sLine.IndexOf("=") + 1); sPara = sPara.Trim(); if (sName.StartsWith("PEN")) { int penid = 0; if (int.TryParse(sName.Substring(3, 1), out penid)) { if (sName.EndsWith("_ENABLED")) { if (sPara.ToUpper() == "TRUE" || sPara == "1" || sPara.ToUpper() == "ON") { PenEnabled[penid] = true; } else if (sPara.ToUpper() == "FALSE" || sPara == "0" || sPara.ToUpper() == "OFF") { PenEnabled[penid] = false; } } int penc = 0; if (int.TryParse(sPara, out penc)) { if (sName.EndsWith("_RED") && penc >= 0 && penc <= 255) { PenAttr[penid].Color = Color.FromArgb(penc, PenAttr[penid].Color.G, PenAttr[penid].Color.B); } else if (sName.EndsWith("_GREEN") && penc >= 0 && penc <= 255) { PenAttr[penid].Color = Color.FromArgb(PenAttr[penid].Color.R, penc, PenAttr[penid].Color.B); } else if (sName.EndsWith("_BLUE") && penc >= 0 && penc <= 255) { PenAttr[penid].Color = Color.FromArgb(PenAttr[penid].Color.R, PenAttr[penid].Color.G, penc); } else if (sName.EndsWith("_ALPHA") && penc >= 0 && penc <= 255) { PenAttr[penid].Transparency = (byte)(255 - penc); } else if (sName.EndsWith("_WIDTH") && penc >= 30 && penc <= 3000) { PenAttr[penid].Width = penc; } } if (sName.EndsWith("_HOTKEY")) { Hotkey_Pens[penid].Parse(sPara); } } } int tempi = 0; float tempf = 0; switch (sName) { case "LANGUAGE_FILE": ChangeLanguage(sPara); break; case "HOTKEY_GLOBAL": Hotkey_Global.Parse(sPara); break; case "HOTKEY_ERASER": Hotkey_Eraser.Parse(sPara); break; case "HOTKEY_INKVISIBLE": Hotkey_InkVisible.Parse(sPara); break; case "HOTKEY_POINTER": Hotkey_Pointer.Parse(sPara); break; case "HOTKEY_PAN": Hotkey_Pan.Parse(sPara); break; case "HOTKEY_UNDO": Hotkey_Undo.Parse(sPara); break; case "HOTKEY_REDO": Hotkey_Redo.Parse(sPara); break; case "HOTKEY_SNAPSHOT": Hotkey_Snap.Parse(sPara); break; case "HOTKEY_CLEAR": Hotkey_Clear.Parse(sPara); break; case "WHITE_TRAY_ICON": if (sPara.ToUpper() == "TRUE" || sPara == "1" || sPara.ToUpper() == "ON") { WhiteTrayIcon = true; } else { WhiteTrayIcon = false; } break; case "SNAPSHOT_PATH": SnapshotBasePath = sPara; if (!SnapshotBasePath.EndsWith("/") && !SnapshotBasePath.EndsWith("\\")) { SnapshotBasePath += "/"; } break; case "ERASER_ICON": if (sPara.ToUpper() == "FALSE" || sPara == "0" || sPara.ToUpper() == "OFF") { EraserEnabled = false; } break; case "POINTER_ICON": if (sPara.ToUpper() == "FALSE" || sPara == "0" || sPara.ToUpper() == "OFF") { PointerEnabled = false; } break; case "PEN_WIDTH_ICON": if (sPara.ToUpper() == "FALSE" || sPara == "0" || sPara.ToUpper() == "OFF") { PenWidthEnabled = false; } else if (sPara.ToUpper() == "TRUE" || sPara == "1" || sPara.ToUpper() == "ON") { PenWidthEnabled = true; } break; case "SNAPSHOT_ICON": if (sPara.ToUpper() == "FALSE" || sPara == "0" || sPara.ToUpper() == "OFF") { SnapEnabled = false; } break; case "CLOSE_ON_SNAP": if (sPara.ToUpper() == "FALSE" || sPara == "0" || sPara.ToUpper() == "OFF") { CloseOnSnap = "false"; } else if (sPara.ToUpper() == "TRUE" || sPara == "1" || sPara.ToUpper() == "ON") { CloseOnSnap = "true"; } else if (sPara.ToUpper() == "BLANKONLY") { CloseOnSnap = "blankonly"; } break; case "ALWAYS_HIDE_TOOLBAR": if (sPara.ToUpper() == "TRUE" || sPara == "1" || sPara.ToUpper() == "ON") { AlwaysHideToolbar = true; } break; case "UNDO_ICON": if (sPara.ToUpper() == "FALSE" || sPara == "0" || sPara.ToUpper() == "OFF") { UndoEnabled = false; } break; case "CLEAR_ICON": if (sPara.ToUpper() == "FALSE" || sPara == "0" || sPara.ToUpper() == "OFF") { ClearEnabled = false; } break; case "PAN_ICON": if (sPara.ToUpper() == "FALSE" || sPara == "0" || sPara.ToUpper() == "OFF") { PanEnabled = false; } break; case "INKVISIBLE_ICON": if (sPara.ToUpper() == "FALSE" || sPara == "0" || sPara.ToUpper() == "OFF") { InkVisibleEnabled = false; } break; case "ALLOW_DRAGGING_TOOLBAR": if (sPara.ToUpper() == "FALSE" || sPara == "0" || sPara.ToUpper() == "OFF") { AllowDraggingToolbar = false; } break; case "ALLOW_HOTKEY_IN_POINTER_MODE": if (sPara.ToUpper() == "FALSE" || sPara == "0" || sPara.ToUpper() == "OFF") { AllowHotkeyInPointerMode = false; } break; case "TOOLBAR_LEFT": if (int.TryParse(sPara, out tempi)) { gpButtonsLeft = tempi; } break; case "TOOLBAR_TOP": if (int.TryParse(sPara, out tempi)) { gpButtonsTop = tempi; } break; case "TOOLBAR_HEIGHT": if (float.TryParse(sPara, out tempf)) { ToolbarHeight = tempf; } break; } } } fini.Close(); }