/// <summary>
        /// Constructor
        /// </summary>
        /// <param name="repositoryDirectory">
        /// The root directory where the manifest can be found
        /// </param>
        public LocalRepositoryState(
            DirectoryInfo rootDirectory,
            bool readOnly)
        {
            ManifestFileLock      = new object();
            myManifestChangedLock = new object();
            myManifestChanged     = false;
            myReadOnly            = readOnly;

            RootDirectory = rootDirectory;

            LoadManifest();

            if (readOnly == false)
            {
                TempDirUtilities.RemoveExtraTempDirectoriesFrom(
                    RootDirectory);

                TempDirectory = TempDirUtilities.CreateTempDirectoryIn(
                    RootDirectory);
            }

            // There might not be a console present, but I guess it doesn't
            // hurt to put this here.
            System.Console.CancelKeyPress += delegate
            {
                CleanupBeforeExit();
            };
        }
        /// <summary>
        /// CryptRepositoryProxy constructor
        /// </summary>
        /// <param name="innerProxy">
        /// An existing repository to use as the inner repository.
        /// </param>
        /// <param name="outerManifest">
        /// Provide an outer manifest - used during seed.  Null otherwise.
        /// </param>
        /// <param name="outerKey">
        /// A string which will be used as the encryption key.
        /// </param>
        /// <param name="readOnly">
        /// Specify if this repository will be used in read-only mode.
        /// </param>
        protected CryptRepositoryProxy(
            IRepositoryProxy innerProxy,
            Manifest outerManifest,
            String outerKeyString,
            bool readOnly)
        {
            InnerProxy     = innerProxy;
            OuterKeyString = outerKeyString;

            ProxyToInner              = new ProxyToInnerProxy(this);
            myManifestChanged         = false;
            myNeedToRegenerateFileMap = true;
            myReadOnly = readOnly;

            // Lazy generation
            myHashToInnerFileMap = null;

            if (outerManifest != null)
            {
                // Used during "seed" operation
                OuterManifest = outerManifest;
            }
            else
            {
                LoadOuterManifest();
            }

            // Generate map of outer hashes to inner files, find unresolved
            // outer files, and find orphaned inner files.
            ResolveInnerOuter();

            // Remove unresolved outer files
            foreach (ManifestFileInfo nextFile in UnresolvedOuterFiles)
            {
                nextFile.ParentDirectory.Files.Remove(nextFile.Name);
            }

            if (myReadOnly == false)
            {
                // CryptProxy does not own any space - the inner proxy could be
                // remote.  So we put the temp directory in the system temp.
                DirectoryInfo tempRootDirectory =
                    TempDirUtilities.GetSystemTempDirectory();

                TempDirUtilities.RemoveExtraTempDirectoriesFrom(
                    tempRootDirectory);

                TempDirectory = TempDirUtilities.CreateTempDirectoryIn(
                    tempRootDirectory);
            }
        }