////////////////////////////////////////////////////////////////////////////////
//
// @module Quick Save for Unity3D
// @author Michael Clayton
// @support clayton.inds+support@gmail.com
//
////////////////////////////////////////////////////////////////////////////////
using System.Collections.Generic;
using CI.QuickSave.Core.Storage;
using CI.QuickSave.Core.Util;
namespace CI.QuickSave
{
public class QuickSaveRaw
{
///
/// Saves a string directly to the specified file, overwriting if it already exists
///
/// The file to save to
/// The string to save
public static void SaveString(string path, string content) => SaveString(path, content, new QuickSaveSettings());
///
/// Saves a string directly to the specified file using the specified settings, overwriting if it already exists
///
/// The file to save to
/// The string to save
/// Settings
public static void SaveString(string path, string content, QuickSaveSettings settings)
{
var contentToWrite = DataService.PrepareSaveData(content, settings);
if (!FileAccess.SaveString(path, contentToWrite))
{
throw new QuickSaveException("Failed to write to file");
}
}
///
/// Saves a byte array directly to the specified file, overwriting if it already exists
///
/// The file to save to
/// The byte array to save
public static void SaveBytes(string path, byte[] content)
{
if (!FileAccess.SaveBytes(path, content))
{
throw new QuickSaveException("Failed to write to file");
}
}
///
/// Loads the contents of the specified file into a string
///
/// The file to load from
/// The contents of the file as a string
public static string LoadString(string path) => LoadString(path, new QuickSaveSettings());
///
/// Loads the contents of the specified file into a string using the specified settings
///
/// The file to load from
/// Settings
/// The contents of the file as a string
public static string LoadString(string path, QuickSaveSettings settings)
{
var content = FileAccess.LoadString(path);
if (content == null)
{
throw new QuickSaveException("Failed to load file");
}
return DataService.PrepareLoadedData(content, settings);
}
///
/// Loads the contents of the specified file into a byte array
///
/// The file to load from
/// The contents of the file as a byte array
public static byte[] LoadBytes(string path)
{
byte[] content = FileAccess.LoadBytes(path);
if (content == null)
{
throw new QuickSaveException("Failed to load file");
}
return content;
}
///
/// Loads an asset stored in a resources folder
///
/// The type of asset to load
/// The path of the asset to load, relative to the Assets folder and without an extension
/// The specified asset
public static T LoadResource(string path) where T : UnityEngine.Object => UnityEngine.Resources.Load(path);
///
/// Deletes the specified file if it exists
///
/// The file to delete
public static void Delete(string path) => FileAccess.Delete(path);
///
/// Determines if the specified file exists
///
/// The file to check
/// Does the file exist
public static bool Exists(string path) => FileAccess.Exists(path);
///
/// Gets the names of all files in the specified directory
///
/// The path of the directory
/// The filenames of all the files in the directory
public static IEnumerable GetAllFiles(string directory) => FileAccess.GetFiles(directory);
}
}