Ejemplo n.º 1
0
        /// <summary>
        /// Handles serialization of the Song class, or of any types derived from it.
        /// </summary>
        /// <param name="instance">The instance to serialize</param>
        /// <param name="file">The XML file to serialize to</param>
        public static void SerializeTo(Song instance, string file)
        {
            // We need to save these and restore them after serializing, or else whoever is holding
            // a reference to this "instance" will end up with a broken object because we set these
            // to "null" below so that we don't serialize them.
            string savedBGImagePath = instance.BGImagePath;

            Type          type = instance.GetType();
            XmlSerializer xs   = new XmlSerializer(type);

            Directory.CreateDirectory(Path.GetDirectoryName(file));
            FileStream fs = null;

            // When files are de-serialized, they retain the version they were
            // originally serialized under. We need to update it here.
            instance.Version = DreamTools.GetAppVersion();

            if (instance.UseDesign)
            {
                Console.WriteLine("Saving Design..");
                instance.Theme.SaveFile(DreamTools.GetDirectory(DirType.SongDesigns) + "\\" + Path.GetFileNameWithoutExtension(file) + ".SongTheme.xml");
                instance.ThemePath = DreamTools.GetFullPathOrNull(DreamTools.GetDirectory(DirType.SongDesigns), Path.GetFileNameWithoutExtension(file) + ".SongTheme.xml");
            }

            try {
                fs = File.Open(file, FileMode.Create, FileAccess.Write, FileShare.Read);
                xs.Serialize(fs, instance);
            } finally {
                if (fs != null)
                {
                    fs.Close();
                }
                instance.BGImagePath = savedBGImagePath;
            }
        }
Ejemplo n.º 2
0
 public Song()
 {
     this.enumType     = typeof(SongTextType);
     this.SongLyrics   = new ArrayList();
     this.Sequence     = new ArrayList();
     this.CurrentLyric = 0;
     this.Version      = DreamTools.GetAppVersion();
     wrapper           = new WordWrapAtSpace();
 }
Ejemplo n.º 3
0
        ///<summary>Saves the ImageList</summary>
        public void Save()
        {
            XmlTextWriter tw = new XmlTextWriter(DreamTools.GetDirectory(DirType.MediaLists, Name + ".xml"), null);

            tw.Formatting = Formatting.Indented;
            tw.WriteStartDocument();
            tw.WriteStartElement("MediaList");
            tw.WriteElementString("Version", DreamTools.GetAppVersion());
            for (int i = 0; i < Count; i++)
            {
                tw.WriteStartElement("MediaItem");
                tw.WriteElementString("Path", DreamTools.GetRelativePath(DirType.DataRoot, this.iItem[i].Path));
                tw.WriteEndElement();
            }
            tw.WriteEndElement();
            tw.WriteEndDocument();
            tw.Flush();
            tw.Close();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Handles serialization of the Config class, or of any types derived from it.
        /// </summary>
        /// <param name="instance">The instance to serialize</param>
        /// <param name="file">The XML file to serialize to</param>
        public static void SerializeTo(Config instance, string file)
        {
            Type          type = instance.GetType();
            XmlSerializer xs   = new XmlSerializer(type);

            file = Path.GetFullPath(file);
            Directory.CreateDirectory(Path.GetDirectoryName(file));
            FileStream fs = null;

            instance.Version = DreamTools.GetAppVersion();

            try {
                fs = File.Open(file, FileMode.Create, FileAccess.Write, FileShare.Read);
                xs.Serialize(fs, instance);
            } catch (Exception e) {
                Console.WriteLine(e.Message);
            } finally {
                if (fs != null)
                {
                    fs.Close();
                }
            }
        }
Ejemplo n.º 5
0
 public Config()
 {
     Version = DreamTools.GetAppVersion();
     Init();
 }
Ejemplo n.º 6
0
 public Theme()
 {
     Version = DreamTools.GetAppVersion();
 }