diff --git a/3rdPackage/WibuCmNET.dll b/3rdPackage/WibuCmNET.dll new file mode 100644 index 0000000..843e9d6 Binary files /dev/null and b/3rdPackage/WibuCmNET.dll differ diff --git a/SanSystem/Dongle.cs b/SanSystem/Dongle.cs new file mode 100644 index 0000000..785f8e5 --- /dev/null +++ b/SanSystem/Dongle.cs @@ -0,0 +1,133 @@ +using CodeMeter; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SanSystem +{ + class Dongle + { + uint FirmCode; + uint ProductCode; + + Api cmApi; + CmCredential cmCred; + CmAccess2 cmAcc; + HCMSysEntry hcmse; + CmBoxInfo cmBoxInfo; + CmBoxEntry2 BoxContent; + + public Dongle(uint FirmCode, uint ProductCode) + { +#if !DEBUG + if (FirmCode == 103086) + this.FirmCode = FirmCode; + else + this.FirmCode = 103086; +#else + this.FirmCode = 10; +#endif + + this.ProductCode = ProductCode; + cmApi = new Api(); + cmCred = new CmCredential(); + cmAcc = new CmAccess2(); + + cmAcc.Credential = cmCred; + + cmAcc.Ctrl |= CmAccess.Option.UserLimit; + cmAcc.FirmCode = this.FirmCode; + cmAcc.ProductCode = this.ProductCode; + + + hcmse = cmApi.CmAccess2(CmAccessOption.Local, cmAcc); + if(hcmse == null) + { + ErrorCodes2 code = cmApi.CmGetLastErrorCode2(); + string output = string.Format("{0}", code); + + } + + if (!CheckDongleVorhanden()) + Trace.WriteLine("Dongle nicht vorhanden"); + + cmBoxInfo = new CmBoxInfo(); + + CmGetBoxContentsOption boxOptions = new CmGetBoxContentsOption(); + boxOptions = CmGetBoxContentsOption.FirmItem; + + CmBoxEntry2[] tmpBoxContent; + + tmpBoxContent = cmApi.CmGetBoxContents2(hcmse, boxOptions, this.FirmCode, cmBoxInfo); + + foreach (CmBoxEntry2 boxes in tmpBoxContent) + { + if (boxes.ProductCode == this.ProductCode) + { + this.BoxContent = boxes; + } + } + } + ~Dongle() + { + CleanDongle(); + } + + public void CleanDongle() + { + cmApi.CmRelease(hcmse); + } + + public bool CheckDongleVorhanden() + { + + if (hcmse == null) + return false; + else + return true; + } + + public string GetDongleSerial() + { + + CmBoxInfo res = (CmBoxInfo)cmApi.CmGetInfo(hcmse, CmGetInfoOption.BoxInfo); + if (null != res) + { + return res.SerialNumber.ToString(); + } + else + { + throw new Exception("Fehler beim aufrufen der Seriennummer"); + } + } + + public uint GetFeatureMap() + { + return BoxContent.FeatureMap; + } + + public string GetName() + { + return ""; + } + + public bool IsLicensed(byte neededMask) + { + + uint DongleFeature = GetFeatureMap(); + + Trace.WriteLine("DongleFeature: " + DongleFeature); + + byte DongleFeatureB = (byte)DongleFeature; + + if ((DongleFeatureB & neededMask) == neededMask) + return true; + return false; + } + } + + +} diff --git a/SanSystem/FrmReparaturKonzept.cs b/SanSystem/FrmReparaturKonzept.cs index b054d54..a21e4dd 100644 --- a/SanSystem/FrmReparaturKonzept.cs +++ b/SanSystem/FrmReparaturKonzept.cs @@ -40,7 +40,7 @@ namespace SanSystem private void btn_add_san_Click(object sender, EventArgs e) { int mod = (int)Sanierungsarten.KURZLINER ^ (int)Sanierungsarten.QUICKLOCK ^ (int)Sanierungsarten.HUTPROFIL; - FrmSelectNewSan frmSelectNewSan = new FrmSelectNewSan(mod); + FrmSelectNewSan frmSelectNewSan = new FrmSelectNewSan(); frmSelectNewSan.AddKurzlinerClicked += FrmSelectNewSan_AddKurzlinerClicked; frmSelectNewSan.AddHutprofilClicked += FrmSelectNewSan_AddHutprofilClicked; diff --git a/SanSystem/FrmSelectNewSan.cs b/SanSystem/FrmSelectNewSan.cs index f0d7a76..7b32208 100644 --- a/SanSystem/FrmSelectNewSan.cs +++ b/SanSystem/FrmSelectNewSan.cs @@ -85,23 +85,26 @@ namespace SanSystem /// /// /// - /// - public FrmSelectNewSan(int mod) + public FrmSelectNewSan() { InitializeComponent(); - SanArt sanArt = new SanArt(mod); + //SanArt sanArt = new SanArt(mod); + Dongle dongle = new Dongle(10, 60); btn_inliner.Text = Global.Instance.language.Labels["inliner"]; btn_hut.Text = Global.Instance.language.Labels["hut"]; btn_kurzliner.Text = Global.Instance.language.Labels["kurzliner"]; btn_schacht_anb.Text = Global.Instance.language.Labels["schacht_an"]; - btn_inliner.Enabled = sanArt.SanierungActivated(Sanierungsarten.INLINER); - btn_kurzliner.Enabled = sanArt.SanierungActivated(Sanierungsarten.KURZLINER); - btn_hut.Enabled = sanArt.SanierungActivated(Sanierungsarten.HUTPROFIL); - btn_schacht_anb.Enabled = sanArt.SanierungActivated(Sanierungsarten.SCHACHTANBINDUNG); - //btn_hut.Enabled = btn_kurzliner.Enabled = false; + + btn_inliner.Enabled = dongle.IsLicensed((byte)Sanierungsarten.INLINER) ? true : false;// sanArt.SanierungActivated(Sanierungsarten.INLINER); + btn_kurzliner.Enabled = dongle.IsLicensed((byte)Sanierungsarten.KURZLINER) ? true : false; //sanArt.SanierungActivated(Sanierungsarten.KURZLINER); + btn_hut.Enabled = dongle.IsLicensed((byte)Sanierungsarten.HUTPROFIL) ? true : false;// sanArt.SanierungActivated(Sanierungsarten.HUTPROFIL); + btn_schacht_anb.Enabled = dongle.IsLicensed((byte)Sanierungsarten.SCHACHTANBINDUNG) ? true : false; // sanArt.SanierungActivated(Sanierungsarten.SCHACHTANBINDUNG); + btn_hut.Enabled = btn_kurzliner.Enabled = false; + + dongle.CleanDongle(); } private void btn_inliner_Click(object sender, EventArgs e) diff --git a/SanSystem/Program.cs b/SanSystem/Program.cs index 5285483..3389250 100644 --- a/SanSystem/Program.cs +++ b/SanSystem/Program.cs @@ -14,10 +14,20 @@ namespace SanSystem [STAThread] static void Main() { - Global.Instance.LoadLanguage(); - Application.EnableVisualStyles(); - Application.SetCompatibleTextRenderingDefault(false); - Application.Run(new frmMain()); + Dongle dongle = new Dongle(10, 60); + if (dongle.CheckDongleVorhanden()) + { + dongle.CleanDongle(); + Global.Instance.LoadLanguage(); + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new frmMain()); + } + else + { + MessageBox.Show("Sorry es wurde kein Dongle gefunden!"); + Application.Exit(); + } } } } diff --git a/SanSystem/SanSystem.csproj b/SanSystem/SanSystem.csproj index fd24655..0401c70 100644 --- a/SanSystem/SanSystem.csproj +++ b/SanSystem/SanSystem.csproj @@ -78,8 +78,13 @@ + + False + ..\3rdPackage\WibuCmNET.dll + + diff --git a/SanSystem/frmObjektEdit.cs b/SanSystem/frmObjektEdit.cs index 76e491a..5a84ae7 100644 --- a/SanSystem/frmObjektEdit.cs +++ b/SanSystem/frmObjektEdit.cs @@ -116,8 +116,11 @@ namespace SanSystem private void btn_add_san_Click(object sender, EventArgs e) { - int mod = (int)Sanierungsarten.INLINER ^ (int)Sanierungsarten.SCHACHTANBINDUNG; - FrmSelectNewSan frmSelectNewSan = new FrmSelectNewSan(mod); + //Dongle dongle = new Dongle(103086, 60); + + //int mod = dongle.IsLicensed((byte)Sanierungsarten.INLINER) ? (int)Sanierungsarten.INLINER : 0; // (int)Sanierungsarten.INLINER ^ (int)Sanierungsarten.SCHACHTANBINDUNG; // Auslagern zur Dongle + + FrmSelectNewSan frmSelectNewSan = new FrmSelectNewSan(); frmSelectNewSan.AddInlinerClicked += FrmSelectNewSan_AddInlinerClicked; frmSelectNewSan.AddSchachtAnbindungClicked += FrmSelectNewSan_AddSchachtAnbindungClicked;