예제 #1
0
        internal void MigrateProfile(string CurrentPlatformVersion)
        {
            RegistryKey FromKey;
            bool        LogEnabled;

            try
            {
                GetProfileMutex("MigrateProfile", "");
                sw.Reset(); sw.Start(); // Start timing this call
                TL.LogMessage("MigrateProfile", "");

                // Force logging to be enabled for this...
                LogEnabled = TL.Enabled; // Save logging state
                TL.Enabled = true;
                RunningVersions(TL);     // Capture date in case logging wasn't initially enabled

                TL.LogMessage("MigrateProfile", "Migrating keys");
                // Create the root directory if it doesn't already exist
                if (!FileStore.Exists(@"\" + VALUES_FILENAME))
                {
                    FileStore.CreateDirectory(@"\", TL);
                    CreateKey(@"\"); // Create the root key
                    TL.LogMessage("MigrateProfile", "Successfully created root directory and root key");
                }
                else
                {
                    TL.LogMessage("MigrateProfile", "Root directory already exists");
                }

                // Set security ACLs on profile root directory
                TL.LogMessage("MigrateProfile", "Setting security ACLs on ASCOM root directory ");
                FileStore.SetSecurityACLs(TL);

                TL.LogMessage("MigrateProfile", "Copying Profile from Registry");
                // Get the registry root key depending. Success here depends on us running as 32bit as the Platform 5 registry
                // is located under HKLM\Software\Wow6432Node!
                FromKey = Registry.LocalMachine.OpenSubKey(REGISTRY_ROOT_KEY_NAME); // Source to copy from
                if (!FromKey == null)
                {
                    TL.LogMessage("MigrateProfile", "FromKey Opened OK: " + FromKey.Name + ", SubKeyCount: " + FromKey.SubKeyCount.ToString() + ", ValueCount: " + FromKey.ValueCount.ToString());
                    MigrateKey(FromKey, ""); // Use recursion to copy contents to new tree
                    TL.LogMessage("MigrateProfile", "Successfully migrated keys");
                    FromKey.Close();
                    // Restore original logging state
                    TL.Enabled = GetBool(TRACE_XMLACCESS, TRACE_XMLACCESS_DEFAULT); // Get enabled / disabled state from the user registry
                }
                else
                {
                    throw new ProfileNotFoundException(@"Cannot find ASCOM Profile in HKLM\" + REGISTRY_ROOT_KEY_NAME + " Is Platform 5 installed?");
                }
                sw.Stop(); TL.LogMessage("  ElapsedTime", "  " + sw.ElapsedMilliseconds + " milliseconds");
                TL.Enabled = LogEnabled; // Restore logging state
            }
            catch (Exception ex)
            {
                TL.LogMessageCrLf("MigrateProfile", "Exception: " + ex.ToString());
                throw;
            }
        }
예제 #2
0
        private void MigrateKey(RegistryKey p_FromKey, string p_ToDir)
        {
            // Subroutine used for one off copy of registry profile to new XML profile
            string[]    ValueNames, SubKeyNames;
            RegistryKey FromKey;

            Generic.SortedList <string, string> Values = new Generic.SortedList <string, string>();
            // Recusively copy contents from one key to the other
            Stopwatch swLocal;

            ;                  /* Cannot convert LocalDeclarationStatementSyntax, System.NotSupportedException: StaticKeyword not supported!
                                * at ICSharpCode.CodeConverter.CSharp.SyntaxKindExtensions.ConvertToken(SyntaxKind t, TokenContext context)
                                * at ICSharpCode.CodeConverter.CSharp.CommonConversions.ConvertModifier(SyntaxToken m, TokenContext context)
                                * at ICSharpCode.CodeConverter.CSharp.CommonConversions.<ConvertModifiersCore>d__15.MoveNext()
                                * at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
                                * at Microsoft.CodeAnalysis.SyntaxTokenList.CreateNode(IEnumerable`1 tokens)
                                * at ICSharpCode.CodeConverter.CSharp.CommonConversions.ConvertModifiers(IEnumerable`1 modifiers, TokenContext context, Boolean isVariableOrConst)
                                * at ICSharpCode.CodeConverter.CSharp.VisualBasicConverter.MethodBodyVisitor.VisitLocalDeclarationStatement(LocalDeclarationStatementSyntax node)
                                * at Microsoft.CodeAnalysis.VisualBasic.Syntax.LocalDeclarationStatementSyntax.Accept[TResult](VisualBasicSyntaxVisitor`1 visitor)
                                * at Microsoft.CodeAnalysis.VisualBasic.VisualBasicSyntaxVisitor`1.Visit(SyntaxNode node)
                                * at ICSharpCode.CodeConverter.CSharp.CommentConvertingMethodBodyVisitor.ConvertWithTrivia(SyntaxNode node)
                                * at ICSharpCode.CodeConverter.CSharp.CommentConvertingMethodBodyVisitor.DefaultVisit(SyntaxNode node)
                                *
                                * Input:
                                *
                                * Static RecurseDepth As Integer
                                *
                                */
            RecurseDepth += 1; // Increment the recursion depth indicator

            swLocal = Stopwatch.StartNew();
            TL.LogMessage("MigrateKeys " + RecurseDepth.ToString(), "To Directory: " + p_ToDir);
            try
            {
                TL.LogMessage("MigrateKeys" + RecurseDepth.ToString(), "From Key: " + p_FromKey.Name + ", SubKeyCount: " + p_FromKey.SubKeyCount.ToString() + ", ValueCount: " + p_FromKey.ValueCount.ToString());
            }
            catch (Exception ex)
            {
                TL.LogMessage("MigrateKeys", "Exception processing \"" + p_ToDir + "\": " + ex.ToString());
                TL.LogMessage("MigrateKeys", "Exception above: no action taken, continuing...");
            }

            // First copy values from the from key to the to key
            ValueNames = p_FromKey.GetValueNames();
            Values.Add(COLLECTION_DEFAULT_VALUE_NAME, COLLECTION_DEFAULT_UNSET_VALUE);
            foreach (string ValueName in ValueNames)
            {
                if (ValueName == "")
                {
                    Values.Remove(COLLECTION_DEFAULT_VALUE_NAME); // Remove the default unset value and replace with actual value
                    Values.Add(COLLECTION_DEFAULT_VALUE_NAME, p_FromKey.GetValue(ValueName).ToString());
                }
                else
                {
                    Values.Add(ValueName, p_FromKey.GetValue(ValueName).ToString());
                }
            }
            WriteValues(p_ToDir, ref Values); // Write values to XML file

            // Now process the keys
            SubKeyNames = p_FromKey.GetSubKeyNames();
            foreach (string SubKeyName in SubKeyNames)
            {
                FromKey = p_FromKey.OpenSubKey(SubKeyName);       // Point at the source to copy to it
                CreateKey(p_ToDir + @"\" + SubKeyName);
                MigrateKey(FromKey, p_ToDir + @"\" + SubKeyName); // Recursively process each key
                FromKey.Close();
            }
            swLocal.Stop(); TL.LogMessage("  ElapsedTime " + RecurseDepth.ToString(), "  " + swLocal.ElapsedMilliseconds + " milliseconds, Completed Directory: " + p_ToDir);
            RecurseDepth -= 1; // Decrement the recursion depth counter
            swLocal       = null;
        }