Ver código fonte

modify OTSLicMgr.cs and add OTSCrypt.cs

CXS 5 anos atrás
pai
commit
088dcea38f

+ 106 - 0
OTS/OTSModelSharp/OTSCrypt.cs

@@ -0,0 +1,106 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OTSModelSharp
+{
+    class OTSCrypt   
+    {
+        CARACrypt m_oCrypt;
+
+        int LICENSE_KEYSTRING_LENGTH_MAX = 1024;
+
+        int LICENSE_STRING_LENGTH_MAX = 1024;
+
+        public void Encrypt( String a_sKey, String a_sLicense)
+    {
+        string sKey = null;
+        string sLicense = null;
+
+        sKey = LICENSE_KEYSTRING_LENGTH_MAX.ToString();
+       
+        WCharToChar(a_sKey, sKey);
+       
+        sLicense = LICENSE_STRING_LENGTH_MAX.ToString();
+        string wsLicense = a_sLicense.Length.ToString();
+        WCharToChar(wsLicense, sLicense);
+        a_sLicense.Clone();
+
+        sKey =  a_sKey;
+        sLicense = a_sLicense.Length.ToString();
+
+
+        m_oCrypt.TransformString(sKey, sLicense);
+
+		string psz = LICENSE_KEYSTRING_LENGTH_MAX.ToString();
+        byte[] yourArray = new byte[256];
+        Array.Clear(yourArray, 0, yourArray.Length);
+          
+       CharToWChar(sLicense, psz);
+            String cl = psz;
+        a_sLicense = psz;
+
+		 psz.Remove(1,1);
+
+      
+    }
+
+      public  int WCharToChar( String a_psSource, String a_psTarget)
+	{
+        int iRet = 0;
+        int nLen = Convert.ToInt32(a_psSource) * 2 + 2;
+        var stringBuilder = new StringBuilder();
+        stringBuilder.AppendFormat(iRet.ToString(), a_psTarget, nLen, a_psSource, nLen);
+		return (int) iRet;
+    }
+
+        // string conventions
+       public int CharToWChar( string a_psSource, String a_psTarget)
+	{
+		int iRet = 0;
+        int nLen = Convert.ToInt32(a_psSource) + 1;
+        var stringBuilder = new StringBuilder();
+        stringBuilder.AppendFormat(iRet.ToString(), a_psTarget, nLen, a_psSource, nLen);
+		return (int) iRet;
+    }
+
+    public void Decrypt( String a_sKey, String a_sLicense)
+    {
+            string sKey = null;
+            string sLicense = null;
+
+           sKey = LICENSE_KEYSTRING_LENGTH_MAX.ToString();
+        //wchar_t* wsKey = a_sKey.GetBuffer();
+	       WCharToChar(a_sKey, sKey);
+        //a_sKey.ReleaseBuffer();
+
+           sLicense = LICENSE_STRING_LENGTH_MAX.ToString();
+            String wsLicense = a_sLicense.Length.ToString();
+    
+           WCharToChar(wsLicense, sLicense);
+
+            // COTSHelper::WCharToChar(wsLicense, sLicense);
+            a_sLicense.Clone();
+
+           sKey =  a_sKey;
+           sLicense = a_sLicense.Length.ToString();
+
+            m_oCrypt.TransformString(sKey, sLicense);
+
+		   String psz = LICENSE_KEYSTRING_LENGTH_MAX.ToString();
+           byte[] array = new byte[256];
+            Array.Clear(array, 0, psz.Length);
+           // memset(psz, 0, sizeof(wchar_t) * LICENSE_KEYSTRING_LENGTH_MAX);
+           CharToWChar(sLicense, psz);
+		    String cl=psz;
+            a_sLicense = cl;
+            psz.Remove(1,1);
+            sKey.Remove(1,1);
+            sLicense.Remove(1,1);
+             cl=sLicense;
+       
+    }
+}
+}

+ 1 - 19
OTS/OTSModelSharp/OTSDataType/COTSLicenseInfo.cs

@@ -3,30 +3,12 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using OTSDataType.otsdataconst;
 
 namespace OTSDataType
 {
      public class COTSLicenseInfo
     {
-       
-        public enum  OTS_SOFT_PACKAGE_ID
-        {
-            INVALID = -1,
-		    MIN = 0,
-		    OTSIncA = 0,
-		    OTSPartA = 1,
-		    MAX = 1
-	    }
-
-        public  enum OTS_LICENSE_TYPE
-        {
-            INVALID = -1,
-		    MIN = 0,
-		    Online = 0,
-		    Offline = 1,
-		    MAX = 1
-	    }
-
         // software package id
         OTS_SOFT_PACKAGE_ID m_nPackId;
 

+ 37 - 30
OTS/OTSModelSharp/OTSLicMgr.cs

@@ -636,7 +636,7 @@ namespace OTSModelSharp
             }
 
             // return license info
-            return pOTSLicenseFilePtr.GetLicenseInfo();
+            return GetLicenseInfo();
         }
 
 
@@ -681,9 +681,9 @@ namespace OTSModelSharp
         // gets the name of the folder
         public String GetFolderName(String a_strPathName)
         {
-            Char[] sPath = new char[ DataPublic.MAX_PATH];
+            Char[] sPath = new char[MAX_PATH];
 
-            String.Format(sPath.ToString(),  DataPublic.MAX_PATH.ToString(), a_strPathName);
+            String.Format(sPath.ToString(),MAX_PATH.ToString(), a_strPathName);
 
             // PathRemoveFileSpec(sPath);
 
@@ -842,25 +842,25 @@ namespace OTSModelSharp
             String strTitle = "";
 
             // nick name
-            strTitle = MultiLang.GetInstance().GetStringByKey( DataPublic.GrpOtherParam,  DataPublic.IDS_LICENSE_INFO_TITLE_FIRST);
-            strLicenseInfoTextBody = strTitle +  DataPublic.FILE_TITLE_SPLIT + " " + a_pOTSLicenseInfo.GetComputerNickName() + LINE_END;
+            strTitle = MultiLang.GetInstance().GetStringByKey(OTSModelresource.GrpOtherParam, OTSModelresource.IDS_LICENSE_INFO_TITLE_FIRST);
+            strLicenseInfoTextBody = strTitle + FILE_TITLE_SPLIT + " " + a_pOTSLicenseInfo.GetComputerNickName() + LINE_END;
             // machine id
-            strTitle = MultiLang.GetInstance().GetStringByKey( DataPublic.GrpOtherParam,  DataPublic.IDS_LICENSE_INFO_TITLE_FIRST + 1);
-            strLicenseInfoTextBody += strTitle +  DataPublic.FILE_TITLE_SPLIT + " " + a_pOTSLicenseInfo.GetMachineId() + LINE_END;
+            strTitle = MultiLang.GetInstance().GetStringByKey(OTSModelresource.GrpOtherParam, OTSModelresource.IDS_LICENSE_INFO_TITLE_FIRST + 1);
+            strLicenseInfoTextBody += strTitle +  FILE_TITLE_SPLIT + " " + a_pOTSLicenseInfo.GetMachineId() + LINE_END;
             // software package id
-            strTitle = MultiLang.GetInstance().GetStringByKey( DataPublic.GrpOtherParam,  DataPublic.IDS_LICENSE_INFO_TITLE_FIRST + 2);
+            strTitle = MultiLang.GetInstance().GetStringByKey(OTSModelresource.GrpOtherParam, OTSModelresource.IDS_LICENSE_INFO_TITLE_FIRST + 2);
             String strPackId = String.Format("%i", (int)a_pOTSLicenseInfo.GetPackId());
-            strLicenseInfoTextBody += strTitle +  DataPublic.FILE_TITLE_SPLIT + " " + strPackId + LINE_END;
+            strLicenseInfoTextBody += strTitle +  FILE_TITLE_SPLIT + " " + strPackId + LINE_END;
             // license type id
-            strTitle = MultiLang.GetInstance().GetStringByKey( DataPublic.GrpOtherParam,  DataPublic.IDS_LICENSE_INFO_TITLE_FIRST + 3);
+            strTitle = MultiLang.GetInstance().GetStringByKey(OTSModelresource.GrpOtherParam, OTSModelresource.IDS_LICENSE_INFO_TITLE_FIRST + 3);
             String strLicType;
             strLicType = String.Format("%i", (int)a_pOTSLicenseInfo.GetLicType());
-            strLicenseInfoTextBody += strTitle +  DataPublic.FILE_TITLE_SPLIT + " " + strLicType + LINE_END;
+            strLicenseInfoTextBody += strTitle +  FILE_TITLE_SPLIT + " " + strLicType + LINE_END;
             // expire date
-            strTitle = MultiLang.GetInstance().GetStringByKey( DataPublic.GrpOtherParam,  DataPublic.IDS_LICENSE_INFO_TITLE_FIRST + 4);
+            strTitle = MultiLang.GetInstance().GetStringByKey(OTSModelresource.GrpOtherParam, OTSModelresource.IDS_LICENSE_INFO_TITLE_FIRST + 4);
             String strExpiredDate;
             strExpiredDate = String.Format(EXPIRE_DATA_FORMAT);
-            strLicenseInfoTextBody += strTitle +  DataPublic.FILE_TITLE_SPLIT + " " + strExpiredDate + LINE_END;
+            strLicenseInfoTextBody += strTitle +  FILE_TITLE_SPLIT + " " + strExpiredDate + LINE_END;
 
             // return license info text body
             return strLicenseInfoTextBody;
@@ -1057,7 +1057,7 @@ namespace OTSModelSharp
 
             if (a_nLicTypeId >= OTS_LICENSE_TYPE.MIN && a_nLicTypeId <= OTS_LICENSE_TYPE.MAX)
             {
-                strLicType = MultiLang.GetInstance().GetStringByKey( DataPublic.GrpOtherParam,  DataPublic.IDS_LICENSETYPEID_FIRST + (int)a_nLicTypeId);
+                strLicType = MultiLang.GetInstance().GetStringByKey(OTSModelresource.GrpOtherParam, OTSModelresource.IDS_LICENSETYPEID_FIRST + (int)a_nLicTypeId);
             }
 
             return strLicType;
@@ -1071,7 +1071,7 @@ namespace OTSModelSharp
 
             if (a_nPackId >= OTS_SOFT_PACKAGE_ID.MIN && a_nPackId <= OTS_SOFT_PACKAGE_ID.MAX)
             {
-                strPackId = MultiLang.GetInstance().GetStringByKey( DataPublic.GrpOtherParam,  DataPublic.IDS_SOFTWARETYPEID_FIRST + (int)a_nPackId);
+                strPackId = MultiLang.GetInstance().GetStringByKey(OTSModelresource.GrpOtherParam, OTSModelresource.IDS_SOFTWARETYPEID_FIRST + (int)a_nPackId);
             }
 
             return strPackId;
@@ -1203,7 +1203,7 @@ namespace OTSModelSharp
             foreach (var strLine in listLineStr)
             {
                 // split the string line with ":"
-                List<string> listStr = SplitString(strLine,  DataPublic.FILE_TITLE_SPLIT);
+                List<string> listStr = SplitString(strLine,FILE_TITLE_SPLIT);
 
                 // jump over the string if it is invalid
                 // it should have a title string and item string
@@ -1735,9 +1735,9 @@ namespace OTSModelSharp
 
         public String GetFolderName(String a_strPathName)
         {
-            Char[] sPath = new char[ DataPublic.MAX_PATH];
+            Char[] sPath = new char[MAX_PATH];
 
-            String.Format(sPath.ToString(),  DataPublic.MAX_PATH.ToString(), a_strPathName);
+            String.Format(sPath.ToString(),MAX_PATH.ToString(), a_strPathName);
 
             // PathRemoveFileSpec(sPath);
 
@@ -1829,7 +1829,7 @@ namespace OTSModelSharp
         {
             if (a_strFolder != "")
             {
-                return HasAttribute(a_strFolder,  DataPublic.FILE_ATTRIBUTE_DIRECTORY);
+                return System.IO.Directory.Exists(a_strFolder);
             }
 
             return false;
@@ -1838,17 +1838,24 @@ namespace OTSModelSharp
         // check if the given string is valid file name or not
         public bool IsValidFileName(string a_sFileName)
         {
-            String strFileName = a_sFileName;
-            const String INVALIDFILENAMECHAR = "\\/:*?\"<>";
-            a_sFileName = INVALIDFILENAMECHAR;
-            return true;
-        }
-
-        public bool HasAttribute(string a_strFolder, int a_nAttribute)
-        {
-            int flags = Convert.ToInt32(a_strFolder);
-            return (flags !=  DataPublic.INVALID_FILE_ATTRIBUTES) && (flags == a_nAttribute);
+            bool isFilename = true;
+            string[] errorStr = new string[] { "/", "\\", ":", ",", "*", "?", "\"", "<", ">", "|" };
+            if (string.IsNullOrEmpty(a_sFileName))
+            {
+                isFilename = false;
+            }
+            else
+            {
+                for (int i = 0; i < errorStr.Length; i++)
+                {
+                    if (a_sFileName.Contains(errorStr[i]))
+                    {
+                        isFilename = false;
+                        break;
+                    }
+                }
+            }
+            return isFilename;
         }
-
     }
 }

+ 1 - 0
OTS/OTSModelSharp/OTSModelSharp.csproj

@@ -160,6 +160,7 @@
     <Compile Include="Measure\GetStageInfo\StageFile.cs" />
     <Compile Include="Measure\GetXrayInfo\PosXrayFileMgr.cs" />
     <Compile Include="OTSControl\EBrukerErrorCode.cs" />
+    <Compile Include="OTSCrypt.cs" />
     <Compile Include="OTSDataType\CBSEImg.cs" />
     <Compile Include="OTSDataType\CDomain.cs" />
     <Compile Include="OTSDataType\CDoubleRange.cs" />