Exemple #1
0
        /// <summary>
        /// Serialize the save file.
        /// </summary>
        /// <param name="s">Secret ti serialize.</param>
        /// <returns>Base64 string of current serialized secret.</returns>
        internal static void Serialize(SaveFile s, string fileName)
        {
            string directory = Path.GetDirectoryName(fileName);

            if (Directory.Exists(directory) == false && string.IsNullOrEmpty(directory) == false)
            {
                Directory.CreateDirectory(directory);
            }

            FileStream m = new FileStream(fileName, FileMode.Create);
            formatter.Serialize(m, s);
            m.Flush();
            m.Close();
        }
        /// <summary>
        /// Saves the list of codes to disk.
        /// </summary>
        internal void SaveList()
        {
            SaveFile sf = new SaveFile();
            sf.Height = this.Parent.Height;
            sf.Width = this.Parent.Width;
            foreach (Control ctrl in fpl_list.Controls)
            {
                if (ctrl is CodeDetail)
                {
                    CodeDetail c = (CodeDetail)ctrl;
                    Secret s = new Secret(c.DisplayName, c.Code);
                    sf.SecretsList.Add(s);
                }
            }

            SaveFile.Serialize(sf, Params.SAVE_FILE);
        }