Exemple #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonUpdate_Click(object sender, EventArgs e)
        {
            if (false ||
                frmResult == null ||
                frmResult.Visible == false)
            {
                frmResult = new FormResult();
                frmResult.Show();
            }
            frmResult.GetListBoxResult.Items.Clear();
            //
            FileInfo      local_file = null;
            DirectoryInfo local_dir  = null;

            //
            for (int i = 0; i < checkedListBoxFrom.CheckedItems.Count; i++)
            {
                local_file = null;
                local_dir  = null;
                if (Directory.Exists(checkedListBoxFrom.CheckedItems[i].ToString()))
                {
                    local_dir = new DirectoryInfo(checkedListBoxFrom.CheckedItems[i].ToString());
                }
                else
                {
                    // ファイルは存在しない
                    if (File.Exists(checkedListBoxFrom.CheckedItems[i].ToString()) == false)
                    {
                        MessageBox.Show("[" + checkedListBoxFrom.CheckedItems[i].ToString() + "] は、存在しません。"
                                        , "アップデートするファイルが存在しません"
                                        , MessageBoxButtons.OK
                                        , MessageBoxIcon.Error);
                        continue;
                    }
                    local_file = new FileInfo(checkedListBoxFrom.CheckedItems[i].ToString());
                }
                for (int j = 0; j < checkedListBoxTo.CheckedItems.Count; j++)
                {
                    String local_result = "";
                    if (local_dir != null)
                    {
                        local_result = local_dir.FullName + System.Environment.NewLine
                                       + "  ->" + checkedListBoxTo.CheckedItems[j].ToString() + "\\" + local_dir.Name;
                        try
                        {
                            //MessageBox.Show("[" + local_info.FullName + "] から [" + checkedListBoxTo.CheckedItems[j].ToString() + "\\" + local_info.Name + "]");
                            MyFile.CopyDirectory(local_dir.FullName, checkedListBoxTo.CheckedItems[j].ToString() + "\\" + local_dir.Name);
                            local_result = "[OK]" + local_result;
                        }
                        catch (Exception)
                        {
                            local_result = "[NG]" + local_result;
                        }
                    }
                    else
                    {
                        local_result = local_file.FullName + System.Environment.NewLine
                                       + "  ->" + checkedListBoxTo.CheckedItems[j].ToString() + "\\" + local_file.Name;
                        try
                        {
                            //MessageBox.Show("[" + local_info.FullName + "] から [" + checkedListBoxTo.CheckedItems[j].ToString() + "\\" + local_info.Name + "]");
                            local_file.CopyTo(checkedListBoxTo.CheckedItems[j].ToString() + "\\" + local_file.Name, true);
                            local_result = "[OK]" + local_result;
                        }
                        catch (Exception)
                        {
                            local_result = "[NG]" + local_result;
                        }
                    }
                    if (frmResult != null)
                    {
                        frmResult.GetListBoxResult.Items.Add(local_result);
                    }
                }
            }
            MessageBox.Show("アップデートが終了しました。", "終了", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }