internal static string ConditionPlatformVersion(string PlatformVersion, IAscomDataStore Profile, TraceLogger TL)
        {
            string str = PlatformVersion;

            if (Profile != null)
            {
                try
                {
                    string withoutExtension = Path.GetFileNameWithoutExtension(Process.GetCurrentProcess().MainModule.FileName);
                    TL?.LogMessage("ConditionPlatformVersion", "  ModuleFileName: \"" + withoutExtension + "\" \"" + Process.GetCurrentProcess().MainModule.FileName + "\"");
                    //if (Operators.CompareString(Strings.Left(withoutExtension.ToUpper(), 3), "IS-", false) == 0)
                    if (withoutExtension.ToUpper().StartsWith("IS-"))
                    {
                        TL?.LogMessage("ConditionPlatformVersion", "    Inno installer temporary executable detected, searching for parent process!");
                        TL?.LogMessage("ConditionPlatformVersion", "    Old Module Filename: " + withoutExtension);
                        PerformanceCounter performanceCounter = new PerformanceCounter("Process", "Creating Process ID", Process.GetCurrentProcess().ProcessName);
                        withoutExtension = Path.GetFileNameWithoutExtension(Process.GetProcessById(checked ((int)Math.Round((double)performanceCounter.NextValue()))).MainModule.FileName);
                        TL?.LogMessage("ConditionPlatformVersion", "    New Module Filename: " + withoutExtension);
                        performanceCounter.Close();
                        performanceCounter.Dispose();
                    }
                    SortedList <string, string> sortedList1 = Profile.EnumProfile("ForcePlatformVersion");
                    IEnumerator <System.Collections.Generic.KeyValuePair <string, string> > enumerator1 = null;
                    try
                    {
                        enumerator1 = sortedList1.GetEnumerator();
                        while (enumerator1.MoveNext())
                        {
                            System.Collections.Generic.KeyValuePair <string, string> current = enumerator1.Current;
                            TL?.LogMessage("ConditionPlatformVersion", "  ForcedFileName: \"" + current.Key + "\" \"" + current.Value + "\" \"" + Strings.UCase(Path.GetFileNameWithoutExtension(current.Key)) + "\" \"" + Strings.UCase(Path.GetFileName(current.Key)) + "\" \"" + Strings.UCase(current.Key) + "\" \"" + current.Key + "\" \"" + Strings.UCase(withoutExtension) + "\"");
                            string Left = !current.Key.Contains(".") ? current.Key : Path.GetFileNameWithoutExtension(current.Key);
                            if (Operators.CompareString(Left, "", false) != 0 && Strings.UCase(withoutExtension).StartsWith(Strings.UCase(Left)))
                            {
                                str = current.Value;
                                TL?.LogMessage("ConditionPlatformVersion", "  Matched file: \"" + withoutExtension + "\" \"" + Left + "\"");
                            }
                        }
                    }
                    finally
                    {
                        if (enumerator1 != null)
                        {
                            enumerator1.Dispose();
                        }
                    }
                    SortedList <string, string> sortedList2 = Profile.EnumProfile("ForcePlatformVersionSeparator");
                    IEnumerator <System.Collections.Generic.KeyValuePair <string, string> > enumerator2 = null;
                    try
                    {
                        enumerator2 = sortedList2.GetEnumerator();
                        while (enumerator2.MoveNext())
                        {
                            System.Collections.Generic.KeyValuePair <string, string> current = enumerator2.Current;
                            TL?.LogMessage("ConditionPlatformVersion", "  ForcedFileName: \"" + current.Key + "\" \"" + current.Value + "\" \"" + Strings.UCase(Path.GetFileNameWithoutExtension(current.Key)) + "\" \"" + Strings.UCase(Path.GetFileName(current.Key)) + "\" \"" + Strings.UCase(current.Key) + "\" \"" + current.Key + "\" \"" + Strings.UCase(withoutExtension) + "\"");
                            if (!current.Key.Contains("."))
                            {
                            }

                            if (Operators.CompareString(Strings.UCase(Path.GetFileNameWithoutExtension(current.Key)), Strings.UCase(withoutExtension), false) == 0)
                            {
                                if (string.IsNullOrEmpty(current.Value))
                                {
                                    str = str.Replace(".", CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator);
                                    TL?.LogMessage("ConditionPlatformVersion", "  String IsNullOrEmpty: \"" + str + "\"");
                                }
                                else
                                {
                                    str = str.Replace(".", current.Value);
                                    TL?.LogMessage("ConditionPlatformVersion", "  String Is: \"" + current.Value + "\" \"" + str + "\"");
                                }
                                TL?.LogMessage("ConditionPlatformVersion", "  Matched file: \"" + withoutExtension + "\" \"" + current.Key + "\"");
                            }
                        }
                    }
                    finally
                    {
                        if (enumerator2 != null)
                        {
                            enumerator2.Dispose();
                        }
                    }
                }
                catch (Exception ex)
                {
                    //ProjectData.SetProjectError(ex);
                    Exception exception = ex;
                    TL?.LogMessageCrLf("ConditionPlatformVersion", "Exception: " + exception.ToString());
                    EventLogCode.LogEvent("ConditionPlatformVersion", "Exception: ", EventLogEntryType.Error, GlobalConstants.EventLogErrors.VB6HelperProfileException, exception.ToString());
                    //ProjectData.ClearProjectError();
                }
            }
            TL?.LogMessage("ConditionPlatformVersion", "  Returning: \"" + str + "\"");
            return(str);
        }
