Example #1
0
        private void MyDiary_Loaded(object sender, RoutedEventArgs e)
        {
            Colorit();
            string date_string    = DateTime.Now.ToString("yyyy-MM-dd");
            string weekday_string = DateTime.Now.DayOfWeek.ToString();

            this.Label_time.Content = date_string + " " + weekday_string;
            this.diaryBox.Text      = original_text;

            WinChange(0);

            string help_msg = "";

            help_msg += "MyDiary By BlackHand\n";
            help_msg += "o : 打开日记\n";
            help_msg += "c : 更换颜色\n";
            help_msg += "×: 退出";
            Label_helptext.Content = help_msg;

            System.Resources.ResXResourceReader rr = new System.Resources.ResXResourceReader(respath);
            var dict = rr.GetEnumerator();

            while (dict.MoveNext())
            {
                if (dict.Key.ToString() == "FILEPATH")
                {
                    Filepath = dict.Value.ToString();
                }
                if (dict.Key.ToString() == "PASSWORD")
                {
                    pword = dict.Value.ToString();
                }
            }
            rr.Close();

            /*
             * try
             * {
             *  ManageReg();
             * }
             * catch
             * {
             *  MessageBox.Show("请使用管理员权限打开本应用。");
             *  Application.Current.Shutdown();
             * }
             */

            string path = System.IO.Path.GetDirectoryName(Filepath);

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
                FileStream fs = new FileStream(Filepath, FileMode.Append);
                fs.Close();
            }
        }
Example #2
0
        /// <summary>
        /// 创建Orc实例(from Stream)
        /// </summary>
        /// <param name="offsetX"></param>
        /// <param name="offsetY"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="resource"></param>
        /// <returns></returns>
        public static OrcUtil getInstance(int[] offsetX, int offsetY, int width, int height, Stream resource)
        {
            OrcUtil rtn = new OrcUtil();
            rtn.offsetX = offsetX;
            rtn.offsetY = offsetY;
            rtn.width = width;
            rtn.height = height;
            rtn.dict = new Dictionary<Bitmap, String>();

            System.Resources.ResXResourceReader resxReader = new System.Resources.ResXResourceReader(resource);
            IDictionaryEnumerator enumerator = resxReader.GetEnumerator();
            while (enumerator.MoveNext())
            {
                DictionaryEntry entry = (DictionaryEntry)enumerator.Current;
                rtn.dict.Add((Bitmap)entry.Value, (String)entry.Key);
            }
            return rtn;
        }
Example #3
0
        private void generateResourceMenuItem_Click(object sender, EventArgs e)
        {
            Point origStart = GetOriginalXY(selStartMousePos);
            Point origEnd   = GetOriginalXY(selEndMousePos);

            if (selStartMousePos.X != 0 || selStartMousePos.Y != 0)
            {
                int       top    = origStart.Y < origEnd.Y ? origStart.Y : origEnd.Y;
                int       left   = origStart.X < origEnd.X ? origStart.X : origEnd.X;
                int       width  = Math.Abs(origEnd.X - origStart.X);
                int       height = Math.Abs(origEnd.Y - origStart.Y);
                Rectangle box    = new Rectangle(left, top, width, height);
                Bitmap    bitmap = ((Bitmap)image).Clone(box, ((Bitmap)image).PixelFormat);

                if (Statics.DTE.Solution.IsOpen)
                {
                    foreach (EnvDTE.Project proj in Statics.DTE.Solution.Projects)
                    {
                        if (proj.Name.Contains("Test"))
                        {
                            try
                            {
                                ImageInputForm inputForm = new ImageInputForm();
                                inputForm.ShowDialog();

                                Microsoft.CSharp.CSharpCodeProvider codeProvider = new Microsoft.CSharp.CSharpCodeProvider();
                                string resFile       = Path.GetDirectoryName(proj.FileName) + @"\Properties\Resources.resx";
                                string resDesginFile = Path.GetDirectoryName(proj.FileName) + @"\Properties\Resources.Designer.cs";
                                System.Resources.ResXResourceReader reader = new System.Resources.ResXResourceReader(resFile);
                                using (System.Resources.ResXResourceWriter writer = new System.Resources.ResXResourceWriter(resFile + ".new"))
                                {
                                    System.Collections.IDictionaryEnumerator iterator = reader.GetEnumerator();
                                    while (iterator.MoveNext())
                                    {
                                        writer.AddResource(iterator.Key.ToString(), iterator.Value);
                                    }
                                    writer.AddResource(inputForm.Input, bitmap);
                                    writer.Generate();
                                }
                                File.Copy(resFile + ".new", resFile, true);
                                File.Delete(resFile + ".new");
                                string[] unMatched;
                                System.CodeDom.CodeCompileUnit unit = System.Resources.Tools.StronglyTypedResourceBuilder.Create(resFile, "Resources",
                                                                                                                                 proj.Properties.Item("DefaultNamespace").Value + ".Properties",
                                                                                                                                 codeProvider,
                                                                                                                                 true, out unMatched);
                                using (StreamWriter designWriter = new StreamWriter(resDesginFile))
                                {
                                    codeProvider.GenerateCodeFromCompileUnit(unit, designWriter,
                                                                             new System.CodeDom.Compiler.CodeGeneratorOptions());
                                }
                                MessageBox.Show("Image generation succeeded", "Resources Updated");
                                return;
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show("Image generation failed\n" + ex.Message, "Resources Did Not Update");
                            }
                        }
                    }
                    MessageBox.Show("You need to have a project open, named *Test*", "Resources Did Not Update");
                    return;
                }
                MessageBox.Show("You need to have a solution open with a project named *Test*", "Resources Did Not Update");
                return;
            }
        }
