Example #1
0
        //</Snippet3>

        private bool WriteFormDataToFile()
        {
            // Write the form positions to the file.
            UTF8Encoding encoding = new UTF8Encoding();

            RectangleConverter rectConv = new RectangleConverter();
            string             form1pos = rectConv.ConvertToString(_form1Position);
            string             form2pos = rectConv.ConvertToString(_form2Position);

            byte[] dataToWrite = encoding.GetBytes("~" + form1pos + "~" + form2pos);

            try
            {
                // Set the write position to the start of the file and write
                _userData.Seek(0, SeekOrigin.Begin);
                _userData.Write(dataToWrite, 0, dataToWrite.Length);
                _userData.Flush();

                _userData.SetLength(dataToWrite.Length);
                return(true);
            }
            catch
            {
                // An error occurred while attempting to write, return false.
                return(false);
            }
        }
Example #2
0
        void InstallPad_FormClosing(object sender, FormClosingEventArgs e)
        {
            // Serialize form position to file, so we can restore it later.
            RectangleConverter convert      = new RectangleConverter();
            string             formPosition = convert.ConvertToString(this.Bounds);

            TextWriter writer = null;

            try
            {
                string configFolder = Path.GetDirectoryName(InstallPadApp.ConfigFilePath);
                if (!Directory.Exists(configFolder))
                {
                    Directory.CreateDirectory(configFolder);
                }
                writer = new StreamWriter(InstallPadApp.ConfigFilePath);
                writer.Write(formPosition);
            }
            // We can get here if InstallPad.form_load had a problem,
            // so just eat exceptions rather than throwing more of them.
            catch (Exception ex) { }
            finally
            {
                if (writer != null)
                {
                    writer.Close();
                }
            }
        }
Example #3
0
        private void Save()
        {
            foreach (var window in windows.Values)
            {
                string settingID = string.Format("window.{0}.visible", window.ID);
                Tool.Settings.SetValue(settingID, window.Visible.ToString());

                if (window.Visible)
                {
                    settingID = string.Format("window.{0}.bounds", window.ID);
                    Tool.Settings.SetValue(settingID, converter.ConvertToString(window.DesktopBounds));
                }
            }
        }
Example #4
0
        /// <summary>
        /// 메모폼 정보 저장
        /// </summary>
        private void saveMemo(Item item)
        {
            XmlDocument xmlDoc   = Common.XmlControl.getInstance().xmlLoad(DEFINE.MEMO_DATA_PATH);
            XmlNode     memoNode = xmlDoc.SelectSingleNode("//MEMODATA");
            String      path     = item.PATH;

            if (path != "/")
            {
                String[] paths = path.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
                for (int i = 0; i < paths.Length; i++)
                {
                    memoNode = memoNode.SelectSingleNode("./" + DEFINE.NODE_GROUPNAME + "[@name='" + paths[i] + "']");
                }
            }

            XmlNode            targetNode = memoNode.SelectSingleNode("./" + DEFINE.NODE_MEMONAME + "[@name='" + item.TITLE + "']");
            RectangleConverter rc         = new RectangleConverter();

            XmlNode      tmpNode = xmlDoc.CreateNode(XmlNodeType.Element, targetNode.Name, "");
            XmlAttribute attr1   = xmlDoc.CreateAttribute("name");

            attr1.Value = item.TITLE;
            XmlAttribute attr2 = xmlDoc.CreateAttribute("text");

            attr2.Value = item.TEXT;
            XmlAttribute attr3 = xmlDoc.CreateAttribute("rect");

            attr3.Value = rc.ConvertToString(item.RECT);
            tmpNode.Attributes.Append(attr1);
            tmpNode.Attributes.Append(attr2);
            tmpNode.Attributes.Append(attr3);

            targetNode.ParentNode.ReplaceChild(tmpNode, targetNode);

            Common.XmlControl.getInstance().xmlSave(xmlDoc, DEFINE.MEMO_DATA_PATH);

            if (mainFolder != null)
            {
                mainFolder.listViewReload();
            }
        }
Example #5
0
        private void button4_Click(object sender, EventArgs e)
        {
            JArray             patterns = new JArray();
            RectangleConverter rc       = new RectangleConverter();

            foreach (var item in listBox1.Items)
            {
                string identifier = item.ToString();

                if (!selectedRectangles.ContainsKey(identifier) ||
                    !selectedImages.ContainsKey(identifier))
                {
                    continue;
                }

                JArray rectArray = new JArray();
                foreach (var r in selectedRectangles[identifier])
                {
                    JObject rectObj = new JObject();
                    rectObj["rect"] = rc.ConvertToString(r.Rectangle);
                    rectObj["type"] = r.Type;
                    rectArray.Add(rectObj);
                }


                selectedImages[identifier].Save(PATH + identifier + ".png");

                JObject pattern = new JObject();
                pattern["identifier"] = identifier;
                pattern["rects"]      = rectArray;
                patterns.Add(pattern);
            }

            JObject root = new JObject();

            root["patterns"] = patterns;
            File.WriteAllText(PATH + "config.json", JsonConvert.SerializeObject(root));
        }
