Esempio n. 1
0
        private static object Load(string extension = defaultExtension)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.FileName   = "*." + extension;
            ofd.DefaultExt = extension;
            ofd.Filter     = "tibia helper files (*." + extension + ")|*." + extension;
            VersionedObject obj = null;

            if (ofd.ShowDialog() == true)
            {
                try
                {
                    string filename = Path.GetFullPath(ofd.FileName);

                    // Restore from file
                    var        formatter = new BinaryFormatter();
                    FileStream stream    = File.OpenRead(filename);
                    obj = formatter.Deserialize(stream) as VersionedObject;
                    stream.Close();
                    checkVersion(obj);
                    return(obj.obj);
                }
                catch (Exception)
                {
                    return(null);
                }
            }
            return(null);
        }
Esempio n. 2
0
 public static void checkVersion(VersionedObject obj)
 {
     if (obj.version == "0.0.0")
     {
         try
         {
             DataCollecter data = (DataCollecter)obj.obj;
         }
         catch (Exception)
         {
         }
     }
 }
Esempio n. 3
0
        private static bool Save(object toSave, string extension = defaultExtension)
        {
            bool            success;
            VersionedObject obj = new VersionedObject(toSave);

            SaveFileDialog sfd = new SaveFileDialog();

            sfd.FileName   = "*." + extension;
            sfd.DefaultExt = extension;
            sfd.Filter     = "tibia helper files (*." + extension + ")|*." + extension;

            if (sfd.ShowDialog() == true)
            {
                try
                {
                    string filename = Path.GetFullPath(sfd.FileName);

                    // Delete old file, if it exists
                    if (File.Exists(filename))
                    {
                        File.Delete(filename);
                    }

                    // Persist to file
                    FileStream stream    = File.Create(filename);
                    var        formatter = new BinaryFormatter();
                    formatter.Serialize(stream, obj);
                    stream.Close();
                    success = true;
                }
                catch (Exception)
                {
                    success = false;
                }
                return(success);
            }
            return(false);
        }