コード例 #1
0
ファイル: MainForm.cs プロジェクト: Jaofeng/SaveCopier
        private void GameButton_UploadClick(object sender, EventArgs e)
        {
            GameButton gb = (GameButton)sender;

            gb.UploadButtonEnabled = false;
            Application.DoEvents();
            GameInfo gi = Program.Games[gb.Tag.ToString()];

            if (gi == null || !gi.HasSave)
            {
                return;
            }
            using (CopyForm cf = new CopyForm(_LoginedUserID, false))
            {
                cf.GameInfo = gi;
                DialogResult dr = cf.ShowDialog(this);
                switch (dr)
                {
                case DialogResult.OK:
                    MessageBox.Show("遊戲進度資料檔已上傳完畢!!", _CaptionText, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    break;

                case DialogResult.Abort:
                    MessageBox.Show("找不到遊戲進度儲存目錄,無法備份進度檔!!", _CaptionText, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    break;

                default:
                    MessageBox.Show("遊戲進度資料檔尚未備份完畢,請重新上傳!!", _CaptionText, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    break;
                }
                gb.UploadButtonEnabled = true;
            }
        }
コード例 #2
0
ファイル: MainForm.cs プロジェクト: Jaofeng/SaveCopier
        private void GameButton_DownloadClick(object sender, EventArgs e)
        {
            GameButton gb = (GameButton)sender;

            gb.DownloadButtonEnabled = false;
            Application.DoEvents();
            GameInfo gi = Program.Games[gb.Tag.ToString()];

            if (gi == null || !gi.HasSave)
            {
                return;
            }
            string userSavesPath = Path.Combine(Path.Combine(Program.Config["SavesPath"], gi.ID), _LoginedUserID);

            if (!Directory.Exists(userSavesPath))
            {
                MessageBox.Show("您沒有備份此遊戲進度資料!!", _CaptionText, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                CopyForm cf = new CopyForm(_LoginedUserID, true);
                cf.GameInfo = gi;
                if (cf.ShowDialog(this) == DialogResult.OK)
                {
                    MessageBox.Show("遊戲進度資料檔已下載完畢!!", _CaptionText, MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("遊戲進度資料檔尚未下載完畢,請重新下載!!", _CaptionText, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
            gb.DownloadButtonEnabled = true;
        }
コード例 #3
0
ファイル: MainForm.cs プロジェクト: Jaofeng/SaveCopier
        private void GameButton_Click(object sender, EventArgs e)
        {
            GameButton gb = (GameButton)sender;
            GameInfo   gi = Program.Games[gb.Tag.ToString()];

            if (gi == null)
            {
                return;
            }
            string fn    = gi.Exec;
            string gPath = gi.Path;

            if (string.IsNullOrEmpty(gPath))
            {
                gPath = Path.Combine(_GameRoot, gi.ID);
            }
            //else
            //    gPath = gPath.Replace("%GameRoot%", _GameRoot);
            //fn = fn.Replace("%Game%", gPath);
            if (!Path.IsPathRooted(fn))
            {
                fn = Path.Combine(gPath, fn);
            }
            if (!File.Exists(fn))
            {
                MessageBox.Show(string.Format("找不到遊戲 \"{0}\" 的執行檔或捷徑檔!!", gi.Name), _CaptionText, MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }
            else
            {
                try
                {
                    ProcessStartInfo psi = new ProcessStartInfo(fn);
                    psi.WorkingDirectory = gPath;
                    Process.Start(psi);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(string.Format("發生錯誤!!\n\n{0}", ex.Message), _CaptionText, MessageBoxButtons.OK, MessageBoxIcon.Stop);
                }
            }
        }
コード例 #4
0
ファイル: MainForm.cs プロジェクト: Jaofeng/SaveCopier
        private void ShowGameList(MenuInfo mi)
        {
            panRight.Hide();
            Application.DoEvents();
            labClass.Text = mi.Name;
            panGame.Controls.Clear();
            Application.DoEvents();
            LinkLabel lnk = new LinkLabel();

            lnk.Name     = "lnkGame";
            lnk.Location = new Point(0, -100);
            lnk.Text     = "None";
            panGame.Controls.Add(lnk);
            GameButton      gb  = null;
            List <GameInfo> lgi = Program.Games.FindAll(gi => gi.MenuID.Equals(mi.ID, StringComparison.OrdinalIgnoreCase));

            lgi.Sort((g1, g2) => g1.Sort.CompareTo(g2.Sort));
            foreach (GameInfo gi in lgi)
            {
                gb             = new GameButton();
                gb.Text        = gi.Name;
                gb.Name        = string.Format("gb_{0}", gi.ID.Replace(" ", "_"));
                gb.MouseEnter += new EventHandler(MenuItem_MouseEnter);
                gb.Font        = _MenuFont;
                gb.ForeColor   = _MenuTextColor;
                gb.BackColor   = _MenuBackColor;
                gb.Click      += new EventHandler(GameButton_Click);
                gb.Dock        = DockStyle.Top;
                gb.Height      = _GameItemHeight;
                gb.Tag         = gi.ID;

                #region 處理圖示
                if (!string.IsNullOrEmpty(gi.Icon))
                {
                    string iconPath  = string.Empty;
                    int    iconIndex = 0;
                    if (gi.Icon.IndexOf(',') != -1)
                    {
                        string[] sp = gi.Icon.Split(',');
                        iconPath = sp[0];
                        int.TryParse(sp[1], out iconIndex);
                    }
                    else
                    {
                        iconPath = gi.Icon;
                    }
                    //iconPath = iconPath.Replace("%Game%", gi.Path);
                    if (!Path.IsPathRooted(iconPath))
                    {
                        iconPath = Path.Combine(_IconPath, iconPath);
                    }
                    Image img = null;
                    if (File.Exists(iconPath))
                    {
                        string[] mime = GameInfo.MimeType(iconPath).ToLower().Split('/');

                        switch (mime[0])
                        {
                        case "application":
                        {
                            Icon[] icons = IconHandler.IconsFromFile(iconPath, IconSize.Large);
                            if (icons != null && icons.Length != 0)
                            {
                                if (icons.Length <= iconIndex)
                                {
                                    img = icons[0].ToBitmap();
                                }
                                else
                                {
                                    img = icons[iconIndex].ToBitmap();
                                }
                            }
                            break;
                        }

                        case "image":
                        {
                            switch (mime[1])
                            {
                            case "x-icon":
                            {
                                Size s = Size.Empty;
                                if (_IconAreaWidth > gb.Height)
                                {
                                    s = new Size(gb.Height, gb.Height);
                                }
                                else
                                {
                                    s = new Size(_IconAreaWidth, _IconAreaWidth);
                                }
                                img = new Icon(iconPath, s).ToBitmap();
                                break;
                            }

                            default:
                                img = Image.FromFile(iconPath);
                                break;
                            }
                            break;
                        }
                        }
                    }
                    if (img != null)
                    {
                        gb.IconWidth = _IconAreaWidth;
                        gb.Icon      = img;
                        gb.ShowIcon  = true;
                    }
                }
                #endregion

                #region 處理上/下傳按鍵
                gb.ShowSaveButton = gi.HasSave;
                if (gi.HasSave)
                {
                    gb.UploadButtonText      = "上傳進度";
                    gb.UploadButtonFont      = new Font("新細明體", 9);
                    gb.UploadButtonImage     = global::SaveCopier.Properties.Resources.Previous;
                    gb.UploadButtonEnabled   = !string.IsNullOrEmpty(_LoginedUserID);
                    gb.UploadClick          += new EventHandler(GameButton_UploadClick);
                    gb.DownloadButtonText    = "下載進度";
                    gb.DownloadButtonFont    = new Font("新細明體", 9);
                    gb.DownloadButtonImage   = global::SaveCopier.Properties.Resources.Next;
                    gb.DownloadButtonEnabled = !string.IsNullOrEmpty(_LoginedUserID);
                    gb.DownloadClick        += new EventHandler(GameButton_DownloadClick);
                    gb.SaveButtonWidth       = _SaveButtonWidth;
                }
                #endregion

                panGame.Controls.Add(gb);
                gb.BringToFront();
                Application.DoEvents();
            }
            panRight.Show();
            Application.DoEvents();
            panGame.Focus();
        }