Exemplo n.º 1
0
        private NoteManager(string storagePath, StorageMethod method)
        {
            StoragePath   = storagePath;
            StorageMethod = method;

            Load();
        }
Exemplo n.º 2
0
 public static NoteManager GetManager(string storagePath = "notes.json", StorageMethod method = StorageMethod.Json)
 {
     if (!Managers.ContainsKey(storagePath))
     {
         Managers.Add(storagePath, new NoteManager(storagePath, method));
     }
     return(Managers[storagePath]);
 }
Exemplo n.º 3
0
        public (DataType t, object data) ReadData(StorageMethod storageSlot)
        {
            DataType t    = DataType.None;
            object   data = null;

            using (MemoryStream stream = new MemoryStream())
            {
                pngOriginal.WriteToStream(stream, true, true);
                stream.Seek(0, SeekOrigin.Begin);
            }

            bool hasEOF = false;
            int  IDATs  = 0;

            foreach (PNGChunk chunk in pngOriginal.Chunks)
            {
                if (chunk.Name == "_EOF")
                {
                    hasEOF = true;
                }
                if (chunk.Name == "IDAT")
                {
                    IDATs++;
                }
            }

            StegoProvider pr = Providers.XOREOF;

            if (storageSlot == StorageMethod.IDAT)
            {
                pr = Providers.XORIDAT;
            }

            if (!hasEOF && storageSlot == StorageMethod.EOF)
            {
                provider = null; Logger.Log($"There is no data in {storageSlot.ToString()}", Logger.LOG_LEVEL.ERR);
            }
            else if (IDATs <= 1)
            {
                provider = null; Logger.Log($"There is no data in {storageSlot.ToString()}", Logger.LOG_LEVEL.ERR);
            }
            else
            {
                try
                {
                    provider = (SteganographyProvider)Activator.CreateInstance(pr.ProviderType, pngOriginal, true);
                    provider.SetPassword(password);
                    t = provider.Extract(out data);
                    return(t, data);
                }
                catch (InvalidPasswordException)
                {
                    Logger.Log("The password was incorrect.", Logger.LOG_LEVEL.ERR);
                }
            }

            return(DataType.None, null);
        }
 /// <summary>
 /// Initializes the Selected queried Persistent Storage Method
 /// </summary>
 /// <returns>A boolean of whether the operation completed successfully or failed</returns>
 public bool Initialize()
 {
     if (StorageMethod == null)
     {
         return(false);
     }
     StorageMethod.Initialize();
     return(true);
 }
Exemplo n.º 5
0
 /// <summary>
 /// Initializs the Selected Cached Persistent Storage Method
 /// </summary>
 /// <returns>A boolean of whether the operation completed successfully or failed</returns>
 public bool Initialize()
 {
     if (StorageMethod == null)
     {
         return(false);
     }
     StorageMethod.Initialize();
     ((ICachedStorageMethod <T>)StorageMethod).UpdateCache();
     CurrentCache = ((ICachedStorageMethod <T>)StorageMethod).GetCache();
     return(true);
 }
Exemplo n.º 6
0
        public ShaderSource GetShaderFloat4(List <IVoxelModifierEmissionOpacity> modifiers)
        {
            var mixin = new ShaderMixinSource();

            mixin.Mixins.Add(writer);
            StorageMethod.Apply(mixin);
            foreach (var attr in modifiers)
            {
                ShaderSource applier = attr.GetApplier("Isotropic");
                if (applier != null)
                {
                    mixin.AddCompositionToArray("Modifiers", applier);
                }
            }
            return(mixin);
        }
Exemplo n.º 7
0
    /// <summary>
    /// Generic method used for reading save data
    /// </summary>
    /// <returns>Read data</returns>
    /// <param name="method">Storing method</param>
    /// <typeparam name="T">Typeof data to store</typeparam>
    public static T LoadFromFIle <T>(StorageMethod method, string name)
    {
        T storedData = default(T);

        string fileName = SavingLocation + name + "." + method.ToString().ToLower();

        Debug.Log("File: " + fileName);

        try
        {
            switch (method)
            {
            case StorageMethod.Binary:
                using (Stream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    BinaryFormatter formatter = new BinaryFormatter();
                    storedData = (T)formatter.Deserialize(stream);

                    stream.Close();
                    stream.Dispose();
                }
                break;

            case StorageMethod.XML:
                using (FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    XmlSerializer serializer = new XmlSerializer(typeof(T));
                    storedData = (T)serializer.Deserialize(stream);

                    stream.Close();
                    stream.Dispose();
                }
                break;

            case StorageMethod.JSON:
                string serializedData = File.ReadAllText(fileName);
                storedData = JsonUtility.FromJson <T>(serializedData);
                break;
            }
        }
        catch (System.Exception ex)
        {
            Debug.LogWarning("File reading error: " + ex.Message);
        }

        return(storedData);
    }
