public static string appKey; //腾讯翻译君API 密钥

        public static void TencentTrans_Init()
        {
            appId  = IniFileHelper.ReadItemValue(Environment.CurrentDirectory + "\\settings.ini", "TencentTranslator", "appID");
            appKey = IniFileHelper.ReadItemValue(Environment.CurrentDirectory + "\\settings.ini", "TencentTranslator", "appKey");
        }
        private void PartCombox_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (openflag != true)
            {
                if (lastPartChoose == 0)
                {
                    IniFileHelper.WriteValue(Environment.CurrentDirectory + "\\settings.ini", "TranslateFormSettings", "srcTextColorR", "" + ColorRTrackBar.Value);
                    IniFileHelper.WriteValue(Environment.CurrentDirectory + "\\settings.ini", "TranslateFormSettings", "srcTextColorG", "" + ColorGTrackBar.Value);
                    IniFileHelper.WriteValue(Environment.CurrentDirectory + "\\settings.ini", "TranslateFormSettings", "srcTextColorB", "" + ColorBTrackBar.Value);
                    IniFileHelper.WriteValue(Environment.CurrentDirectory + "\\settings.ini", "TranslateFormSettings", "srcTextFont", FontsCombox.Text);
                    IniFileHelper.WriteValue(Environment.CurrentDirectory + "\\settings.ini", "TranslateFormSettings", "srcTextsize", "" + TextSizeBox.Num);
                }
                else if (lastPartChoose == 1)
                {
                    IniFileHelper.WriteValue(Environment.CurrentDirectory + "\\settings.ini", "TranslateFormSettings", "firstTransTextColorR", "" + ColorRTrackBar.Value);
                    IniFileHelper.WriteValue(Environment.CurrentDirectory + "\\settings.ini", "TranslateFormSettings", "firstTransTextColorG", "" + ColorGTrackBar.Value);
                    IniFileHelper.WriteValue(Environment.CurrentDirectory + "\\settings.ini", "TranslateFormSettings", "firstTransTextColorB", "" + ColorBTrackBar.Value);
                    IniFileHelper.WriteValue(Environment.CurrentDirectory + "\\settings.ini", "TranslateFormSettings", "firstTransTextFont", FontsCombox.Text);
                    IniFileHelper.WriteValue(Environment.CurrentDirectory + "\\settings.ini", "TranslateFormSettings", "firstTransTextsize", "" + TextSizeBox.Num);
                }
                else if (lastPartChoose == 2)
                {
                    IniFileHelper.WriteValue(Environment.CurrentDirectory + "\\settings.ini", "TranslateFormSettings", "secondTransTextColorR", "" + ColorRTrackBar.Value);
                    IniFileHelper.WriteValue(Environment.CurrentDirectory + "\\settings.ini", "TranslateFormSettings", "secondTransTextColorG", "" + ColorGTrackBar.Value);
                    IniFileHelper.WriteValue(Environment.CurrentDirectory + "\\settings.ini", "TranslateFormSettings", "secondTransTextColorB", "" + ColorBTrackBar.Value);
                    IniFileHelper.WriteValue(Environment.CurrentDirectory + "\\settings.ini", "TranslateFormSettings", "secondTransTextFont", FontsCombox.Text);
                    IniFileHelper.WriteValue(Environment.CurrentDirectory + "\\settings.ini", "TranslateFormSettings", "secondTransTextsize", "" + TextSizeBox.Num);
                }

                if (PartCombox.SelectedIndex == 0)
                {
                    ColorRTrackBar.Value = int.Parse(IniFileHelper.ReadItemValue(Environment.CurrentDirectory + "\\settings.ini", "TranslateFormSettings", "srcTextColorR", "0"));
                    ColorGTrackBar.Value = int.Parse(IniFileHelper.ReadItemValue(Environment.CurrentDirectory + "\\settings.ini", "TranslateFormSettings", "srcTextColorG", "0"));
                    ColorBTrackBar.Value = int.Parse(IniFileHelper.ReadItemValue(Environment.CurrentDirectory + "\\settings.ini", "TranslateFormSettings", "srcTextColorB", "0"));
                    FontsCombox.Text     = IniFileHelper.ReadItemValue(Environment.CurrentDirectory + "\\settings.ini", "TranslateFormSettings", "srcTextFont", "微软雅黑");
                    TextSizeBox.Num      = int.Parse(IniFileHelper.ReadItemValue(Environment.CurrentDirectory + "\\settings.ini", "TranslateFormSettings", "srcTextsize", "12"));
                }
                else if (PartCombox.SelectedIndex == 1)
                {
                    ColorRTrackBar.Value = int.Parse(IniFileHelper.ReadItemValue(Environment.CurrentDirectory + "\\settings.ini", "TranslateFormSettings", "firstTransTextColorR", "0"));
                    ColorGTrackBar.Value = int.Parse(IniFileHelper.ReadItemValue(Environment.CurrentDirectory + "\\settings.ini", "TranslateFormSettings", "firstTransTextColorG", "0"));
                    ColorBTrackBar.Value = int.Parse(IniFileHelper.ReadItemValue(Environment.CurrentDirectory + "\\settings.ini", "TranslateFormSettings", "firstTransTextColorB", "0"));
                    FontsCombox.Text     = IniFileHelper.ReadItemValue(Environment.CurrentDirectory + "\\settings.ini", "TranslateFormSettings", "firstTransTextFont", "微软雅黑");
                    TextSizeBox.Num      = int.Parse(IniFileHelper.ReadItemValue(Environment.CurrentDirectory + "\\settings.ini", "TranslateFormSettings", "firstTransTextsize", "12"));
                }
                else if (PartCombox.SelectedIndex == 2)
                {
                    ColorRTrackBar.Value = int.Parse(IniFileHelper.ReadItemValue(Environment.CurrentDirectory + "\\settings.ini", "TranslateFormSettings", "secondTransTextColorR", "0"));
                    ColorGTrackBar.Value = int.Parse(IniFileHelper.ReadItemValue(Environment.CurrentDirectory + "\\settings.ini", "TranslateFormSettings", "secondTransTextColorG", "0"));
                    ColorBTrackBar.Value = int.Parse(IniFileHelper.ReadItemValue(Environment.CurrentDirectory + "\\settings.ini", "TranslateFormSettings", "secondTransTextColorB", "0"));
                    FontsCombox.Text     = IniFileHelper.ReadItemValue(Environment.CurrentDirectory + "\\settings.ini", "TranslateFormSettings", "secondTransTextFont", "微软雅黑");
                    TextSizeBox.Num      = int.Parse(IniFileHelper.ReadItemValue(Environment.CurrentDirectory + "\\settings.ini", "TranslateFormSettings", "secondTransTextsize", "12"));
                }

                lastPartChoose = PartCombox.SelectedIndex;
            }
            else
            {
                openflag = false;
            }
        }
