Exemple #1
0
 public AlbumManager()
 {
     _album = new PhotoAlbum();
 }
 static public void WriteAlbum(PhotoAlbum album, string path)
 {
     WriteAlbum(album, path, null);
 }
        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 th 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("Unrecognizedalbum 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();
                }
            }
        }
Exemple #4
0
 public AlbumManager(string name, string pwd) : this()
 {
     _name    = name;
     _album   = AlbumStorage.ReadAlbum(name, pwd);
     Password = pwd;
 }