Example #6
0
        /// <summary>
        /// Creates XML string from instance of module
        /// </summary>
        /// <param name="module">Module</param>
        /// <returns>XML Node of module</returns>
        public HtmlNode GetNodeFromModule(AModule module)
        {
            Type moduleType = module.GetType();
            Type setupType  = module.setup.GetType();

            // Create root node
            String moduleName = (String)moduleType.GetField("name", BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy).GetValue(null);


            HtmlDocument htmlDoc = new HtmlDocument();
            HtmlNode     node    = htmlDoc.CreateElement("module");

            // Save all setup_* members to attributes
            MemberInfo[] setupMembers = setupType.GetMember("setup_*", BindingFlags.Public | BindingFlags.Instance);
            foreach (MemberInfo setupMember in setupMembers)
            {
                HtmlAttribute attribute = htmlDoc.CreateAttribute(setupMember.Name);
                attribute.Value = (String)setupType.InvokeMember(setupMember.Name, BindingFlags.Public | BindingFlags.Instance | BindingFlags.GetProperty, null, module.setup, null);
                node.Attributes.Append(attribute);
            }

            // Save name(type) of module
            HtmlAttribute nameAttr = htmlDoc.CreateAttribute("name");

            nameAttr.Value = moduleName;
            node.Attributes.Append(nameAttr);

            // Save position as attr
            Rectangle          location     = (Rectangle)setupType.GetField("location", BindingFlags.Public | BindingFlags.Instance | BindingFlags.FlattenHierarchy).GetValue(module.setup);
            HtmlAttribute      locationAttr = htmlDoc.CreateAttribute("location");
            RectangleConverter converter    = new RectangleConverter();

            locationAttr.Value = converter.ConvertToString(location);
            node.Attributes.Append(locationAttr);

            return(node);
        }