Пример #3
0
        public static string SecretKey; //腾讯旧版API SecretKey

        public static void TencentOldTrans_Init()
        {
            SecretId  = IniFileHelper.ReadItemValue(Environment.CurrentDirectory + "\\settings.ini", "TencentOldTranslator", "SecretId");
            SecretKey = IniFileHelper.ReadItemValue(Environment.CurrentDirectory + "\\settings.ini", "TencentOldTranslator", "SecretKey");
        }
        public static string secretKey; //百度翻译API 的密钥

        public static void BaiduTrans_Init()
        {
            appId     = IniFileHelper.ReadItemValue(Environment.CurrentDirectory + "\\settings.ini", "BaiduTranslator", "appID");
            secretKey = IniFileHelper.ReadItemValue(Environment.CurrentDirectory + "\\settings.ini", "BaiduTranslator", "secretKey");
        }
Пример #5
0
        /*
         *
         *
         * const int WM_NCHITTEST = 0x0084;
         * const int HTLEFT = 10;
         * const int HTRIGHT = 11;
         * const int HTTOP = 12;
         * const int HTTOPLEFT = 13;
         * const int HTTOPRIGHT = 14;
         * const int HTBOTTOM = 15;
         * const int HTBOTTOMLEFT = 0x10;
         * const int HTBOTTOMRIGHT = 17;
         * protected override void WndProc(ref Message m)
         * {
         *  base.WndProc(ref m);
         *  switch (m.Msg)
         *  {
         *      case WM_NCHITTEST:
         *          Point vPoint = new Point((int)m.LParam & 0xFFFF,
         *              (int)m.LParam >> 16 & 0xFFFF);
         *          vPoint = PointToClient(vPoint);
         *          if (vPoint.X <= 5)
         *              if (vPoint.Y <= 5)
         *                  m.Result = (IntPtr)HTTOPLEFT;
         *              else if (vPoint.Y >= ClientSize.Height - 5)
         *                  m.Result = (IntPtr)HTBOTTOMLEFT;
         *              else m.Result = (IntPtr)HTLEFT;
         *          else if (vPoint.X >= ClientSize.Width - 5)
         *              if (vPoint.Y <= 5)
         *                  m.Result = (IntPtr)HTTOPRIGHT;
         *              else if (vPoint.Y >= ClientSize.Height - 5)
         *                  m.Result = (IntPtr)HTBOTTOMRIGHT;
         *              else m.Result = (IntPtr)HTRIGHT;
         *          else if (vPoint.Y <= 5)
         *              m.Result = (IntPtr)HTTOP;
         *          else if (vPoint.Y >= ClientSize.Height - 5)
         *              m.Result = (IntPtr)HTBOTTOM;
         *          break;
         *  }
         * }
         *
         * [DllImport("user32.dll")]
         * public static extern bool ReleaseCapture();
         * [DllImport("user32.dll")]
         * public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
         * public const int WM_SYSCOMMAND = 0x0112;
         * public const int SC_MOVE = 0xF010;
         * public const int HTCAPTION = 0x0002;
         */
        /*
         * //之前的窗口改变大小部分代码,已弃用
         * private void GameTranslateForm_Move(object sender, EventArgs e)
         * {
         *  ReleaseCapture();
         *
         *  SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
         *
         * }
         */
        /*
         * //之前的窗口拖动部分代码,已弃用
         * private void TransparentPanel_MouseDown(object sender, MouseEventArgs e)
         * {
         *  mouse_offset = new Point(-e.X, -e.Y);
         * }
         *
         * private void TransparentPanel_MouseMove(object sender, MouseEventArgs e)
         * {
         *
         *  if (e.Button == MouseButtons.Left)
         *  {
         *      Point mousePos = Control.MousePosition;
         *      mousePos.Offset(mouse_offset.X, mouse_offset.Y);
         *      Location = mousePos;
         *  }
         *
         * }
         */


        /// <summary>
        /// 自动进行游戏翻译
        /// 检查是否设置了分行翻译、去掉一些乱码类型的符号、检查是否空文本
        /// </summary>
        /// <param name="text"></param>
        /// <param name="srcLang"></param>
        /// <param name="desLang"></param>
        public void GameTranslateAuto(string text, string srcLang, string desLang)
        {
            //先检查玩家是否设置了分行翻译
            bool eachRowTrans = Convert.ToBoolean(IniFileHelper.WriteValue(Environment.CurrentDirectory + "\\settings.ini", "Translate_All", "EachRowTrans", "True"));

            if (eachRowTrans == false)
            {
                text = text.Replace("<br>", "").Replace("</br>", "").Replace("\n", "").Replace("\t", "").Replace("\r", "");
            }

            //处理:去掉一些乱码类型的符号
            text = text.Replace("_", "").Replace("-", "").Replace("+", "");

            string currentAPI;
            string ret = "";

            for (int i = 1; i <= 2; i++)
            {
                if (i == 1)
                {
                    currentAPI = firstTransAPI;
                }
                else
                {
                    currentAPI = secondTransAPI;
                }

                if (text == "")
                {
                    ret = "";
                }
                else
                {
                    if (currentAPI == "BaiduTranslator")
                    {
                        ret = BaiduTranslator.Baidu_Translate(text, desLang, srcLang);
                        if (ret == "Request Timeout")
                        {
                            ret = "[百度]翻译超时";
                        }
                        else
                        {
                            BaiduTransOutInfo oinfo = JsonConvert.DeserializeObject <BaiduTransOutInfo>(ret);
                            if (oinfo.trans_result != null)
                            {
                                ret = "";
                                for (int k = 0; k < oinfo.trans_result.Count; k++)
                                {
                                    ret = ret + oinfo.trans_result[k].dst + "\n";
                                }
                            }
                            else
                            {
                                ret = "[百度]翻译错误";
                            }
                        }
                    }
                    else if (currentAPI == "TencentTranslator")
                    {
                        ret = TencentTranslator.Fanyijun_Translate(text, desLang, srcLang);
                        if (ret == "Request Timeout")
                        {
                            ret = "[腾讯]翻译超时";
                        }
                        else
                        {
                            TencentTransOutInfo oinfo = JsonConvert.DeserializeObject <TencentTransOutInfo>(ret);
                            if (oinfo.data != null)
                            {
                                ret = oinfo.data.target_text;
                            }
                            else
                            {
                                ret = "[腾讯]翻译错误";
                            }
                        }
                    }
                    else if (currentAPI == "JBjTranslator")
                    {
                        ret = JBeijingTranslator.Translate_JapanesetoChinese(text);
                        if (ret == null || ret == "")
                        {
                            ret = "";
                        }
                    }
                    else if (currentAPI == "TencentOldTranslator")
                    {
                        ret = TencentOldTranslator.TencentOld_Translate(text, desLang, srcLang);
                        if (ret == "Request Timeout")
                        {
                            ret = "[腾讯旧]翻译超时";
                        }
                        else
                        {
                            TencentOldTransOutInfo oinfo = JsonConvert.DeserializeObject <TencentOldTransOutInfo>(ret);
                            if (oinfo.Response.TargetText != null)
                            {
                                ret = oinfo.Response.TargetText;
                            }
                            else
                            {
                                ret = "[腾讯旧]翻译错误";
                            }
                        }
                    }
                    else
                    {
                        ret = "";
                    }
                }

                if (i == 1)
                {
                    firstTransText = ret;
                }
                else
                {
                    secondTransText = ret;
                }
            }
        }
