/// <summary> /// Init IndexedFile with target manifest. /// </summary> /// <param name="Manifest"></param> public static void Init(string Manifest) { FileInfo ManifestFile = new FileInfo(Manifest); Installation00Path = ManifestFile.FullName; if (!ManifestFile.Directory.Exists) { ManifestFile.Directory.Create(); } BasePath = ManifestFile.Directory.FullName; if (!ManifestFile.Exists) { TheArk = new Installation00(); var content = JsonConvert.SerializeObject(TheArk); var file = Path.Combine(BasePath, Installation00Path); if (File.Exists(file)) { File.Delete(file); } File.WriteAllText(file, content); } else { TheArk = JsonConvert.DeserializeObject <Installation00>(File.ReadAllText(ManifestFile.FullName)); } foreach (var item in TheArk.Installations) { FileInfo InstallationFile = new FileInfo(Path.Combine(BasePath, "InstallationIndeices", item)); var installation = JsonConvert.DeserializeObject <Installation>(File.ReadAllText(InstallationFile.FullName)); Installation00.PresentingInstallations.Add(installation); } }
public static void DeleteFile(string PseudoLocation) { var index = Get(PseudoLocation); if (index is not null) { index.CoreFile.Delete(); var installation = Installation00.FindInstallation(index.ParentInstallation); installation.Indices.Remove(index); installation.Modified = true; } }
/// <summary> /// Store a copy of given file. /// </summary> /// <param name="fi"></param> /// <param name="PseudoLocation"></param> public static void StoreCpy(FileInfo fi, string PseudoLocation) { PseudoLocation = UnifyPseudoLocation(PseudoLocation); var installation = Installation00.GetInstallation(); var fileID = Guid.NewGuid(); { var index = Get(PseudoLocation); if (index != null) { File.Copy(fi.FullName, index.RealLocation, true); return; } } if (installation == Installation.Empty) { installation = new Installation(); installation.FolderID = Guid.NewGuid().ToString(); installation.Modified = true; var folder = Path.Combine(BasePath, installation.FolderID); if (!Directory.Exists(folder)) { Directory.CreateDirectory(folder); } var f = fi.CopyTo(Path.Combine(folder, fileID.ToString())); Index index = new Index(); index.RealLocation = f.Name; index.PseudoLocation = PseudoLocation; installation.Indices.Add(index); Installation00.PresentingInstallations.Add(installation); TheArk.Installations.Add(installation.FolderID); SaveIndeics(); } else { installation.Modified = true; var folder = Path.Combine(BasePath, installation.FolderID); var f = fi.CopyTo(Path.Combine(folder, fileID.ToString())); Index index = new Index(); index.RealLocation = f.Name; index.PseudoLocation = PseudoLocation; installation.Indices.Add(index); } }
/// <summary> /// Store a reference to given file. /// </summary> /// <param name="fi"></param> /// <param name="PseudoLocation"></param> public static void StoreRef(FileInfo fi, string PseudoLocation) { var installation = Installation00.GetInstallation(); var fileID = Guid.NewGuid(); PseudoLocation = UnifyPseudoLocation(PseudoLocation); var i = Get(PseudoLocation); if (i is not null) { i.RealLocation = fi.FullName; } else if (installation == Installation.Empty) { installation = new Installation(); installation.FolderID = Guid.NewGuid().ToString(); installation.Modified = true; var folder = Path.Combine(BasePath, installation.FolderID); if (!Directory.Exists(folder)) { Directory.CreateDirectory(folder); } Index index = new Index(); index.RealLocation = fi.FullName; index.PseudoLocation = PseudoLocation; installation.Indices.Add(index); Installation00.PresentingInstallations.Add(installation); TheArk.Installations.Add(installation.FolderID); SaveIndeics(); } else { installation.Modified = true; Index index = new Index(); index.RealLocation = fi.FullName; index.PseudoLocation = PseudoLocation; installation.Indices.Add(index); } }