Beispiel #2
0
 private void WriteValues(string p_SubKeyName, ref SortedList <string, string> p_KeyValuePairs, bool p_CheckForCurrentProfileStore)
 {
     this.swSupport.Reset();
     this.swSupport.Start();
     this.TL.LogMessage("  WriteValues", "  SubKeyName: " + p_SubKeyName);
     if (Operators.CompareString(Strings.Left(p_SubKeyName, 1), "\\", false) != 0)
     {
         p_SubKeyName = "\\" + p_SubKeyName;
     }
     try
     {
         int num1 = 0;
         IEnumerator <System.Collections.Generic.KeyValuePair <string, string> > enumerator1 = null;
         try
         {
             enumerator1 = p_KeyValuePairs.GetEnumerator();
             while (enumerator1.MoveNext())
             {
                 System.Collections.Generic.KeyValuePair <string, string> current = enumerator1.Current;
                 checked { ++num1; }
                 this.TL.LogMessage("  WriteValues List", "  " + num1.ToString() + " " + current.Key + " = " + current.Value);
             }
         }
         finally
         {
             if (enumerator1 != null)
             {
                 enumerator1.Dispose();
             }
         }
         XmlWriterSettings settings = new XmlWriterSettings();
         settings.Indent = true;
         FileStream fileStream = new FileStream(this.FileStore.get_FullPath(p_SubKeyName + "\\ProfileNew.xml"), FileMode.Create, FileAccess.Write, FileShare.None, 2048, FileOptions.WriteThrough);
         XmlWriter  xmlWriter  = XmlWriter.Create((Stream)fileStream, settings);
         using (xmlWriter)
         {
             xmlWriter.WriteStartDocument();
             xmlWriter.WriteStartElement("Profile");
             xmlWriter.WriteStartElement("DefaultElement");
             xmlWriter.WriteAttributeString("Value", p_KeyValuePairs["***** DefaultValueName *****"]);
             xmlWriter.WriteEndElement();
             int num2 = 0;
             IEnumerator <System.Collections.Generic.KeyValuePair <string, string> > enumerator2 = null;
             try
             {
                 enumerator2 = p_KeyValuePairs.GetEnumerator();
                 while (enumerator2.MoveNext())
                 {
                     System.Collections.Generic.KeyValuePair <string, string> current = enumerator2.Current;
                     checked { ++num2; }
                     this.TL.LogMessage("  Writing Value", "  " + num2.ToString() + " " + current.Key + " = " + current.Value);
                     if (current.Value == null)
                     {
                         this.TL.LogMessage("  Writing Value", "  WARNING - Suppplied Value is Nothing not empty string");
                     }
                     if (Operators.CompareString(current.Key, "***** DefaultValueName *****", false) != 0)
                     {
                         xmlWriter.WriteStartElement("Element");
                         xmlWriter.WriteAttributeString("Name", current.Key);
                         xmlWriter.WriteAttributeString("Value", current.Value);
                         xmlWriter.WriteEndElement();
                     }
                 }
             }
             finally
             {
                 if (enumerator2 != null)
                 {
                     enumerator2.Dispose();
                 }
             }
             xmlWriter.WriteEndElement();
             xmlWriter.Close();
         }
         try
         {
             fileStream.Flush();
             fileStream.Close();
             fileStream.Dispose();
         }
         catch (Exception ex)
         {
             //ProjectData.SetProjectError(ex);
             //ProjectData.ClearProjectError();
         }
         try
         {
             if (p_CheckForCurrentProfileStore)
             {
                 this.FileStore.Rename(p_SubKeyName + "\\Profile.xml", p_SubKeyName + "\\ProfileOriginal.xml");
             }
             try
             {
                 this.FileStore.Rename(p_SubKeyName + "\\ProfileNew.xml", p_SubKeyName + "\\Profile.xml");
             }
             catch (Exception ex1)
             {
                 //ProjectData.SetProjectError(ex1);
                 Exception exception1 = ex1;
                 this.TL.Enabled = true;
                 this.TL.LogMessage("XMLAccess:WriteValues", "Unable to rename new profile file to current - " + p_SubKeyName + "\\ProfileNew.xmlto " + p_SubKeyName + "\\Profile.xml " + exception1.ToString());
                 try
                 {
                     this.FileStore.Rename(p_SubKeyName + "\\ProfileOriginal.xml", p_SubKeyName + "\\Profile.xml");
                 }
                 catch (Exception ex2)
                 {
                     //ProjectData.SetProjectError(ex2);
                     Exception exception2 = ex2;
                     this.TL.Enabled = true;
                     this.TL.LogMessage("XMLAccess:WriteValues", "Unable to rename original profile file to current - " + p_SubKeyName + "\\ProfileOriginal.xmlto " + p_SubKeyName + "\\Profile.xml " + exception2.ToString());
                     //ProjectData.ClearProjectError();
                 }
                 //ProjectData.ClearProjectError();
             }
         }
         catch (Exception ex)
         {
             //ProjectData.SetProjectError(ex);
             Exception exception = ex;
             this.TL.Enabled = true;
             this.TL.LogMessage("XMLAccess:WriteValues", "Unable to rename current profile file to original - " + p_SubKeyName + "\\Profile.xmlto " + p_SubKeyName + "\\ProfileOriginal.xml " + exception.ToString());
             //ProjectData.ClearProjectError();
         }
         this.swSupport.Stop();
         this.TL.LogMessage("  WriteValues", "  Created cache entry " + p_SubKeyName + " - " + Conversions.ToString(this.swSupport.ElapsedMilliseconds) + " milliseconds");
     }
     catch (Exception ex)
     {
         //ProjectData.SetProjectError(ex);
         Exception exception = ex;
         this.TL.LogMessageCrLf("  WriteValues", "  Exception " + p_SubKeyName + " " + exception.ToString());
         int num = (int)Interaction.MsgBox((object)("XMLAccess:Writevalues " + p_SubKeyName + " " + exception.ToString()), MsgBoxStyle.OkOnly, (object)null);
         //ProjectData.ClearProjectError();
     }
 }
