Exemple #1
0
        public bool LoadBinaryFile(string nameOfFile, out Leaderboard leaderboard)
        {
            string output = String.Empty;

            leaderboard = new Leaderboard();

            string fileName = Application.persistentDataPath + m_pathToFile + nameOfFile;

            //TODO check if file exists
            try {
                byte[] encrypted;
                encrypted = File.ReadAllBytes(fileName);                  //TODO Read in chunks

                output = XOREncrypt.DecryptStringFromBytes(encrypted);

                print("Output: " + output);
                leaderboard = JsonUtility.FromJson <Leaderboard> (output);
                print("Reading from file: " + output);
                return(true);
            } catch (System.Exception ex) {
                output = "Exceção de IO na leitura: " + ex.Message;
                print("Deu merda");
                return(false);
            }
        }
        void Test2()
        {
            XOREncrypt.Test();
            Leaderboard leaderboard = LoadOrCreateLeaderboard("Stage 1");

            Score score  = new Score(65, "Stage 1 part 1", DateTime.Now.ToShortTimeString());
            Score score2 = new Score(21, "Stage 1 part 2", DateTime.Now.ToShortTimeString());

            AddScore(leaderboard, score);
            AddScore(leaderboard, score2);

            //print (JsonUtility.ToJson (leaderboard));
        }
Exemple #3
0
        //private static readonly int CHUNK_SIZE = 1024;

        public bool SaveBytesToFile(string fileName, string fileToSave, bool overwrite = true)
        {
            string path = Application.persistentDataPath + m_pathToFile + fileName;

            try {
                //fileToSave = XOREncrypt.EncryptStringToBytes(fileToSave); //TODO SCRAMBLE this with unique ID from device
                print("Unique ID: " + SystemInfo.deviceUniqueIdentifier);
                byte[] encrypted = XOREncrypt.EncryptStringToBytes(fileToSave);
                using (BinaryWriter binaryWriter = new BinaryWriter(File.Open(path, FileMode.OpenOrCreate))) {                   //overwrite ? File.CreateText(path) : File.AppendText(path)
                    //TODO write in chunks
                    binaryWriter.Write(encrypted);
                    return(true);
                }
            } catch (System.Exception ex) {
                fileToSave = "Exceção de IO na escrita: " + ex.Message;
                return(false);
            }
        }