Example #1
0
    bool loadFromDisk()

    /* attempts to load from disk. If the path returns false from SaveLoad.LoadManager, this will return false.
     * If loading is successful (the file exists and is accessible), then it will return true.
     * Otherwise, if the path is valid but a save file doesn't exist, then a new cameraManager is initialized and saved to the path.
     */
    {
        if (SaveLoad.path.Equals(""))
        {
            return(false);
        }
        if (SaveLoad.LoadManager(ref SM))
        {
            manager.fromSerializable(SM);

            print("read from disk: " + SaveLoad.path + "\n");
            return(true);
        }
        else if (SaveLoad.path.Equals(""))
        {
            print("no read file selected\n");
        }
        else
        {
            print("file " + SaveLoad.path + " doesn't exist.\n");
            print("new manager initialized and written to " + SaveLoad.path + "\n");
            CameraManager       blank             = new CameraManager();
            serializableManager blankSerializable = new serializableManager();
            blankSerializable.toSerializable(blank);
            SaveLoad.SaveManager(blankSerializable);
            return(true);
        }
        return(false);
    }
Example #2
0
 public void fromSerializable(serializableManager M)
 {
     position1.fromSerializable(M.position1);
     position2.fromSerializable(M.position2);
     position3.fromSerializable(M.position3);
     position4.fromSerializable(M.position4);
     position5.fromSerializable(M.position5);
     position6.fromSerializable(M.position6);
     position7.fromSerializable(M.position7);
     position8.fromSerializable(M.position8);
     position9.fromSerializable(M.position9);
     position0.fromSerializable(M.position0);
 }
    // tries to save serializableManager M to the given path, returns false if it is unsuccessful (e.g. the given path is protected)
    public static bool SaveManager(serializableManager M)
    {
        serializableManList.Add(M);
        BinaryFormatter bf = new BinaryFormatter();

        try{
            FileStream file = File.Create(path);
            bf.Serialize(file, SaveLoad.serializableManList[serializableManList.Count - 1]);
            file.Close();
            return(true);
        } catch (Exception) {
        }
        return(false);
    }
 // tries to save serializableManager M to the given path, returns false if it is unsuccessful (e.g. the given path does not exist)
 public static bool LoadManager(ref serializableManager M)
 {
     if (File.Exists(path) && !path.Equals(""))
     {
         try {
             BinaryFormatter bf   = new BinaryFormatter();
             FileStream      file = File.Open(path, FileMode.Open);
             M = (serializableManager)bf.Deserialize(file);
             file.Close();
             return(true);
         } catch (Exception) {
         }
     }
     return(false);
 }