public void Test_Zip_Folder_Contains_All_Files_And_Match_Content([Values(ArchiveType.Zip, ArchiveType.GZip)] ArchiveType archiveType) { // Arrange var testFiles = new List <DotNetHelper_IO.FileObject>() { RandomTestFileNoExtension, RandomTestFileNoExtension, RandomTestFileNoExtension }; testFiles.ForEach(f => f.Write("A")); var folderWithTestFile = new FolderObject(testFiles.First().FilePathOnly); var zipFileName = folderWithTestFile.FullName + $"{folderWithTestFile.Name}.zip"; var zipFile = folderWithTestFile.ZipFolderToFileSystem(zipFileName, ArchiveType.Zip, null, "*", SearchOption.AllDirectories); using (var archive = zipFile.GetReadableArchive()) { foreach (var entry in archive.Entries) { Assert.Contains(entry.Key, testFiles.Select(f => f.Name).ToList()); var stream = entry.OpenEntryStream(); var content = stream.ReadToString(); Assert.That(content.Equals(testFiles.First(f => f.FileNameOnly == entry.Key).ReadAllText())); } } Assert.That(zipFile.GetEntriesCount(), Is.EqualTo(testFiles.Count)); }
void OnEnable() { lastTool = Tools.current; Tools.current = Tool.None; if (folderObject == null) { folderObject = target as FolderObject; } if (folderObject.hideChildrenInHierarchy) { foreach (Transform child in folderObject.transform) { child.hideFlags |= HideFlags.HideInHierarchy; } } else { foreach (Transform child in folderObject.transform) { child.hideFlags &= ~HideFlags.HideInHierarchy; } } EditorApplication.RepaintHierarchyWindow(); }
public static FolderModel GetFolderInfo(string id, string path) { string folder = new DirectoryInfo(path).Name; CategoryModel category = JsonConvert.DeserializeObject <CategoryModel>(File.ReadAllText(Path.Combine(path, folder + ".info"))); FolderObject fl = new FolderObject(); fl.id = id; fl.name = category.title; string parentName = new DirectoryInfo(path).Parent.Name; if (FindFolderById(parentName.Split('.')[0], PathHelper.GetRepoPath()) == null) { fl.type = FolderType.Category.ToString(); fl.parent = null; } else { fl.type = FolderType.Product.ToString(); fl.parent = parentName; } FolderModel model = new FolderModel(); model.folder = fl; //string json = "{ folder:\"" + JsonConvert.SerializeObject(fl) + "\"}"; return(model); }
private static void InitApp() { DependencyResolver.GetInstance <ILogger>().ConsoleAndLog("Initializing application...."); PurgeFolder = new FolderObject(Default.PurgeFolder, true, false, false); // DELETE ALL SUBFOLDERS THATS NOT SUPPOSE TO BE THEIR PurgeFolder.Subfolders .Where(sf => !FolderTypes.Select(f => f.ToString()).Contains(sf.FolderNameOnly)).ToList() .ForEach(delegate(FolderObject o) { o.DeleteFolder(); DependencyResolver.GetInstance <ILogger>().ConsoleAndLog($"Deleting Folder {o.FullFolderPath} because it doesn't belong in this directory"); }); foreach (var type in FolderTypes) { if (PurgeFolder.Subfolders.Where(subfolder => subfolder.FolderNameOnly == type.ToString()).IsNullOrEmpty()) { using (var newFolder = new FolderObject(PurgeFolder.FullFolderPath + type + Path.DirectorySeparatorChar)) { DependencyResolver.GetInstance <ILogger>().ConsoleAndLog($"Creating Folder {newFolder.FullFolderPath}"); newFolder.Create(); } } } PurgeFolder.RefreshObject(true, false, false); }
private static int CountFiles(FolderObject folderObject) { var amount = folderObject.Files?.Count ?? 0; foreach (var subFolder in folderObject.Folders) { amount += CountFiles(subFolder); } return(amount); }
public void CanSetPathOfFolderObject(string folderPath) { //Assign DataObject folder = new FolderObject(); string expectedResult = @"c:\Projects"; //Act folder.Path = folderPath; string result = folderPath; //Assert Assert.Equal(expectedResult, result); }
public void CanSetNameOfFolderObject(string folderPath) { //Assign DataObject folder = new FolderObject(); string expectedResult = "Projects"; //Act folder.Path = folderPath; folder.Name = folderPath.Name(); string result = folder.Name; //Assert Assert.Equal(expectedResult, result); }
public void CanSetLastAccessOfFolderObject(string folderPath) { //Assign DataObject folder = new FolderObject(); folder.Path = folderPath; string expectedResult = "2017/01/23 09:41:06.75"; //Act folder.LastAccess = folderPath.LastAccess(); string result = folder.LastAccess; //Assert Assert.Equal(expectedResult, result); }
public void CanSetSizeOfFolderObject(string folderPath) { //Assign DataObject folder = new FolderObject(); string expectedResult = "1.12MB"; folder.Path = folderPath; //Act folder.Size = folderPath.FolderSize(); string result = folder.Size; //Assert Assert.Equal(expectedResult, result); }
static void ProgramFlow() { Console.WriteLine("Welcome to AutoCopy :) !"); new ProfileFolder(); Console.WriteLine("Create new profile(y/n)"); string ans = Console.ReadLine(); if (ans == "y" || ans == "Y") { ProfileFolder.CreateProfile(); } FolderObject obj = ProfileFolder.SelectProfile(); Console.WriteLine("Pulse intro to close"); new CopyLog(obj); Console.ReadLine(); }
void BIFItems() { List <string> objects = new List <string>(); ResourceType curType = TypeMap[curItemType]; foreach (AuroraArchive archive in AuroraEngine.Resources.data.bifObjects) { if (archive.GetType() == typeof(RIMObject)) { RIMObject rim = (RIMObject)archive; foreach ((string name, ResourceType rt) in rim.resources.Keys) { if (rt != curType) { continue; } using (Stream stream = rim.GetResource(name, rt)) { GFFObject obj = new GFFLoader(stream).GetObject(); objects.Add((string)obj["TemplateResRef"].Value); } } } else if (archive.GetType() == typeof(FolderObject)) { FolderObject folder = (FolderObject)archive; foreach ((string name, ResourceType rt) in folder.resources.Keys) { if (rt != curType) { continue; } using (Stream stream = folder.GetResource(name, rt)) { GFFObject obj = new GFFLoader(stream).GetObject(); objects.Add((string)obj["TemplateResRef"].Value); } } } } bifItems = objects.ToArray(); }
public void FolderComponentRemoved() { if (folderObject == null) { folderObject = target as FolderObject; } folderObject.gameObject.GetComponent <Transform>().hideFlags = HideFlags.None; lockFolder = false; hideChildrenInHierarchy = false; if (folderObject.lockFolder != lockFolder) { folderObject.gameObject.hideFlags &= ~HideFlags.NotEditable; foreach (Component component in folderObject.GetComponents(typeof(Component))) { component.hideFlags &= ~HideFlags.NotEditable; } Tools.current = Tool.Move; EditorUtility.SetDirty(folderObject); folderObject.lockFolder = lockFolder; } if (folderObject.hideChildrenInHierarchy != hideChildrenInHierarchy) { foreach (Transform child in folderObject.transform) { child.hideFlags &= ~HideFlags.HideInHierarchy; } EditorApplication.RepaintHierarchyWindow(); folderObject.hideChildrenInHierarchy = hideChildrenInHierarchy; } }
private static void DrawFolderIconInHierarchy(int instanceID, Rect folderObjectRect) { GameObject folderGameObject = EditorUtility.InstanceIDToObject(instanceID) as GameObject; if (folderGameObject && folderGameObject.GetComponent <FolderObject>()) { FolderObject folderObject = folderGameObject.GetComponent <FolderObject>(); if (!folderObject.hideChildrenInHierarchy) { if (!folderIcon) { string folderIconPath = "Assets" + Directory.GetFiles(Application.dataPath, "FolderObjectIcon.png", SearchOption.AllDirectories)[0].Substring(Application.dataPath.Length).Replace('\\', '/'); folderIcon = AssetDatabase.LoadAssetAtPath(folderIconPath, typeof(Texture2D)) as Texture2D; } GUI.Box(new Rect(folderObjectRect.xMax - folderIconSize - 2.0f, folderObjectRect.center.y - (folderIconSize / 2.0f), folderIconSize, folderIconSize), folderIcon, GUIStyle.none); } else { if (!hiddenIcon) { string hiddenIconPath = "Assets" + Directory.GetFiles(Application.dataPath, "FolderHiddenIcon.png", SearchOption.AllDirectories)[0].Substring(Application.dataPath.Length).Replace('\\', '/'); hiddenIcon = AssetDatabase.LoadAssetAtPath(hiddenIconPath, typeof(Texture2D)) as Texture2D; } GUI.Box(new Rect(folderObjectRect.xMax - folderIconSize - 2.0f, folderObjectRect.center.y - (folderIconSize / 2.0f), folderIconSize, folderIconSize), hiddenIcon, GUIStyle.none); } if (folderObject.lockFolder) { if (!lockedIcon) { string lockedIconPath = "Assets" + Directory.GetFiles(Application.dataPath, "FolderLockedIcon.png", SearchOption.AllDirectories)[0].Substring(Application.dataPath.Length).Replace('\\', '/'); lockedIcon = AssetDatabase.LoadAssetAtPath(lockedIconPath, typeof(Texture2D)) as Texture2D; } GUI.Box(new Rect(folderObjectRect.xMax - folderIconSize - 20.0f, folderObjectRect.center.y - (folderIconSize / 2.0f), folderIconSize, folderIconSize), lockedIcon, GUIStyle.none); } } }
public CopyAsyncTestFixture() { TestFolder = new FolderObject(WorkingDirectory); }
public MoveOperationTextFixture() { TestFolder = new FolderObject(WorkingDirectory + Path.DirectorySeparatorChar + nameof(MoveOperationTextFixture)); }
public CopyTestFixture() { TestFolder = new FolderObject(WorkingDirectory + Path.DirectorySeparatorChar + nameof(CopyTestFixture)); }
public static FolderObject WalkDirectoryTree(this FolderObject folderObject, DirectoryInfo root) { folderObject.Name = root.Name; folderObject.FullPath = root.FullName; FileInfo[] files = null; try { files = root.GetFiles("*.*"); } catch (UnauthorizedAccessException e) { Console.WriteLine(e.Message); } catch (DirectoryNotFoundException e) { Console.WriteLine(e.Message); } if (files != null && files.Any()) { foreach (var fi in files) { FileObject file; try { using (Stream stream = File.OpenRead(fi.FullName)) { using (var srcImg = Image.FromStream(stream, false, false)) { file = new FileObject(fi.Name, srcImg.Width.ToString(), srcImg.Height.ToString()); } } } catch (Exception) // it is a video ! { var inputFile = new MediaFile { Filename = fi.FullName }; using (var engine = new Engine()) { engine.GetMetadata(inputFile); } if (inputFile.Metadata == null) { continue; } if (inputFile.Metadata.VideoData == null) { continue; } var size = inputFile.Metadata.VideoData.FrameSize.Split('x'); file = new FileObject(fi.Name, size.First(), size.Last()); } folderObject.Files.Add(file); } } var subDirs = root.GetDirectories(); if (subDirs.Any()) { foreach (var dirInfo in subDirs) { folderObject.Folders.Add(WalkDirectoryTree(new FolderObject(), dirInfo)); } } return(folderObject); }
static void Main(string[] args) { #region Checking state var error = false; if (!File.Exists($"{Environment.CurrentDirectory}\\poivre")) { Console.WriteLine("> Error. Can't find password file. ABORT!"); error = true; } if (!File.Exists($"{Environment.CurrentDirectory}\\sel")) { Console.WriteLine("> Error. Can't find salt file. ABORT!"); error = true; } if (!File.Exists($"{Environment.CurrentDirectory}\\settings")) { Console.WriteLine("> Error. Can't find settings file. ABORT!"); error = true; } if (error) { Console.ReadLine(); Environment.Exit(-1); } Password = File.ReadAllText($"{Environment.CurrentDirectory}\\poivre"); Salt = File.ReadAllText($"{Environment.CurrentDirectory}\\sel"); var settings = File.ReadAllText($"{Environment.CurrentDirectory}\\settings").Split(';'); var originPath = settings.First(); var originExists = Directory.Exists(originPath); var destPath = settings.Last(); var destExists = Directory.Exists(destPath); if (!originExists || !destExists) { if (!originExists) { Console.WriteLine($"> Error. The origin directory does not exists : {originPath}."); } if (!destExists) { Console.WriteLine($"> Error. The destination directory does not exists : {destPath}."); } Console.ReadLine(); Environment.Exit(-1); } Console.WriteLine("- [OK]"); Console.WriteLine("> Checkup prerequisites done"); Console.WriteLine($"- Origin directory path : {originPath}"); Console.WriteLine($"- Destination directory path : {destPath}"); Console.WriteLine($"- [Encrypt mode active?] : {!DoDecrypt}"); Console.WriteLine("< Continue ?"); Console.ReadLine(); var stopWatch = new Stopwatch(); stopWatch.Start(); #endregion //Checking state #region //////////////// DECRYPT if (DoDecrypt) { Console.WriteLine("- [OK]"); Console.WriteLine($"> Begin decryption of files in {destPath}"); DecryptFiles(new DirectoryInfo(destPath)); Console.WriteLine("< Decryption done. Shutting down"); stopWatch.Stop(); Console.WriteLine($"\nExecuted in {stopWatch.ElapsedMilliseconds} ms"); Console.ReadLine(); Environment.Exit(0); } #endregion ///////////// DECRYPT #region //////////////// ENCRYPT Console.WriteLine("> Starting mapping generation"); MappedTree = new FolderObject(); MappedTree.WalkDirectoryTree(new DirectoryInfo(originPath)); var nbFilesToTreat = CountFiles(MappedTree); Console.WriteLine("- [OK] Mapping generation done"); Console.WriteLine("< Continue ?"); Console.ReadLine(); Console.WriteLine("> Begin files encryption from originPath"); FlattenedTree = new FolderObject(MappedTree.Name, MappedTree.FullPath, new List <FileObject>(MappedTree.Files), new List <FolderObject>(MappedTree.Folders)); for (var i = 0; i < FlattenedTree.Folders.Count; i++) { FlattenedTree.Folders.AddRange(FlattenedTree.Folders[i].Folders); } EncryptFiles(new DirectoryInfo(originPath), new DirectoryInfo(destPath)); var nbFilesTreated = new DirectoryInfo(destPath).GetFiles().Length; Console.WriteLine($"- {nbFilesTreated} files have been treated on {nbFilesToTreat}"); if (nbFilesTreated == nbFilesToTreat) { Console.WriteLine("- [OK]"); Console.WriteLine("> Begin mapping encryption"); GenerateEncryptedJson(new DirectoryInfo(destPath)); Console.WriteLine("- Mapping encryption done"); Console.WriteLine($"- Output path : {destPath}\\mapping.json"); Console.WriteLine("< All files have been treated. Shutting down"); } else { Console.WriteLine("- [KO]"); Console.WriteLine("- Not all files have been treated ..."); Console.WriteLine("< Abort mapping encryption. Shutting down"); } stopWatch.Stop(); Console.WriteLine($"\nExecuted in {stopWatch.ElapsedMilliseconds} ms"); Console.ReadLine(); Environment.Exit(0); #endregion ///////////// ENCRYPT }
public MoveTestFixture() { TestFolder = new FolderObject(WorkingDirectory); }
public IncrumentTest() { TestFolder = new FolderObject(WorkingDirectory); TestFile = new FileObject(TestFolder.FullName + "UnitTestFile"); }
public override void OnInspectorGUI() { if (folderObject == null) { folderObject = target as FolderObject; } if (folderObject.gameObject.GetComponent <Transform>().hideFlags != HideFlags.HideInInspector) { folderObject.gameObject.GetComponent <Transform>().hideFlags = HideFlags.HideInInspector; } lockFolder = folderObject.lockFolder; hideChildrenInHierarchy = folderObject.hideChildrenInHierarchy; GUILayout.Space(15); lockFolder = EditorGUILayout.Toggle(" Lock Folder?", lockFolder); if (FolderObjectOptions.displayFolderToggleDescriptions) { EditorGUILayout.HelpBox("This option prevents the Folder object from being deleted or changed (does not apply to children).", MessageType.None); } GUILayout.Space(15); hideChildrenInHierarchy = EditorGUILayout.Toggle(" Hide Children?", hideChildrenInHierarchy); if (FolderObjectOptions.displayFolderToggleDescriptions) { EditorGUILayout.HelpBox("This option hides all of the Folder's children in the Hierarchy window. This has no effect on child GameObject's active or visible states in the Scene.", MessageType.None); } GUILayout.Space(20); if (GUI.changed) { if (folderObject.lockFolder != lockFolder) { if (lockFolder) { folderObject.gameObject.hideFlags |= HideFlags.NotEditable; foreach (Component component in folderObject.GetComponents(typeof(Component))) { if (component == folderObject) { component.hideFlags &= ~HideFlags.NotEditable; } else { component.hideFlags |= HideFlags.NotEditable; } } EditorUtility.SetDirty(folderObject); } else { folderObject.gameObject.hideFlags &= ~HideFlags.NotEditable; foreach (Component component in folderObject.GetComponents(typeof(Component))) { component.hideFlags &= ~HideFlags.NotEditable; } Tools.current = Tool.Move; EditorUtility.SetDirty(folderObject); } folderObject.lockFolder = lockFolder; } if (folderObject.hideChildrenInHierarchy != hideChildrenInHierarchy) { if (hideChildrenInHierarchy) { foreach (Transform child in folderObject.transform) { child.hideFlags |= HideFlags.HideInHierarchy; } } else { foreach (Transform child in folderObject.transform) { child.hideFlags &= ~HideFlags.HideInHierarchy; } } EditorApplication.RepaintHierarchyWindow(); folderObject.hideChildrenInHierarchy = hideChildrenInHierarchy; } EditorUtility.SetDirty(target); } }
public ZipObjectTextFixture() { TestFolder = new FolderObject(WorkingDirectory); }