Beispiel #1
0
        static public PhotoAlbum ReadAlbum(string path, string password)
        {
            StreamReader sr = null;

            try
            {
                string version;
                if (password == null || password.Length == 0)
                {
                    sr      = new StreamReader(path);
                    version = sr.ReadLine();
                    if (version.EndsWith("e"))
                    {
                        throw new AlbumStorageException("A password is required to open the album");
                    }
                }
                else
                {
                    // Create CryptoReader to use as StreamReader
                    CryptoReader cr = new CryptoReader(path, password);
                    version = cr.ReadUnencryptedLine();
                    if (!version.EndsWith("e"))
                    {
                        // Decryption not required
                        cr.Close();
                        sr      = new StreamReader(path);
                        version = sr.ReadLine();
                    }
                    else
                    {
                        string checkLine = cr.ReadLine();
                        if (checkLine != password)
                        {
                            throw new AlbumStorageException("The given password is not valid");
                        }
                        sr = cr;
                    }
                }
                PhotoAlbum album = new PhotoAlbum();

                switch (version)
                {
                case "63":
                    ReadAlbumV63(sr, album);
                    break;

                case "91":
                case "91e":
                    ReadAlbumV91(sr, album);
                    break;

                default:
                    throw new AlbumStorageException("Unrecognized album version");
                }

                album.HasChanged = false;

                return(album);
            }
            catch (System.Security.Cryptography.CryptographicException cex)
            {
                throw new AlbumStorageException("Unable to decrypt album " + path, cex);
            }
            catch (FileNotFoundException fnx)
            {
                throw new AlbumStorageException("Unable to read album " + path, fnx);
            }
            finally
            {
                if (sr != null)
                {
                    sr.Close();
                }
            }
        }
Beispiel #2
0
 public AlbumManager()
 {
     _album = new PhotoAlbum();
 }
Beispiel #3
0
 static public void WriteAlbum(PhotoAlbum album, string path)
 {
     WriteAlbum(album, path, null);
 }
Beispiel #4
0
 public AlbumManager(string name, string pwd) : this()
 {
     this.name = name;
     album     = AlbumStorage.ReadAlbum(name, pwd);
     Password  = pwd;
 }