Exemplo n.º 8
0
        /// <summary>
        /// Saves the json.
        /// </summary>
        public static void SaveJson <T>(T data, string key, StorageMethod method = StorageMethod.JSON)
        {
            string json = JsonUtility.ToJson(data);

            string[] pathArray = key.Split('/');

            string path = GetFolderPath();

            if (pathArray.Length > 1)
            {
                for (int i = 0; i < pathArray.Length - 1; i++)
                {
                    path += "/" + pathArray[i];
                }
                SafeCreateDirectory(path);
            }

            string filePath = GetFilePath(key);

            Debug.Log(filePath);
            try
            {
                switch (method)
                {
                case StorageMethod.Binary:
                    BinaryFormatter bf   = new BinaryFormatter();
                    FileStream      file = File.Create(filePath);
                    bf.Serialize(file, json);
                    file.Close();
                    break;

                case StorageMethod.JSON:
                    File.WriteAllText(filePath, json);
                    break;
                }
            }
            catch (Exception ex)
            {
                Debug.LogWarning("エラー: " + ex.Message);
            }

#if UNITY_EDITOR
            AssetDatabase.Refresh();
#endif
        }
Exemplo n.º 9
0
    /// <summary>
    /// Generic method used for saving data
    /// </summary>
    /// <param name="dataToStore">Data to store</param>
    /// <param name="method">Storing method</param>
    /// <typeparam name="T">Typeof data to store</typeparam>
    public static void SaveToFile <T>(T dataToStore, StorageMethod method, string name)
    {
        string fileName = SavingLocation + name + "." + method.ToString().ToLower();

        Debug.Log("File: " + fileName);

        try
        {
            switch (method)
            {
            case StorageMethod.Binary:
                BinaryFormatter formatter = new BinaryFormatter();
                using (FileStream stream = new FileStream(fileName, FileMode.Create, FileAccess.Write))
                {
                    formatter.Serialize(stream, dataToStore);
                    stream.Close();
                    stream.Dispose();
                }
                break;

            case StorageMethod.XML:
                XmlSerializer serializer = new XmlSerializer(typeof(T));
                using (FileStream stream = new FileStream(fileName, FileMode.Create, FileAccess.Write))
                {
                    serializer.Serialize(stream, dataToStore);

                    stream.Close();
                }
                break;

            case StorageMethod.JSON:
                string serializedData = JsonUtility.ToJson(dataToStore, true);

                Debug.Log(serializedData);
                File.WriteAllText(fileName, serializedData);
                break;
            }
        }
        catch (System.Exception ex)
        {
            Debug.LogWarning("File writing error: " + ex.Message);
        }
    }
        virtual public ShaderSource GetVoxelizationShader(List <VoxelModifierEmissionOpacity> modifiers)
        {
            var mixin = new ShaderMixinSource();

            mixin.Mixins.Add(Writer);
            StorageMethod.Apply(mixin);
            foreach (var modifier in modifiers)
            {
                if (!modifier.Enabled)
                {
                    continue;
                }

                ShaderSource applier = modifier.GetApplier(ApplierKey);
                if (applier != null)
                {
                    mixin.AddCompositionToArray("Modifiers", applier);
                }
            }
            return(mixin);
        }
