364 lines
8.4 KiB
C#
364 lines
8.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Drawing;
|
|
using System.IO;
|
|
using System.Reflection;
|
|
using System.Runtime.InteropServices;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using IniParser;
|
|
using IniParser.Model;
|
|
|
|
namespace StartApp
|
|
{
|
|
public partial class form_Main : Form
|
|
{
|
|
private List<CADVerInfo> m_cadLists = new List<CADVerInfo>();
|
|
|
|
private IniData m_iniData = null;
|
|
|
|
private CadType m_cadType { get; set; } = CadType.eCadType_NONE;
|
|
|
|
private string m_profilesName { get; set; }
|
|
|
|
private string m_shVersion { get; set; }
|
|
|
|
private string m_OEM { get; set; }
|
|
|
|
private int m_maxVer { get; set; } = 19;
|
|
|
|
private int m_minVer { get; set; } = 25;
|
|
|
|
private string m_cName { get; set; }
|
|
|
|
private string m_appVer { get; set; }
|
|
|
|
private string m_Version { get; set; }
|
|
|
|
private Bitmap m_bitmap { get; set; } = null;
|
|
|
|
private Icon m_icon { get; set; } = null;
|
|
|
|
public bool init()
|
|
{
|
|
if (!initIniData())
|
|
return false;
|
|
if (!initCADList())
|
|
return false;
|
|
|
|
setIcon();
|
|
initPicBox();
|
|
arrangeControls();
|
|
|
|
foreach (var info in m_cadLists)
|
|
listBox_CAD.Items.Add(info.m_sCADName);
|
|
|
|
if (m_cName != null && m_Version != null)
|
|
this.Text = m_cName + " " + m_Version;
|
|
|
|
return true;
|
|
}
|
|
|
|
public bool directStartCAD()
|
|
{
|
|
// 唯一的CAD版本,直接启动
|
|
if (m_cadLists.Count == 1)
|
|
{
|
|
startCAD(m_cadLists[0]);
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public form_Main()
|
|
{
|
|
InitializeComponent();
|
|
return;
|
|
}
|
|
|
|
private bool initCADList()
|
|
{
|
|
if (m_cadLists.Count != 0)
|
|
return true;
|
|
|
|
CADVerInfo.getCadList(ref m_cadLists, m_cadType, m_minVer, m_maxVer);
|
|
if (m_cadLists.Count == 0)
|
|
{
|
|
MessageBox.Show("没有找到可用的CAD版本");
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
private void getCadVersionList(ref List<string> lst)
|
|
{
|
|
string verCAD = string.Empty;
|
|
|
|
if (m_iniData["STARTAPP"].ContainsKey("CADVer"))
|
|
verCAD = m_iniData["STARTAPP"]["CADVer"];
|
|
|
|
string[] ar = verCAD.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
|
|
lst.AddRange(ar);
|
|
}
|
|
|
|
private bool initIniData()
|
|
{
|
|
var parser = new FileIniDataParser();
|
|
string inipath = @".\sys\product.ini";
|
|
m_iniData = File.Exists(inipath) ? parser.ReadFile(inipath, Encoding.Default) : null;
|
|
if (m_iniData == null)
|
|
{
|
|
MessageBox.Show("无法读取配置文件。");
|
|
return false;
|
|
}
|
|
|
|
m_profilesName = m_iniData["Product"]["ProfilesName"];
|
|
if (m_profilesName == null)
|
|
{
|
|
MessageBox.Show("无法获取配置名称。");
|
|
return false;
|
|
}
|
|
|
|
m_shVersion = m_iniData["Product"]["Version"];
|
|
if (m_shVersion == null)
|
|
{
|
|
MessageBox.Show("无法获取上华版本信息。");
|
|
return false;
|
|
}
|
|
|
|
// 判断一下是不是新版本的配置文件,判断 [STARTAPP]
|
|
if (m_iniData.Sections.ContainsSection("STARTAPP") && m_iniData["STARTAPP"].ContainsKey("CADVer"))
|
|
{
|
|
// 直接获取cad版本范围
|
|
List<string> cadVersionlst = new List<string>();
|
|
getCadVersionList(ref cadVersionlst);
|
|
if (cadVersionlst.Count == 0)
|
|
{
|
|
MessageBox.Show("新版本配置文件中无法获取cad版本列表。");
|
|
return false;
|
|
}
|
|
|
|
|
|
CADVerInfo.getCadList(ref m_cadLists, cadVersionlst);
|
|
|
|
if (m_cadLists.Count == 0)
|
|
{
|
|
MessageBox.Show("无法获取已安装的cad版本。");
|
|
return false;
|
|
}
|
|
|
|
}
|
|
else
|
|
{ // 兼容旧版本的配置文件,读取 [Product] 中的 CADVer
|
|
var obj = m_iniData["Product"]["CADVer"];
|
|
if (obj != null)
|
|
{
|
|
string[] array = obj.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
|
|
string sMax = string.Empty, sMin = string.Empty;
|
|
if (array.Length == 2)
|
|
{
|
|
m_cadType = CadType.eCadType_AutoCAD;
|
|
sMin = array[0];
|
|
sMax = array[1];
|
|
}
|
|
else if (array.Length == 3 && array[0] == "zw")
|
|
{
|
|
m_cadType = CadType.eCadType_ZWCAD;
|
|
sMin = array[1];
|
|
sMax = array[2];
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show("无法获取CAD类型信息。");
|
|
return false;
|
|
}
|
|
|
|
if (int.TryParse(sMin, out int min) && int.TryParse(sMax, out int max))
|
|
{
|
|
m_minVer = min;
|
|
m_maxVer = max;
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show("无法获取CAD版本范围信息。");
|
|
return false;
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show("无法获取CAD版本信息。");
|
|
return false;
|
|
}
|
|
}
|
|
|
|
m_cName = m_iniData["Product"]["CName"];
|
|
m_appVer = m_iniData["Product"]["APPVer"];
|
|
m_OEM = m_iniData["Product"]["OEM"];
|
|
m_Version = m_iniData["Product"]["Version"];
|
|
|
|
return true;
|
|
}
|
|
|
|
private void initPicBox()
|
|
{
|
|
string sBmp = string.Empty;
|
|
if (m_profilesName.Contains("EW"))// 管廊
|
|
{
|
|
if (m_OEM == "shcj")
|
|
sBmp = "StartApp.bmp.shcj.bmp";
|
|
else
|
|
sBmp = "StartApp.bmp.earthworm.bmp";
|
|
}
|
|
else if (m_profilesName.Contains("PP3D")) // 水处理
|
|
{
|
|
if (m_OEM == "shcj")
|
|
sBmp = "StartApp.bmp.shcj.bmp";
|
|
else
|
|
sBmp = "StartApp.bmp.PP3D.bmp";
|
|
}
|
|
else if (m_profilesName.Contains("ECR3D")) // 电缆敷设
|
|
{
|
|
sBmp = "StartApp.bmp.ECableRoute3d.bmp";
|
|
}
|
|
else if (m_profilesName.Contains("ME-RPBIM")) // 中交
|
|
{
|
|
sBmp = "StartApp.bmp.中交集团.bmp";
|
|
}
|
|
else if (m_profilesName.Contains("ME-RupCAD")) // 速建
|
|
{
|
|
sBmp = "StartApp.bmp.RupCAD.bmp";
|
|
}
|
|
else if (m_profilesName.Contains("ENV")) // 环境
|
|
{
|
|
sBmp = "StartApp.bmp.PP3D.bmp";
|
|
}
|
|
else
|
|
sBmp = "StartApp.bmp.PP3D.bmp";
|
|
|
|
if (string.IsNullOrEmpty(sBmp)) return;
|
|
|
|
using (Stream ss = Assembly.GetExecutingAssembly().GetManifestResourceStream(sBmp))
|
|
{
|
|
if (ss != null)
|
|
m_bitmap = new Bitmap(ss);
|
|
}
|
|
}
|
|
|
|
private void setIcon()
|
|
{
|
|
string sIcon = string.Empty;
|
|
if (m_profilesName.Contains("EW"))// 管廊
|
|
{
|
|
sIcon = "StartApp.bmp.earthworm.ico";
|
|
}
|
|
else if (m_profilesName.Contains("ECR3D")) // 电缆敷设
|
|
{
|
|
sIcon = "StartApp.bmp.ECR3D.ico";
|
|
}
|
|
else
|
|
{ // 默认
|
|
if (m_cadType == CadType.eCadType_ZWCAD)
|
|
sIcon = "StartApp.bmp.poolplant_zw.ico";
|
|
else
|
|
sIcon = "StartApp.bmp.PoolPlant3D.ico";
|
|
}
|
|
if (string.IsNullOrEmpty(sIcon)) return;
|
|
using (Stream ss = Assembly.GetExecutingAssembly().GetManifestResourceStream(sIcon))
|
|
{
|
|
if (ss != null)
|
|
m_icon = new Icon(ss);
|
|
}
|
|
|
|
if (m_icon != null)
|
|
this.Icon = m_icon;
|
|
}
|
|
|
|
private void startCAD(CADVerInfo cad)
|
|
{
|
|
var startInfo = new ProcessStartInfo
|
|
{
|
|
FileName = cad.m_sExeName,
|
|
Arguments = $"/p {m_profilesName}{m_shVersion}",
|
|
WorkingDirectory = cad.m_sCADLocation,
|
|
WindowStyle = ProcessWindowStyle.Maximized
|
|
};
|
|
try
|
|
{
|
|
using (Process pro = Process.Start(startInfo)) { }
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show(ex.Message);
|
|
}
|
|
}
|
|
|
|
private void button_ok_Click(object sender, EventArgs e)
|
|
{
|
|
int idx = listBox_CAD.SelectedIndex;
|
|
if (idx < 0 || idx >= m_cadLists.Count)
|
|
{
|
|
MessageBox.Show("请选择一个CAD版本。");
|
|
return;
|
|
}
|
|
|
|
startCAD(m_cadLists[idx]);
|
|
|
|
Close();
|
|
}
|
|
|
|
private void listBox_CAD_DoubleClick(object sender, EventArgs e)
|
|
{
|
|
button_ok_Click(sender, e);
|
|
}
|
|
|
|
private void pictureBox_Main_Paint(object sender, PaintEventArgs e)
|
|
{
|
|
if (m_bitmap == null) return;
|
|
|
|
e.Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
|
|
int border = 2;
|
|
e.Graphics.DrawImage(m_bitmap
|
|
, -border
|
|
, -border
|
|
, pictureBox_Main.Width + border
|
|
, pictureBox_Main.Height + border +1);
|
|
}
|
|
|
|
private void arrangeControls()
|
|
{
|
|
if (m_bitmap == null) return;
|
|
|
|
// pictureBox_Main 从 0,0 开始,其宽度为窗口宽度
|
|
// 根据宽度和图片长宽比例,计算高度
|
|
|
|
int wndWidth = this.ClientSize.Width;
|
|
int wndHeight = this.ClientSize.Height;
|
|
int border = 6;
|
|
|
|
pictureBox_Main.Top = 0;
|
|
pictureBox_Main.Left = 0;
|
|
pictureBox_Main.Width = wndWidth;
|
|
pictureBox_Main.Height = (int)(wndHeight * .5f);
|
|
|
|
label_text.Top = pictureBox_Main.Height;
|
|
label_text.Left = 0;
|
|
|
|
button_ok.Top = button_cancel.Top = wndHeight - border - button_ok.Height;
|
|
button_ok.Left = (int)((wndWidth - button_ok.Width) * .5);
|
|
button_cancel.Left = wndWidth - border - button_cancel.Width;
|
|
|
|
listBox_CAD.Top = label_text.Bottom;
|
|
listBox_CAD.Left = 6;
|
|
listBox_CAD.Width = wndWidth - border * 2;
|
|
listBox_CAD.Height = button_ok.Top - listBox_CAD.Top - border;
|
|
}
|
|
|
|
private void button_cancel_Click(object sender, EventArgs e)
|
|
{
|
|
Close();
|
|
}
|
|
}
|
|
}
|