Beispiel #3
0
        public void CreateKey(string p_SubKeyName)
        {
            SortedList <string, string> p_KeyValuePairs = new SortedList <string, string>();

            try
            {
                this.GetProfileMutex("CreateKey", p_SubKeyName);
                this.sw.Reset();
                this.sw.Start();
                this.TL.LogMessage("CreateKey", "SubKey: \"" + p_SubKeyName + "\"");
                p_SubKeyName = Strings.Trim(p_SubKeyName);
                string[] strArray = Strings.Split(p_SubKeyName, "\\", -1, CompareMethod.Text);
                string   Left     = p_SubKeyName;
                if (Operators.CompareString(Left, "", false) != 0)
                {
                    if (Operators.CompareString(Left, "\\", false) == 0)
                    {
                        if (!this.FileStore.get_Exists("\\Profile.xml"))
                        {
                            this.TL.LogMessage("  CreateKey", "  Creating root key \"\\\"");
                            p_KeyValuePairs.Clear();
                            p_KeyValuePairs.Add("***** DefaultValueName *****", "===== ***** UnsetValue ***** =====");
                            this.WriteValues("\\", ref p_KeyValuePairs, false);
                        }
                        else
                        {
                            this.TL.LogMessage("  CreateKey", "  Root key alread exists");
                        }
                    }
                    else
                    {
                        int num1 = 0;
                        int num2 = checked (strArray.Length - 1);
                        int num3 = num1;
                        while (num3 <= num2)
                        {
                            string p_SubKeyName1 = "";
                            int    num4          = 0;
                            int    num5          = num3;
                            int    index         = num4;
                            while (index <= num5)
                            {
                                p_SubKeyName1 = p_SubKeyName1 + "\\" + strArray[index];
                                checked { ++index; }
                            }
                            if (!this.FileStore.get_Exists(p_SubKeyName1 + "\\Profile.xml"))
                            {
                                this.FileStore.CreateDirectory(p_SubKeyName1, this.TL);
                                p_KeyValuePairs.Clear();
                                p_KeyValuePairs.Add("***** DefaultValueName *****", "===== ***** UnsetValue ***** =====");
                                this.WriteValues(p_SubKeyName1, ref p_KeyValuePairs, false);
                            }
                            checked { ++num3; }
                        }
                    }
                }
                this.sw.Stop();
                this.TL.LogMessage("  ElapsedTime", "  " + Conversions.ToString(this.sw.ElapsedMilliseconds) + " milliseconds");
            }
            finally
            {
                this.ProfileMutex.ReleaseMutex();
            }
        }
