コード例 #1
0
ファイル: FormDownload.cs プロジェクト: rgunczer/QAB
        private void cmdDownload_Click(object sender, EventArgs e)
        {
            string downloadTo = Settings.Get("DownloadTo");

            if (string.IsNullOrEmpty(downloadTo))
            {
                UtilSys.MessageBox("Set download to location first");
                return;
            }

            m_downloadList.Clear();
            GetList(tvw.Nodes[0]);

            FrmProgress frmP = new FrmProgress();

            frmP.Text = "Downloading...";
            frmP.SetProgressMax(m_downloadList.Count);

            frmP.Show();
            frmP.Top  = Top + Height / 2;
            frmP.Left = (Left + Width / 2) - frmP.Width / 2;

            frmP.Update();

            Scripter.DoEvents();

            foreach (string item in m_downloadList)
            {
                string temp = Settings.Get("ServerIP");

                string[] arr = temp.Split(':');

                if (2 == arr.Length)
                {
                    frmP.Text = item;
                    frmP.UpdateProgress();

                    string ip   = arr[0];
                    int    port = Convert.ToInt32(arr[1]);

                    NetworkClient nc = new NetworkClient(ip, port);

                    string savePath = Path.Combine(downloadTo, item);
                    nc.DownloadFile(item, savePath);
                }
            }
            frmP.Close();
        }
コード例 #2
0
ファイル: Opener.cs プロジェクト: rgunczer/QAB
        public static void Open(string path, string filter)
        {
            if (string.IsNullOrEmpty(filter))
            {
                filter = "QABOT Script Files (*.scp)|*.scp|QABOT Script Import Modules (*.sci)|*.sci|QABOT Data Files (*.dat)|*.dat|QABOT Project Files (*.qpf)|*.qpf|QABOT Template Files (*.tem)|*.tem|All Files (*.*)|*.*";
            }

            if (string.IsNullOrEmpty(path))
            {
                path = UtilSys.OpenFileDialog("Open QABOT Script, Data or Template File", filter, LastOpenedFolder);
            }

            if (string.Empty == path)
            {
                return;
            }

            bool bOpened = false;

            // if the script is already opened in one of tabs
            // check if it is modified if yes, ask to save it?
            int    i      = 0;
            Editor editor = null;

            foreach (TabPage page in frm.tabFiles.TabPages)
            {
                editor = (Editor)page.Controls[0].Controls[0];

                Debug.Assert(null != editor);

                if (editor.Path2File == path)
                {
                    bOpened = true;
                    frm.tabFiles.SelectedIndex = i;
                    editor.Clear();
                    Application.DoEvents();
                    break;
                }
                ++i;
            }

            Stopwatch sw = new Stopwatch();

            sw.Start();

            string[] buffer = ScriptLoader.Load(frm, mru, path);

            if (null == buffer)
            {
                frm.UpdateMRUMenu();
                return;
            }

            LastOpenedFolder = Path.GetDirectoryName(path);

            FrmProgress frmP = new FrmProgress();

            frmP.Show();
            frmP.Top  = frm.Top + frm.Height / 2;
            frmP.Left = (frm.Left + frm.Width / 2) - frmP.Width / 2;

            frmP.SetProgressMax(buffer.Length);

            if (!bOpened)
            {
                frm.CreateNewDocument(path);
                editor = frm.CurrentEditor;
            }

            editor.Dirty   = false;
            editor.Loading = true;
            editor.SuspendLayout();

            bool IsCompatibilityChangeMade = false;

            string line = string.Empty;

            for (int j = 0; j < buffer.Length; ++j)
            {
                line = buffer[j];

                if (_bCompatibilty)
                {
                    line = CreateCompatibileLine(line);

                    if (line != buffer[j])
                    {
                        IsCompatibilityChangeMade = true;
                        Scripter.Output("Line(" + j.ToString() + ") changed from -> to: '" + buffer[j] + "' -> '" + line + "'");
                    }
                }
                editor.AddLine(line);
                frmP.UpdateProgress();
                frmP.Text = "Progress... (" + j + "/" + buffer.Length + ")";
            }

            editor.ResumeLayout();
            editor.Loading = false;
            editor.HandleBlockComments();
            editor.InitUndoStack();
            frmP.Close();

            if (!bOpened)
            {
                frm.tabFiles.SelectedIndex = frm.tabFiles.TabPages.Count - 1;
                frm.tabFiles.TabPages[frm.tabFiles.SelectedIndex].Focus();
                frm.UpdateDebugButtons();
            }

            editor.Dirty = IsCompatibilityChangeMade;

            frm.UpdateMRUMenu();
            frm.OnReParse();
            editor.Focus();

            sw.Stop();

            TimeSpan span = sw.Elapsed;

            Scripter.Output("Load Time: " + span.Hours + ":" + span.Minutes + ":" + span.Seconds + ":" + span.Milliseconds);
        }