Example #7
0
        /// <summary>
        /// 이름 정보 변경
        /// </summary>
        /// <param name="item"></param>
        private void renameItem(Item item, string newName)
        {
            XmlDocument xmlDoc   = Common.XmlControl.getInstance().xmlLoad(DEFINE.MEMO_DATA_PATH);
            XmlNode     memoNode = xmlDoc.SelectSingleNode("//MEMODATA");
            String      path     = item.PATH;

            if (path != "/")
            {
                String[] paths = path.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
                for (int i = 0; i < paths.Length; i++)
                {
                    memoNode = memoNode.SelectSingleNode("./" + DEFINE.NODE_GROUPNAME + "[@name='" + paths[i] + "']");
                }
            }

            string  targetType = item.TYPE == DEFINE.FILETYPE.FILETYPE_TEXT ? DEFINE.NODE_MEMONAME : DEFINE.NODE_GROUPNAME;
            XmlNode targetNode = memoNode.SelectSingleNode("./" + targetType + "[@name='" + item.TITLE + "']");


            XmlNode      tmpNode = xmlDoc.CreateNode(XmlNodeType.Element, targetNode.Name, "");
            XmlAttribute attr1   = xmlDoc.CreateAttribute("name");

            attr1.Value = newName;
            tmpNode.Attributes.Append(attr1);

            // 이름 바뀐 항목이 Memo인 경우
            if (targetType == DEFINE.NODE_MEMONAME)
            {
                RectangleConverter rc = new RectangleConverter();

                XmlAttribute attr2 = xmlDoc.CreateAttribute("text");
                attr2.Value = item.TEXT;
                tmpNode.Attributes.Append(attr2);
                XmlAttribute attr3 = xmlDoc.CreateAttribute("rect");
                attr3.Value = rc.ConvertToString(item.RECT);
                tmpNode.Attributes.Append(attr3);



                // 현재 이름 변경하는 메모 폼이 열려있을 경우 TITLE 변경
                for (int i = memoForms.Count - 1; i >= 0; i--)
                {
                    if (memoForms[i].g_item.PATH == item.PATH && memoForms[i].g_item.TITLE == item.TITLE)
                    {
                        memoForms[i].g_item.TITLE = newName;
                        memoForms[i].refresh_memoInfo();
                    }
                }
            }
            else if (targetType == DEFINE.NODE_GROUPNAME) //이름 바뀐 항목이 그룹인 경우
            {
                tmpNode.InnerXml = targetNode.InnerXml;
                string groupPath_old = item.PATH + item.TITLE;

                string[] paths = groupPath_old.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
                // 현재 이름 변경하는 그룹에 하위항목에 해당하는 메모 폼이 열려있을 경우
                for (int i = memoForms.Count - 1; i >= 0; i--)
                {
                    string[] paths2  = memoForms[i].g_item.PATH.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
                    bool     isChild = true;
                    for (int j = 0; j < paths2.Length; j++)
                    {
                        if (paths.Length < paths2.Length ? true : paths[j] != paths2[j])
                        {
                            isChild = false;
                            break;
                        }
                    }
                    if (isChild)
                    {
                        StringBuilder sb = new StringBuilder();
                        sb.Append('/');
                        for (int j = 0; j < paths2.Length; j++)
                        {
                            if (j == paths.Length - 1)
                            {
                                sb.Append(newName);
                            }
                            else
                            {
                                sb.Append(paths2[j]);
                            }
                            sb.Append('/');
                        }
                        memoForms[i].g_item.PATH = sb.ToString();
                        memoForms[i].refresh_memoInfo();
                    }
                }
            }

            targetNode.ParentNode.ReplaceChild(tmpNode, targetNode);

            Common.XmlControl.getInstance().xmlSave(xmlDoc, DEFINE.MEMO_DATA_PATH);

            if (mainFolder != null)
            {
                mainFolder.listViewReload();
            }
        }
        public void SaveConfig()
        {
            // local var for marshal-by-reference
            // prevent runtime exception
            var tabletMode = mainForm.tabletMode;
            var cursorType = overlayForm.cursorType;

            Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

            config.AppSettings.Settings.Remove("Strength");
            config.AppSettings.Settings.Add("Strength", smoothingStrength.ToString());
            config.AppSettings.Settings.Remove("Interpolation");
            config.AppSettings.Settings.Add("Interpolation", smoothingInterpolation.ToString());
            config.AppSettings.Settings.Remove("Manual Interpolation");
            config.AppSettings.Settings.Add("Manual Interpolation", manualInterpolation.ToString());
            config.AppSettings.Settings.Remove("Smooth On Draw");
            config.AppSettings.Settings.Add("Smooth On Draw", smoothOnDraw.ToString());
            config.AppSettings.Settings.Remove("Stay On Top");
            config.AppSettings.Settings.Add("Stay On Top", stayOnTop.ToString());
            config.AppSettings.Settings.Remove("Tablet Mode");
            config.AppSettings.Settings.Add("Tablet Mode", tabletMode.ToString());
            config.AppSettings.Settings.Remove("Overlay Screen");
            config.AppSettings.Settings.Add("Overlay Screen", overlayScreen.ToString());
            config.AppSettings.Settings.Remove("Disable Overlay");
            config.AppSettings.Settings.Add("Disable Overlay", disableOverlay.ToString());
            config.AppSettings.Settings.Remove("All Screens");
            config.AppSettings.Settings.Add("All Screens", allScreens.ToString());
            config.AppSettings.Settings.Remove("Manual Overlay Override");
            config.AppSettings.Settings.Add("Manual Overlay Override", manualOverlayOverride.ToString());
            config.AppSettings.Settings.Remove("Override Bounds");
            RectangleConverter r = new RectangleConverter();

            config.AppSettings.Settings.Add("Override Bounds", r.ConvertToString(overrideBounds));
            config.AppSettings.Settings.Remove("Disable Catch Up");
            config.AppSettings.Settings.Add("Disable Catch Up", disableCatchUp.ToString());
            config.AppSettings.Settings.Remove("Snap to Cursor");
            config.AppSettings.Settings.Add("Snap to Cursor", snapToCursor.ToString());
            config.AppSettings.Settings.Remove("Cursor Graphic");
            config.AppSettings.Settings.Add("Cursor Graphic", cursorType.ToString());
            config.AppSettings.Settings.Remove("Main Color");
            config.AppSettings.Settings.Add("Main Color", ColorTranslator.ToHtml(overlayForm.cursorColor));
            config.AppSettings.Settings.Remove("Fill Color");
            config.AppSettings.Settings.Add("Fill Color", ColorTranslator.ToHtml(overlayForm.cursorFillColor));
            config.AppSettings.Settings.Remove("Disable Auto Detection");
            config.AppSettings.Settings.Add("Disable Auto Detection", disableAutoDetection.ToString());
            config.AppSettings.Settings.Remove("Tolerance");
            config.AppSettings.Settings.Add("Tolerance", tolerance.ToString());
            config.AppSettings.Settings.Remove("Tablet Offset Override");
            config.AppSettings.Settings.Add("Tablet Offset Override", tabletOffsetOverride.ToString());
            config.AppSettings.Settings.Remove("Tablet Offset");
            PointConverter p = new PointConverter();

            config.AppSettings.Settings.Add("Tablet Offset", p.ConvertToString(tabletOffset));
            config.AppSettings.Settings.Remove("Hotkey 1");
            config.AppSettings.Settings.Add("Hotkey 1", hotkeys[0].ToString());
            config.AppSettings.Settings.Remove("Hotkey 2");
            config.AppSettings.Settings.Add("Hotkey 2", hotkeys[1].ToString());
            config.AppSettings.Settings.Remove("Hotkey 3");
            config.AppSettings.Settings.Add("Hotkey 3", hotkeys[2].ToString());
            config.AppSettings.Settings.Remove("Hotkey 4");
            config.AppSettings.Settings.Add("Hotkey 4", hotkeys[3].ToString());
            config.AppSettings.Settings.Remove("Hotkey 5");
            config.AppSettings.Settings.Add("Hotkey 5", hotkeys[4].ToString());
            config.AppSettings.Settings.Remove("Hotkey 6");
            config.AppSettings.Settings.Add("Hotkey 6", hotkeys[5].ToString());
            config.Save(ConfigurationSaveMode.Modified);
        }