﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CSOAudioChanger
{
    public partial class btnBrowse : Form
    {
        string CSOPath;
        string BinPath;
        string MP3Path = "";

        public btnBrowse()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            CSOPath = GetReg.GetCSOPath();
            BinPath = CSOPath + "\\Bin\\";
#if DEBUG
            MessageBox.Show(CSOPath);
#else
#endif
            txtPath.Text = CSOPath;
            txtPath.Select(0, 0); //Prevent select all automatically
        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            System.Diagnostics.Process.Start("http://nitroxenon.com");
        }

        private void button1_Click(object sender, EventArgs e)
        {
            dialog.ShowDialog();
                txtMp3Path.Text = dialog.FileName;
                MP3Path = txtMp3Path.Text;
        }

        private void btnEdit_Click(object sender, EventArgs e)
        {
            MP3Path = txtMp3Path.Text;

            if (!String.IsNullOrEmpty(MP3Path) && cbAudioType.SelectedIndex != -1)
            {
                Edit edit = new Edit(CSOPath, MP3Path, cbAudioType.SelectedIndex);
                bool success = edit.StartEdit();
            }
            else if (String.IsNullOrEmpty(MP3Path))
            {
                MessageBox.Show("請先選擇音效檔案");
            }
            else if (cbAudioType.SelectedIndex == -1)
            {
                MessageBox.Show("請先選擇欲修改之音效");
            }
            else
            {
                MessageBox.Show("無法進行修改!");
            }
        }

        private void btnBak_Click(object sender, EventArgs e)
        {
            Dictionary<int, string> AudioDict = new Dictionary<int, string>();
            AudioDict.Add(0, "CSOnline.mp3");
            AudioDict.Add(1, "CSO_Result.mp3");
            AudioDict.Add(2, "ZB4_start.mp3");
            AudioDict.Add(3, "ZE_Ambience.mp3");
            AudioDict.Add(4, "ZE_Ready.mp3");
            AudioDict.Add(5, "Zsh_start.mp3");
            AudioDict.Add(6, "Zsh_daybgm.mp3");
            AudioDict.Add(7, "Zsh_nightbgm.mp3");
            string tmpValue;
            AudioDict.TryGetValue(cbAudioType.SelectedIndex,out tmpValue);
            Backup bak = new Backup(BinPath,tmpValue);
            bak.Start();
        }

        private void btnRes_Click(object sender, EventArgs e)
        {
            Dictionary<int, string> AudioDict = new Dictionary<int, string>();
            AudioDict.Add(0, "CSOnline.mp3");
            AudioDict.Add(1, "CSO_Result.mp3");
            AudioDict.Add(2, "ZB4_start.mp3");
            AudioDict.Add(3, "ZE_Ambience.mp3");
            AudioDict.Add(4, "ZE_Ready.mp3");
            AudioDict.Add(5, "Zsh_start.mp3");
            AudioDict.Add(6, "Zsh_daybgm.mp3");
            AudioDict.Add(7, "Zsh_nightbgm.mp3");
            string tmpValue;
            AudioDict.TryGetValue(cbAudioType.SelectedIndex, out tmpValue);
            Restore res = new Restore(BinPath, tmpValue);
            res.Start();
        }

        private void btnChristmas_Click(object sender, EventArgs e)
        {
            if (cbAudioType.SelectedIndex != -1)
            {
                Edit edit = new Edit(CSOPath, Application.StartupPath + "\\files\\CSO_XMas_Intro.mp3", cbAudioType.SelectedIndex);
                bool success = edit.StartEdit();
            }
            else if (cbAudioType.SelectedIndex == -1)
            {
                MessageBox.Show("請先選擇欲修改之音效");
            }
        }
    }
}
