136 lines
4.3 KiB
C#
136 lines
4.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Text;
|
|
using System.IO;
|
|
using System.Windows.Forms;
|
|
|
|
namespace Formats
|
|
{
|
|
public partial class frmFormatCopy : Form
|
|
{
|
|
public frmFormatCopy()
|
|
{
|
|
InitializeComponent();
|
|
SetDefaults();
|
|
}
|
|
|
|
private void SetDefaults()
|
|
{
|
|
string curFolder = Environment.CurrentDirectory; // C:\development/PROMS/Formats/bin/debug
|
|
int idx = curFolder.ToUpper().IndexOf(@"\PROMS\");
|
|
txbxPROMSFormatsPath.Text = curFolder.Substring(0, idx);
|
|
}
|
|
|
|
// This will create the folders if they don't exist or clear the contents if they do.
|
|
private void ClearOrCreateDestinationFolders(string path)
|
|
{
|
|
DirectoryInfo di = new DirectoryInfo(path);
|
|
if (di.Exists == false) //return;
|
|
{
|
|
DialogResult dlgrslt = DialogResult.No;
|
|
dlgrslt = MessageBox.Show(string.Format("{0} does not exist. Create it?", path), "Create Folder?", MessageBoxButtons.YesNo);
|
|
if (dlgrslt == DialogResult.Yes)
|
|
{
|
|
di.Create();
|
|
di.CreateSubdirectory("fmtall");
|
|
di.CreateSubdirectory("genmacall");
|
|
}
|
|
else
|
|
return;
|
|
}
|
|
// clear the destination fmtall folder
|
|
FileInfo[] fis;
|
|
DirectoryInfo[] diAry = di.GetDirectories("fmtall");
|
|
DirectoryInfo di_fmtgen;
|
|
if (diAry.Length == 0)
|
|
di.CreateSubdirectory("fmtall");
|
|
else
|
|
{
|
|
// clear the destination fmtall folder
|
|
di_fmtgen = diAry[0];
|
|
fis = di_fmtgen.GetFiles("*.xml");
|
|
foreach (FileInfo fi in fis)
|
|
{
|
|
if (fi.IsReadOnly) fi.IsReadOnly = false;
|
|
fi.Delete();
|
|
}
|
|
}
|
|
diAry = di.GetDirectories("genmacall");
|
|
if (diAry.Length == 0)
|
|
di.CreateSubdirectory("genmacall");
|
|
else
|
|
{
|
|
// clear the destination genmacall folder
|
|
di_fmtgen = di.GetDirectories("genmacall")[0];
|
|
fis = di_fmtgen.GetFiles("*.svg");
|
|
foreach (FileInfo fi in fis)
|
|
{
|
|
if (fi.IsReadOnly) fi.IsReadOnly = false;
|
|
fi.Delete();
|
|
}
|
|
}
|
|
}
|
|
|
|
private void btnBrowse_Click(object sender, EventArgs e)
|
|
{
|
|
FolderBrowserDialog fbd = new FolderBrowserDialog();
|
|
|
|
fbd.SelectedPath = txbxPROMSFormatsPath.Text;
|
|
if (fbd.ShowDialog() == DialogResult.OK)
|
|
{
|
|
if (Directory.Exists(fbd.SelectedPath)) txbxPROMSFormatsPath.Text = fbd.SelectedPath + @"\";
|
|
}
|
|
if (!txbxPROMSFormatsPath.Text.EndsWith(@"\")) txbxPROMSFormatsPath.Text += @"\";
|
|
}
|
|
|
|
private void btnCopyFormats_Click(object sender, EventArgs e)
|
|
{
|
|
// make sure there is an ending back slash in the destination path
|
|
if (!txbxPROMSFormatsPath.Text.EndsWith(@"\")) txbxPROMSFormatsPath.Text += @"\";
|
|
|
|
// There should be a "fmtall" and "genmacall" folder in the delelopment project folder
|
|
// ex: C:\development\PROMS\Formats\fmtall and C:\development\PROMS\Formats\genmacall
|
|
string destFmtallPath = txbxPROMSFormatsPath.Text + @"fmtall\";
|
|
string destGenmacallPath = txbxPROMSFormatsPath.Text + @"genmacall\";
|
|
string srcFmtallPath = @"..\..\"; // up to levels from startup path
|
|
|
|
// clear the destination fmtall and genmacall folders
|
|
ClearOrCreateDestinationFolders(txbxPROMSFormatsPath.Text);
|
|
|
|
DirectoryInfo di = new DirectoryInfo(srcFmtallPath);
|
|
if (di.Exists == false) return;
|
|
// copy the fmtall format files
|
|
DirectoryInfo di_fmtgen = di.GetDirectories("fmtall")[0];
|
|
FileInfo[] fis = di_fmtgen.GetFiles("*.xml");
|
|
foreach (FileInfo fi in fis)
|
|
{
|
|
FileInfo fio = new FileInfo(destFmtallPath + fi.Name);
|
|
if (fio.Exists && fio.IsReadOnly) fio.IsReadOnly = false;
|
|
fi.CopyTo(fio.FullName, true);
|
|
fio = new FileInfo(destFmtallPath + fi.Name);
|
|
if (fio.Exists && fio.IsReadOnly) fio.IsReadOnly = false;
|
|
}
|
|
// copy the genmacall format files
|
|
di_fmtgen = di.GetDirectories("genmacall")[0];
|
|
fis = di_fmtgen.GetFiles("*.svg");
|
|
foreach (FileInfo fi in fis)
|
|
{
|
|
FileInfo fio = new FileInfo(destGenmacallPath + fi.Name);
|
|
if (fio.Exists && fio.IsReadOnly) fio.IsReadOnly = false;
|
|
fi.CopyTo(fio.FullName, true);
|
|
fio = new FileInfo(destGenmacallPath + fi.Name);
|
|
if (fio.Exists && fio.IsReadOnly) fio.IsReadOnly = false;
|
|
}
|
|
if(MessageBox.Show("Do you want to end the Format Copier?","Formats Copied.", MessageBoxButtons.YesNo, MessageBoxIcon.Question)== DialogResult.Yes)Application.Exit();
|
|
}
|
|
|
|
private void buttonX2_Click(object sender, EventArgs e)
|
|
{
|
|
Application.Exit();
|
|
}
|
|
|
|
}
|
|
} |