Example #4
0
        private void CreateResourceFromImage(bool entire)
        {
            Bitmap bitmap = null;

            if (entire)
            {
                bitmap = (Bitmap)(zoomPanControl.ZoomPanImage.Clone());
            }
            else if (HasImageSelection && !entire)
            {
                bitmap = ((Bitmap)zoomPanControl.ZoomPanImage).Clone(partBox, ((Bitmap)zoomPanControl.ZoomPanImage).PixelFormat);
            }
            if (bitmap != null)
            {
                if (Statics.DTE.Solution.IsOpen)
                {
                    foreach (EnvDTE.Project proj in Statics.DTE.Solution.Projects)
                    {
                        if (proj.Name.Contains("Test"))
                        {
                            try
                            {
                                string resFile, resDesignFile, resNameSpace;
                                System.CodeDom.Compiler.CodeDomProvider provider;
                                if (proj.FileName.EndsWith("vbproj"))
                                {
                                    resFile       = Path.GetDirectoryName(proj.FileName) + @"\My Project\Resources.resx";
                                    resDesignFile = Path.GetDirectoryName(proj.FileName) + @"\My Project\Resources.Designer.vb";
                                    vbNS          = resNameSpace = proj.Properties.Item("RootNamespace").Value.ToString();
                                    provider      = new Microsoft.VisualBasic.VBCodeProvider();
                                }
                                else
                                {
                                    resFile       = Path.GetDirectoryName(proj.FileName) + @"\Properties\Resources.resx";
                                    resDesignFile = Path.GetDirectoryName(proj.FileName) + @"\Properties\Resources.Designer.cs";
                                    resNameSpace  = proj.Properties.Item("DefaultNamespace").Value + ".Properties";
                                    provider      = new Microsoft.CSharp.CSharpCodeProvider();
                                }
                                ImageInputForm inputForm = new ImageInputForm();
                                inputForm.ShowDialog();

                                System.Resources.ResXResourceReader reader = new System.Resources.ResXResourceReader(resFile);
                                using (System.Resources.ResXResourceWriter writer = new System.Resources.ResXResourceWriter(resFile + ".new"))
                                {
                                    System.Collections.IDictionaryEnumerator iterator = reader.GetEnumerator();
                                    while (iterator.MoveNext())
                                    {
                                        writer.AddResource(iterator.Key.ToString(), iterator.Value);
                                    }
                                    writer.AddResource(inputForm.Input, bitmap);
                                    writer.Generate();
                                }
                                File.Copy(resFile + ".new", resFile, true);
                                File.Delete(resFile + ".new");
                                string[] unMatched;
                                System.CodeDom.CodeCompileUnit unit = System.Resources.Tools.StronglyTypedResourceBuilder.Create(resFile, "Resources",
                                                                                                                                 resNameSpace,
                                                                                                                                 provider,
                                                                                                                                 true, out unMatched);
                                using (StreamWriter designWriter = new StreamWriter(resDesignFile))
                                {
                                    provider.GenerateCodeFromCompileUnit(unit, designWriter,
                                                                         new System.CodeDom.Compiler.CodeGeneratorOptions());
                                }
                                MessageBox.Show("Image generation succeeded", "Resources Updated");
                                if (entire)
                                {
                                    entireResName = inputForm.Input;
                                    NotifyPropertyChanged("EntireResName");
                                }
                                else
                                {
                                    partResName = inputForm.Input;
                                    NotifyPropertyChanged("PartialResName");
                                }

                                return;
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show("Image generation failed\n" + ex.Message, "Resources Did Not Update");
                                return;
                            }
                        }
                    }
                    MessageBox.Show("You need to have a project open, named *Test*", "Resources Did Not Update");
                    return;
                }
                MessageBox.Show("You need to have a solution open with a project named *Test*", "Resources Did Not Update");
                return;
            }
        }