Exemplo n.º 11
0
        public void PrepareLocalStorage(VoxelStorageContext context, IVoxelStorage storage)
        {
            StorageMethod.PrepareLocalStorage(context, storage, 4, 1);

            Graphics.PixelFormat format = Graphics.PixelFormat.R16G16B16A16_Float;
            switch (StorageFormat)
            {
            case StorageFormats.RGBA8:
                format = Graphics.PixelFormat.R8G8B8A8_UNorm;
                break;

            case StorageFormats.R10G10B10A2:
                format = Graphics.PixelFormat.R10G10B10A2_UNorm;
                break;

            case StorageFormats.RGBA16F:
                format = Graphics.PixelFormat.R16G16B16A16_Float;
                break;
            }
            storage.UpdateTexture(context, ref IsotropicTex, format, 1);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Reads the json.
        /// </summary>
        static string ReadJson(string fileName, StorageMethod method)
        {
            string json     = string.Empty;
            string filePath = GetFilePath(fileName);

            if (!Application.isEditor)
            {
                CreateDir();
            }

            //		if (Application.platform == RuntimePlatform.IPhonePlayer) {
            //			// ファイルをコピー
            //			CopyFile(fileName);
            //		}

            try
            {
                switch (method)
                {
                case StorageMethod.Binary:
                    BinaryFormatter bf = new BinaryFormatter();
                    using (FileStream file = File.Open(filePath, FileMode.Open))
                    {
                        json = (string)bf.Deserialize(file);
                        file.Close();
                    }
                    break;

                case StorageMethod.JSON:
                    json = File.ReadAllText(filePath);
                    break;
                }
            }
            catch (Exception ex)
            {
                Debug.LogError(ex.Message);
            }
            return(json);
        }
Exemplo n.º 13
0
        /// <summary>Gets a specified storage path</summary>
        /// <param name="storageMethod">Method of storage</param>
        /// <returns>Directory path based on storage method</returns>
        public static string GetStorageFolder(StorageMethod storageMethod)
        {
            string path = string.Empty;

            //// -- Sample --
            //// Linux / Mac:
            ////  C:\Users\USERNAME\Documents\
            ////  path = Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);

            switch (storageMethod)
            {
            case StorageMethod.PortableApp:
                path = System.IO.Directory.GetCurrentDirectory();
                break;

            case StorageMethod.AllUsers:
                path = System.Environment.GetFolderPath(System.Environment.SpecialFolder.CommonApplicationData);
                path = System.IO.Path.Combine(path, "XI", "ToolsHub");
                break;

            case StorageMethod.SingleUser:
                // We're using local over roaming because we don't want settings uploaded to server if user is on a domain.
                path = System.Environment.GetFolderPath(System.Environment.SpecialFolder.LocalApplicationData);
                path = System.IO.Path.Combine(path, "XI", "ToolsHub");
                break;

            case StorageMethod.Unknown:
            case StorageMethod.UnitTest:
            default:
                //// pth = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
                path = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "ToolsHubTests");
                break;
            }

            return(path);
        }
Exemplo n.º 14
0
        public bool HideFileSystem(string imagePath, string fileSystemData, string password = "", StorageMethod storageMethod = StorageMethod.EOF)
        {
            StegoProvider prov;

            if (storageMethod == StorageMethod.EOF)
            {
                prov = Providers.XOREOF;
            }
            else
            {
                prov = Providers.XORIDAT;
            }

            provider = (SteganographyProvider)Activator.CreateInstance(prov.ProviderType, imagePath, false);
            provider.SetPassword(password, false);

            if (Imprint(DataType.FileSystem, fileSystemData))
            {
                using (FileStream fs = File.Open(imagePath, FileMode.Create, FileAccess.Write, FileShare.Read))
                    provider.WriteToStream(fs);

                return(true);
            }

            return(false);
        }
Exemplo n.º 15
0
        /// <summary>
        /// Loads the data.
        /// </summary>
        /// <returns>The data.</returns>
        /// <param name="fileName">File name.</param>
        /// <typeparam name="T">The 1st type parameter.</typeparam>
        private static T LoadData <T>(string fileName, StorageMethod method)
        {
            T data = JsonUtility.FromJson <T>(ReadJson(fileName, method));

            return(data);
        }
 virtual public int PrepareLocalStorage(VoxelStorageContext context, IVoxelStorage storage)
 {
     return(StorageMethod.PrepareLocalStorage(context, storage, 4, LayoutCount));
 }
Exemplo n.º 17
0
 public SaveManager(StorageMethod method)
 {
     _savingLocation = Application.persistentDataPath;
     _method         = method;
 }
Exemplo n.º 18
0
 public SettingsManager(StorageMethod storageMethod)
 {
     StorageMethod = storageMethod;
 }
Exemplo n.º 19
0
 public static T Load <T>(StorageMethod method = StorageMethod.JSON)
 {
     return(LoadData <T>(typeof(T).Name, method));
 }