Beispiel #4
0
        private SortedList <string, string> ReadValues(string p_SubKeyName)
        {
            SortedList <string, string> sortedList = new SortedList <string, string>();
            bool flag1 = false;
            bool flag2 = false;

            this.swSupport.Reset();
            this.swSupport.Start();
            if (Operators.CompareString(Strings.Left(p_SubKeyName, 1), "\\", false) != 0)
            {
                p_SubKeyName = "\\" + p_SubKeyName;
            }
            this.TL.LogMessage("  ReadValues", "  SubKeyName: " + p_SubKeyName);
            string Left  = "Profile.xml";
            int    num   = -1;
            bool   flag3 = this.FileStore.get_Exists(p_SubKeyName + "\\Profile.xml");
            bool   flag4 = this.FileStore.get_Exists(p_SubKeyName + "\\ProfileOriginal.xml");

            this.FileStore.get_Exists(p_SubKeyName + "\\ProfileNew.xml");
            if (!flag3 & !flag4)
            {
                throw new ProfileNotFoundException("No profile files exist for this key: " + p_SubKeyName);
            }
            do
            {
                checked { ++num; }
                try
                {
                    using (XmlReader xmlReader = XmlReader.Create(this.FileStore.get_FullPath(p_SubKeyName + "\\" + Left), new XmlReaderSettings()
                    {
                        IgnoreWhitespace = true
                    }))
                    {
                        xmlReader.Read();
                        xmlReader.Read();
                        while (xmlReader.Read())
                        {
                            if (xmlReader.NodeType == XmlNodeType.Element)
                            {
                                string name = xmlReader.Name;
                                if (Operators.CompareString(name, "DefaultElement", false) == 0)
                                {
                                    sortedList.Add("***** DefaultValueName *****", xmlReader.GetAttribute("Value"));
                                    this.TL.LogMessage("    ReadValues", "    found ***** DefaultValueName ***** = " + sortedList["***** DefaultValueName *****"]);
                                }
                                else if (Operators.CompareString(name, "Element", false) == 0)
                                {
                                    string attribute = xmlReader.GetAttribute("Name");
                                    sortedList.Add(attribute, xmlReader.GetAttribute("Value"));
                                    this.TL.LogMessage("    ReadValues", "    found " + attribute + " = " + sortedList[attribute]);
                                }
                                else
                                {
                                    this.TL.LogMessage("    ReadValues", "    ## Found unexpected Reader.Name: " + xmlReader.Name.ToString());
                                }
                            }
                        }
                        xmlReader.Close();
                    }
                    this.swSupport.Stop();
                    this.TL.LogMessage("  ReadValues", "  added to cache - " + Conversions.ToString(this.swSupport.ElapsedMilliseconds) + " milliseconds");
                    flag1 = true;
                }
                catch (Exception ex)
                {
                    //ProjectData.SetProjectError(ex);
                    Exception inner = ex;
                    flag2 = true;
                    if (num == 1)
                    {
                        if (Operators.CompareString(Left, "Profile.xml", false) == 0)
                        {
                            Left = "ProfileOriginal.xml";
                            num  = -1;
                            EventLogCode.LogEvent("XMLAccess:ReadValues", "Error reading profile on final retry - attempting recovery from previous version", EventLogEntryType.Warning, GlobalConstants.EventLogErrors.XMLAccessRecoveryPreviousVersion, inner.ToString());
                            this.TL.LogMessageCrLf("  ReadValues", "Final retry exception - attempting recovery from previous version: " + inner.ToString());
                        }
                        else
                        {
                            EventLogCode.LogEvent("XMLAccess:ReadValues", "Error reading profile on final retry", EventLogEntryType.Error, GlobalConstants.EventLogErrors.XMLAccessReadError, inner.ToString());
                            this.TL.LogMessageCrLf("  ReadValues", "Final retry exception: " + inner.ToString());
                            throw new ProfilePersistenceException("XMLAccess Exception", inner);
                        }
                    }
                    else
                    {
                        EventLogCode.LogEvent("XMLAccess:ReadValues", "Error reading profile - retry: " + Conversions.ToString(num), EventLogEntryType.Warning, GlobalConstants.EventLogErrors.XMLAccessRecoveryPreviousVersion, inner.Message);
                        this.TL.LogMessageCrLf("  ReadValues", "Retry " + Conversions.ToString(num) + " exception: " + inner.ToString());
                    }
                    //ProjectData.ClearProjectError();
                }
                if (flag2)
                {
                    Thread.Sleep(200);
                }
            }while (!flag1);
            if (flag2)
            {
                EventLogCode.LogEvent("XMLAccess:ReadValues", "Recovered from read error OK", EventLogEntryType.SuccessAudit, GlobalConstants.EventLogErrors.XMLAccessRecoveredOK, (string)null);
                this.TL.LogMessage("  ReadValues", "Recovered from read error OK");
            }
            return(sortedList);
        }
        internal PEReader(string FileName, TraceLogger TLogger)
        {
            this.sectionHeaders    = (IList <PEReader.IMAGE_SECTION_HEADER>) new List <PEReader.IMAGE_SECTION_HEADER>();
            this.IsAssembly        = false;
            this.OS32BitCompatible = false;
            this.TL = TLogger;
            this.TL.LogMessage("PEReader", "Running within CLR version: " + RuntimeEnvironment.GetSystemVersion());
            if (Operators.CompareString(Strings.Left(FileName, 5).ToUpper(), "FILE:", false) == 0)
            {
                Uri uri = new Uri(FileName);
                FileName = uri.LocalPath + Uri.UnescapeDataString(uri.Fragment).Replace("/", "\\\\");
            }
            this.TL.LogMessage("PEReader", "Filename to check: " + FileName);
            if (!File.Exists(FileName))
            {
                throw new FileNotFoundException("PEReader - File not found: " + FileName);
            }
            this.TL.LogMessage("PEReader", "Determining whether this is an assembly");
            try
            {
                this.SuppliedAssembly = Assembly.ReflectionOnlyLoadFrom(FileName);
                this.IsAssembly       = true;
                this.TL.LogMessage("PEReader.IsAssembly", "Found an assembly because it loaded Ok to the reflection context: " + Conversions.ToString(this.IsAssembly));
            }
            catch (FileNotFoundException ex)
            {
                //ProjectData.SetProjectError((Exception) ex);
                this.TL.LogMessage("PEReader.IsAssembly", "FileNotFoundException: File not found so this is NOT an assembly: " + Conversions.ToString(this.IsAssembly));
                //ProjectData.ClearProjectError();
            }
            catch (BadImageFormatException ex)
            {
                //ProjectData.SetProjectError((Exception) ex);
                int hrForException = Marshal.GetHRForException((Exception)ex);
                switch (hrForException)
                {
                case -2147024885:
                    this.TL.LogMessage("PEReader.IsAssembly", "BadImageFormatException. hResult: " + hrForException.ToString("X8") + " - COR_E_BADIMAGEFORMAT. Setting IsAssembly to: " + Conversions.ToString(this.IsAssembly));
                    break;

                case -2146234105:
                    this.TL.LogMessage("PEReader.IsAssembly", "BadImageFormatException. hResult: " + hrForException.ToString("X8") + " - CLDB_E_FILE_OLDVER. Setting IsAssembly to: " + Conversions.ToString(this.IsAssembly));
                    break;

                case -2146234076:
                    this.TL.LogMessage("PEReader.IsAssembly", "BadImageFormatException. hResult: " + hrForException.ToString("X8") + " - CLDB_E_INDEX_NOTFOUND. Setting IsAssembly to: " + Conversions.ToString(this.IsAssembly));
                    break;

                case -2146234098:
                    this.TL.LogMessage("PEReader.IsAssembly", "BadImageFormatException. hResult: " + hrForException.ToString("X8") + " - CLDB_E_FILE_CORRUPT. Setting IsAssembly to: " + Conversions.ToString(this.IsAssembly));
                    break;

                case -2146234341:
                    this.IsAssembly = true;
                    this.TL.LogMessage("PEReader.IsAssembly", "BadImageFormatException. hResult: " + hrForException.ToString("X8") + " - COR_E_NEWER_RUNTIME. Setting IsAssembly to: " + Conversions.ToString(this.IsAssembly));
                    break;

                case -2146234344:
                    this.TL.LogMessage("PEReader.IsAssembly", "BadImageFormatException. hResult: " + hrForException.ToString("X8") + " - COR_E_ASSEMBLYEXPECTED. Setting IsAssembly to: " + Conversions.ToString(this.IsAssembly));
                    break;

                case -2147024703:
                    this.TL.LogMessage("PEReader.IsAssembly", "BadImageFormatException. hResult: " + hrForException.ToString("X8") + " - ERROR_BAD_EXE_FORMAT. Setting IsAssembly to: " + Conversions.ToString(this.IsAssembly));
                    break;

                case -2147024704:
                    this.TL.LogMessage("PEReader.IsAssembly", "BadImageFormatException. hResult: " + hrForException.ToString("X8") + " - ERROR_EXE_MARKED_INVALID. Setting IsAssembly to: " + Conversions.ToString(this.IsAssembly));
                    break;

                case -2146233315:
                    this.TL.LogMessage("PEReader.IsAssembly", "BadImageFormatException. hResult: " + hrForException.ToString("X8") + " - CORSEC_E_INVALID_IMAGE_FORMAT. Setting IsAssembly to: " + Conversions.ToString(this.IsAssembly));
                    break;

                case -2147023898:
                    this.TL.LogMessage("PEReader.IsAssembly", "BadImageFormatException. hResult: " + hrForException.ToString("X8") + " - ERROR_NOACCESS. Setting IsAssembly to: " + Conversions.ToString(this.IsAssembly));
                    break;

                case -2147024714:
                    this.TL.LogMessage("PEReader.IsAssembly", "BadImageFormatException. hResult: " + hrForException.ToString("X8") + " - ERROR_INVALID_ORDINAL. Setting IsAssembly to: " + Conversions.ToString(this.IsAssembly));
                    break;

                case -2147023742:
                    this.TL.LogMessage("PEReader.IsAssembly", "BadImageFormatException. hResult: " + hrForException.ToString("X8") + " - ERROR_INVALID_DLL. Setting IsAssembly to: " + Conversions.ToString(this.IsAssembly));
                    break;

                case -2147023504:
                    this.TL.LogMessage("PEReader.IsAssembly", "BadImageFormatException. hResult: " + hrForException.ToString("X8") + " - ERROR_FILE_CORRUPT. Setting IsAssembly to: " + Conversions.ToString(this.IsAssembly));
                    break;

                case -2146234280:
                    this.TL.LogMessage("PEReader.IsAssembly", "BadImageFormatException. hResult: " + hrForException.ToString("X8") + " - COR_E_LOADING_REFERENCE_ASSEMBLY. Setting IsAssembly to: " + Conversions.ToString(this.IsAssembly));
                    break;

                case -2146233966:
                    this.TL.LogMessage("PEReader.IsAssembly", "BadImageFormatException. hResult: " + hrForException.ToString("X8") + " - META_E_BAD_SIGNATURE. Setting IsAssembly to: " + Conversions.ToString(this.IsAssembly));
                    break;

                default:
                    this.TL.LogMessage("PEReader.IsAssembly", "BadImageFormatException. hResult: " + hrForException.ToString("X8") + " - Meaning of error code is unknown. Setting IsAssembly to: " + Conversions.ToString(this.IsAssembly));
                    break;
                }
                //ProjectData.ClearProjectError();
            }
            catch (FileLoadException ex)
            {
                //ProjectData.SetProjectError((Exception) ex);
                this.IsAssembly = true;
                this.TL.LogMessage("PEReader.IsAssembly", "FileLoadException: Assembly already loaded so this is an assembly: " + Conversions.ToString(this.IsAssembly));
                //ProjectData.ClearProjectError();
            }
            this.TL.LogMessage("PEReader", "Determining PE Machine type");
            this.stream = (Stream) new FileStream(FileName, FileMode.Open, FileAccess.Read);
            this.reader = new BinaryReader(this.stream);
            this.reader.BaseStream.Seek(0L, SeekOrigin.Begin);
            this.dosHeader = PEReader.MarshalBytesTo <PEReader.IMAGE_DOS_HEADER>(this.reader);
            if ((int)this.dosHeader.e_magic != 23117)
            {
                throw new ASCOM.InvalidOperationException("File is not a portable executable.");
            }
            this.reader.BaseStream.Seek((long)this.dosHeader.e_lfanew, SeekOrigin.Begin);
            this.ntHeaders.Signature = PEReader.MarshalBytesTo <uint>(this.reader);
            if ((long)this.ntHeaders.Signature != 17744L)
            {
                throw new ASCOM.InvalidOperationException("Invalid portable executable signature in NT header.");
            }
            this.ntHeaders.FileHeader = PEReader.MarshalBytesTo <PEReader.IMAGE_FILE_HEADER>(this.reader);
            switch (this.ntHeaders.FileHeader.Machine)
            {
            case 332:
                this.OS32BitCompatible = true;
                this.TL.LogMessage("PEReader.MachineType", "Machine - found \"Intel 32bit\" executable. Characteristics: " + this.ntHeaders.FileHeader.Characteristics.ToString("X8") + ", OS32BitCompatible: " + Conversions.ToString(this.OS32BitCompatible));
                break;

            case 512:
                this.OS32BitCompatible = false;
                this.TL.LogMessage("PEReader.MachineType", "Machine - found \"Itanium 64bit\" executable. Characteristics: " + this.ntHeaders.FileHeader.Characteristics.ToString("X8") + ", OS32BitCompatible: " + Conversions.ToString(this.OS32BitCompatible));
                break;

            case 34404:
                this.OS32BitCompatible = false;
                this.TL.LogMessage("PEReader.MachineType", "Machine - found \"Intel 64bit\" executable. Characteristics: " + this.ntHeaders.FileHeader.Characteristics.ToString("X8") + ", OS32BitCompatible: " + Conversions.ToString(this.OS32BitCompatible));
                break;

            default:
                this.TL.LogMessage("PEReader.MachineType", "Found Unknown machine type: " + this.ntHeaders.FileHeader.Machine.ToString("X8") + ". Characteristics: " + this.ntHeaders.FileHeader.Characteristics.ToString("X8") + ", OS32BitCompatible: " + Conversions.ToString(this.OS32BitCompatible));
                break;
            }
            if (this.OS32BitCompatible)
            {
                this.TL.LogMessage("PEReader.MachineType", "Reading optional 32bit header");
                this.ntHeaders.OptionalHeader32 = PEReader.MarshalBytesTo <PEReader.IMAGE_OPTIONAL_HEADER32>(this.reader);
            }
            else
            {
                this.TL.LogMessage("PEReader.MachineType", "Reading optional 64bit header");
                this.ntHeaders.OptionalHeader64 = PEReader.MarshalBytesTo <PEReader.IMAGE_OPTIONAL_HEADER64>(this.reader);
            }
            if (this.IsAssembly)
            {
                this.TL.LogMessage("PEReader", "This is an assembly, determining Bitness through the CLR header");
                int num1 = 1000;
                if (this.OS32BitCompatible)
                {
                    this.TL.LogMessage("PEReader.Bitness", "This is a 32 bit assembly, reading the CLR Header");
                    if ((long)this.ntHeaders.OptionalHeader32.NumberOfRvaAndSizes < 1000L)
                    {
                        num1 = checked ((int)this.ntHeaders.OptionalHeader32.NumberOfRvaAndSizes);
                    }
                    this.TL.LogMessage("PEReader.Bitness", "Checking " + Conversions.ToString(num1) + " headers");
                    int num2  = 0;
                    int num3  = checked (num1 - 1);
                    int index = num2;
                    while (index <= num3)
                    {
                        if ((long)this.ntHeaders.OptionalHeader32.DataDirectory[index].Size > 0L)
                        {
                            this.sectionHeaders.Add(PEReader.MarshalBytesTo <PEReader.IMAGE_SECTION_HEADER>(this.reader));
                        }
                        checked { ++index; }
                    }
                    IEnumerator <PEReader.IMAGE_SECTION_HEADER> enumerator = null;
                    try
                    {
                        enumerator = this.sectionHeaders.GetEnumerator();
                        while (enumerator.MoveNext())
                        {
                            PEReader.IMAGE_SECTION_HEADER current = enumerator.Current;
                            if (Operators.CompareString(current.Name, ".text", false) == 0)
                            {
                                this.TextBase = current.PointerToRawData;
                            }
                        }
                    }
                    finally
                    {
                        if (enumerator != null)
                        {
                            enumerator.Dispose();
                        }
                    }
                    if (num1 >= 15 && (long)this.ntHeaders.OptionalHeader32.DataDirectory[14].VirtualAddress > 0L)
                    {
                        this.reader.BaseStream.Seek((long)checked (this.ntHeaders.OptionalHeader32.DataDirectory[14].VirtualAddress - this.ntHeaders.OptionalHeader32.BaseOfCode + this.TextBase), SeekOrigin.Begin);
                        this.CLR = PEReader.MarshalBytesTo <PEReader.IMAGE_COR20_HEADER>(this.reader);
                    }
                }
                else
                {
                    this.TL.LogMessage("PEReader.Bitness", "This is a 64 bit assembly, reading the CLR Header");
                    if ((long)this.ntHeaders.OptionalHeader64.NumberOfRvaAndSizes < 1000L)
                    {
                        num1 = checked ((int)this.ntHeaders.OptionalHeader64.NumberOfRvaAndSizes);
                    }
                    this.TL.LogMessage("PEReader.Bitness", "Checking " + Conversions.ToString(num1) + " headers");
                    int num2  = 0;
                    int num3  = checked (num1 - 1);
                    int index = num2;
                    while (index <= num3)
                    {
                        if ((long)this.ntHeaders.OptionalHeader64.DataDirectory[index].Size > 0L)
                        {
                            this.sectionHeaders.Add(PEReader.MarshalBytesTo <PEReader.IMAGE_SECTION_HEADER>(this.reader));
                        }
                        checked { ++index; }
                    }
                    IEnumerator <PEReader.IMAGE_SECTION_HEADER> enumerator = null;
                    try
                    {
                        enumerator = this.sectionHeaders.GetEnumerator();
                        while (enumerator.MoveNext())
                        {
                            PEReader.IMAGE_SECTION_HEADER current = enumerator.Current;
                            if (Operators.CompareString(current.Name, ".text", false) == 0)
                            {
                                this.TL.LogMessage("PEReader.Bitness", "Found TEXT section");
                                this.TextBase = current.PointerToRawData;
                            }
                        }
                    }
                    finally
                    {
                        if (enumerator != null)
                        {
                            enumerator.Dispose();
                        }
                    }
                    if (num1 >= 15 && (long)this.ntHeaders.OptionalHeader64.DataDirectory[14].VirtualAddress > 0L)
                    {
                        this.reader.BaseStream.Seek((long)checked (this.ntHeaders.OptionalHeader64.DataDirectory[14].VirtualAddress - this.ntHeaders.OptionalHeader64.BaseOfCode + this.TextBase), SeekOrigin.Begin);
                        this.CLR = PEReader.MarshalBytesTo <PEReader.IMAGE_COR20_HEADER>(this.reader);
                        this.TL.LogMessage("PEReader.Bitness", "Read CLR header successfully");
                    }
                }
                if (this.OS32BitCompatible)
                {
                    if (((long)this.CLR.Flags & 2L) > 0L)
                    {
                        this.TL.LogMessage("PEReader.Bitness", "Found \"32bit Required\" assembly");
                        this.ExecutableBitness = VersionCode.Bitness.Bits32;
                    }
                    else
                    {
                        this.TL.LogMessage("PEReader.Bitness", "Found \"MSIL\" assembly");
                        this.ExecutableBitness = VersionCode.Bitness.BitsMSIL;
                    }
                }
                else
                {
                    this.TL.LogMessage("PEReader.Bitness", "Found \"64bit Required\" assembly");
                    this.ExecutableBitness = VersionCode.Bitness.Bits64;
                }
                this.TL.LogMessage("PEReader", "Assembly required Runtime version: " + Conversions.ToString((uint)this.CLR.MajorRuntimeVersion) + "." + Conversions.ToString((uint)this.CLR.MinorRuntimeVersion));
            }
            else
            {
                this.TL.LogMessage("PEReader", "This is not an assembly, determining Bitness through the executable bitness flag");
                if (this.OS32BitCompatible)
                {
                    this.TL.LogMessage("PEReader.Bitness", "Found 32bit executable");
                    this.ExecutableBitness = VersionCode.Bitness.Bits32;
                }
                else
                {
                    this.TL.LogMessage("PEReader.Bitness", "Found 64bit executable");
                    this.ExecutableBitness = VersionCode.Bitness.Bits64;
                }
            }
        }