Пример #6
0
 private void EachRowTransCheckBox_CheckedChangeEvent(object sender, EventArgs e)
 {
     IniFileHelper.WriteValue(Environment.CurrentDirectory + "\\settings.ini", "Translate_All", "EachRowTrans", Convert.ToString(EachRowTransCheckBox.Checked));
 }
Пример #7
0
 private void AutoHookCheckBox_CheckedChangeEvent(object sender, EventArgs e)
 {
     IniFileHelper.WriteValue(Environment.CurrentDirectory + "\\settings.ini", "Textractor", "AutoHook", Convert.ToString(AutoHookCheckBox.Checked));
 }
Пример #8
0
 private void SecondTransCombox_SelectedChangedEvent(object sender, EventArgs e)
 {
     IniFileHelper.WriteValue(Environment.CurrentDirectory + "\\settings.ini", "Translate_All", "SecondTranslator", SecondTransCombox.SelectedValue);
 }
        /// <summary>
        /// 背景窗口的静态方法,用于显示一个背景窗口
        /// </summary>
        /// <param name="frmTop">与其叠加的前景窗口</param>
        public static void Show(GameTranslateForm frmTop)
        {
            //弹出菜单设置
            MaterialSkin.Controls.MaterialContextMenuStrip FunMenuStrip = new MaterialSkin.Controls.MaterialContextMenuStrip();
            ToolStripMenuItem LockItem           = new ToolStripMenuItem();
            ToolStripMenuItem SettingsItem       = new ToolStripMenuItem();
            ToolStripMenuItem ReNewOCRItem       = new ToolStripMenuItem();
            ToolStripMenuItem HistoryTextItem    = new ToolStripMenuItem();
            ToolStripMenuItem ExitTransFrmItem   = new ToolStripMenuItem();
            ToolStripMenuItem ShowsrcTextFrmItem = new ToolStripMenuItem();

            FunMenuStrip.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))));
            FunMenuStrip.Depth     = 0;
            FunMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
                LockItem,
                SettingsItem,
                ReNewOCRItem,
                HistoryTextItem,
                ShowsrcTextFrmItem,
                ExitTransFrmItem
            });
            FunMenuStrip.MouseState      = MaterialSkin.MouseState.HOVER;
            FunMenuStrip.ShowImageMargin = false;
            FunMenuStrip.Size            = new System.Drawing.Size(156, 136);
            //
            // 加锁解锁
            //
            LockItem.Size   = new System.Drawing.Size(155, 22);
            LockItem.Text   = "加锁/解锁";
            LockItem.Click += LockItem_Click;
            //
            // 设置
            //
            SettingsItem.Size   = new System.Drawing.Size(155, 22);
            SettingsItem.Text   = "设置";
            SettingsItem.Click += SettingsItem_Click;
            //
            // 刷新OCRToolStripMenuItem
            //
            ReNewOCRItem.Size   = new System.Drawing.Size(155, 22);
            ReNewOCRItem.Text   = "刷新OCR";
            ReNewOCRItem.Click += ReNewOCRItem_Click;
            //
            // 历史文本ToolStripMenuItem
            //
            HistoryTextItem.Size   = new System.Drawing.Size(155, 22);
            HistoryTextItem.Text   = "历史文本";
            HistoryTextItem.Click += HistoryTextItem_Click;
            //
            // 退出翻译ToolStripMenuItem
            //
            ExitTransFrmItem.Size   = new System.Drawing.Size(155, 22);
            ExitTransFrmItem.Text   = "退出翻译";
            ExitTransFrmItem.Click += ExitTransFrmItem_Click;
            //
            // 显示原文ToolStripMenuItem
            //
            ShowsrcTextFrmItem.Size   = new System.Drawing.Size(155, 22);
            ShowsrcTextFrmItem.Text   = "显示/隐藏原文";
            ShowsrcTextFrmItem.Click += ShowSrcTextItem_Click;


            top = frmTop;
            // 背景窗体设置
            GameTranslateBackForm frmBack = new GameTranslateBackForm();

            top.SetBackForm(frmBack);
            back = frmBack;

            double frmBackOpacity = (double)(double.Parse(
                                                 IniFileHelper.ReadItemValue(Environment.CurrentDirectory + "\\settings.ini", "TranslateFormSettings",
                                                                             "opacity", "50")) / 100);

            frmBack.Text            = "MisakaTranslator游戏翻译窗口";
            frmBack.FormBorderStyle = FormBorderStyle.None;
            frmBack.MaximizeBox     = false;

            int LocX  = int.Parse(IniFileHelper.ReadItemValue(Environment.CurrentDirectory + "\\settings.ini", "TranslateFormSettings", "LocX", "-1"));
            int LocY  = int.Parse(IniFileHelper.ReadItemValue(Environment.CurrentDirectory + "\\settings.ini", "TranslateFormSettings", "LocY", "-1"));
            int SizeW = int.Parse(IniFileHelper.ReadItemValue(Environment.CurrentDirectory + "\\settings.ini", "TranslateFormSettings", "SizeW", "-1"));
            int SizeH = int.Parse(IniFileHelper.ReadItemValue(Environment.CurrentDirectory + "\\settings.ini", "TranslateFormSettings", "SizeH", "-1"));

            if (LocX == -1 && LocY == -1)
            {
                frmBack.StartPosition = FormStartPosition.CenterScreen;
            }
            else
            {
                frmBack.Location      = new Point(LocX, LocY);
                frmBack.StartPosition = FormStartPosition.Manual;
                frmBack.Width         = SizeW;
                frmBack.Height        = SizeH;
            }

            frmBack.ShowIcon      = false;
            frmBack.ShowInTaskbar = false;
            frmBack.Opacity       = frmBackOpacity;
            string color = IniFileHelper.ReadItemValue(Environment.CurrentDirectory + "\\settings.ini", "TranslateFormSettings", "BackColor", "Noset");

            if (color == "Noset")
            {
                frmBack.BackColor = Color.LightGray;
            }
            else
            {
                frmBack.BackColor = Color.FromArgb(int.Parse(color));
            }

            frmBack.ContextMenuStrip = FunMenuStrip;

            // 顶部窗体设置
            frmTop.Owner = frmBack;

            frmBack.SizeChanged      += GameTranslateBackForm_SizeLocationChanged;
            frmBack.LocationChanged  += GameTranslateBackForm_SizeLocationChanged;
            frmBack.MouseDoubleClick += GameTranslateBackForm_DoubleClick;
            frmBack.FormClosing      += GameTranslateBackForm_FormClosing;

            frmBack.TopMost = true;
            frmTop.TopMost  = true;

            isLock        = true;
            isShowSrcText = true;

            // 显示窗体
            frmTop.Show();
            frmBack.Show();
        }