protected void Recompile(string compositFilePath, string inputFolder, CrcsProject project) { var ep = new ExecuteProgram(); var apiLevel = project.Properties.ApiLevel; var arguments = new StringBuilder(); arguments.Append("-jar \"").Append(_smaliFile).Append("\""); arguments.Append(" \"").Append(inputFolder).Append("\""); string classesDexFile = Path.Combine(FolderUtility.CreateTempFolder(), "classes.dex"); arguments.Append(" -o \"").Append(classesDexFile).Append("\""); if (_useSmaliApiLevel) { arguments.Append(" -a ").Append(apiLevel); } if (ep.Execute(_javaFile, arguments.ToString(), Path.GetDirectoryName(classesDexFile)) != 0) { throw ep.CreateException(Path.GetFileName(_smaliFile)); } // add to program file apk/jar... using (var zf = new AndroidArchive(compositFilePath)) { zf.Add(classesDexFile, Path.GetFileName(classesDexFile)); } }
public void IsTemporaryFile_Test(string fileName, bool expected) { var folderUtility = new FolderUtility(); var actual = folderUtility.IsTemporaryFile(fileName); Assert.Equal(expected, actual); }
public static bool SolutionContainsProject(string solutionFile, string projectFile) { var projectFileName = Path.GetFileName(projectFile); if (projectFileName == null) { return(false); } var solutionPath = Path.GetDirectoryName(solutionFile); XDocument xdoc = XDocument.Load(solutionFile); IEnumerable <XElement> projectFilesElements = xdoc.Descendants("Projects").Descendants("Item"); foreach (XElement xnode in projectFilesElements) { if (!xnode.Value.EndsWith(projectFileName, StringComparison.OrdinalIgnoreCase)) { continue; } string path = FolderUtility.GetRootedPath(solutionPath, xnode.Value); if (path.Equals(projectFile, StringComparison.OrdinalIgnoreCase)) { return(true); } } return(false); }
public void IsConfigCommand_Test(string input, bool expected) { var folderUtility = new FolderUtility(); var actual = folderUtility.IsConfigCommand(input); Assert.Equal(expected, actual); }
public static void CheckForNewDataTypes() { // Doesnt find type if no assets of it exist. List <DataType> allDataTypeAssets = FolderUtility.FindAssetsByType <DataType>(); List <DataManagerSettingsEntry> possibleEntries = new List <DataManagerSettingsEntry>(); List <DataManagerSettingsEntry> entriesToAdd = new List <DataManagerSettingsEntry>(); DataManagerSettingsAccessor.Settings.ResetEntriesList(); // Checks the all the different kinds of data types foreach (DataType asset in allDataTypeAssets) { DataManagerSettingsEntry newEntry = new DataManagerSettingsEntry(asset.AssemblyName, asset.TypeAsString); bool isAlreadyPossibleEntry = false; // Checks the list of possible entries for duplicates. foreach (DataManagerSettingsEntry possibleEntry in possibleEntries) { if (newEntry.Compare(newEntry, possibleEntry) == 0) { isAlreadyPossibleEntry = true; break; } } // Adds to possible entries if no duplicates exist. if (!isAlreadyPossibleEntry) { possibleEntries.Add(newEntry); } } // Checks the list of possible entries against the list of existing entries to see if any should be added. foreach (DataManagerSettingsEntry possibleEntry in possibleEntries) { bool isAlreadyEntry = false; // Comparing possible entries against existing entries. foreach (DataManagerSettingsEntry entry in DataManagerSettingsAccessor.Settings.EntriesArray) { if (possibleEntry.Compare(possibleEntry, entry) == 0) { isAlreadyEntry = true; break; } } // Adds possible entries to the add list if they're no duplicates already existing. if (!isAlreadyEntry) { entriesToAdd.Add(possibleEntry); } } // Adds the new entries to the settings list. foreach (DataManagerSettingsEntry entry in entriesToAdd) { DataManagerSettingsAccessor.Settings.AddEntry(entry); } }
public void ProcessFile(object fileObject, Func <bool> isCanceled) { if (fileObject == null) { throw new ArgumentNullException("fileObject"); } var file = fileObject as ApkFile; if (file == null) { throw new Exception(string.Format("{0} can not handle object of type {1}", GetType().Name, fileObject.GetType().Name)); } if (!FolderUtility.Empty(file.ResourceFolder)) { return; } MessageEngine.AddInformation(this, string.Format("Extracting content png files from {0}", file.Name)); using (var zf = new ZipFile(file.FileSystemPath)) { zf.Extract( zf.Entries.Where( x => x.Name.EndsWith(".PNG", StringComparison.OrdinalIgnoreCase) && !x.Name.EndsWith(".9.PNG", StringComparison.OrdinalIgnoreCase)), file.ResourceFolder, true); } }
private bool AddNewProject() { var form = new ProjectWizard(false); if (form.ShowDialog() == DialogResult.OK) { try { Cursor = Cursors.WaitCursor; toolStripStatusText.Text = "Creating project..."; if (form.CopySourceFilesToTargetLocation) { FolderUtility.CopyRecursive(form.SourceLocation, form.ProjectLocation, FileExistsQuestion); } CrcsProject rsproj = CrcsProject.CreateProject(form.ProjectFileName, _solution); rsproj.Save(); _solution.AddProject(rsproj); return(true); } finally { Cursor = Cursors.Default; } } return(false); }
public void ProcessFile(object fileObject, Func <bool> isCanceled) { if (fileObject == null) { throw new ArgumentNullException("fileObject"); } var file = fileObject as ApkFile; if (file == null) { throw new Exception(string.Format("{0} can not handle object of type {1}", GetType().Name, fileObject.GetType().Name)); } if (FolderUtility.Empty(file.ResourceFolder)) { return; } MessageEngine.AddInformation(this, string.Format("Updating {0} with optimized png files", file.Name)); using (var zf = new AndroidArchive(file.FileSystemPath)) { foreach (string pngFile in file.GetPngFilesToOptimize()) { zf.Add(pngFile, FolderUtility.GetRelativePath(file.ResourceFolder, pngFile), CompressionType.Store); } } }
public void GetFileName_ReturnsTrue_Test(string filePath, string expected) { var folderUtility = new FolderUtility(); var fileName = folderUtility.GetFileName(filePath); Assert.Equal(expected, fileName); }
public void DoesArrayContentExists_Test(int position, bool expected, string[] testArray) { var folderUtility = new FolderUtility(); var actual = folderUtility.DoesArrayContentExists(testArray, position); Assert.Equal(expected, actual); }
/// <summary> /// This method is prompting to console question to print log to the file /// </summary> /// <param name="utility"></param> static void PrintLogOption(FolderUtility utility) { Console.WriteLine("Type y if you want to print log to root folder"); string option = Console.ReadLine(); if (option == "y") { utility.PrintLogTxtInFolder(); } }
/// <summary> /// This method is prompting to console to-delete folder question /// </summary> /// <param name="utility"></param> static void DeleteOption(FolderUtility utility) { Console.WriteLine("Type y if you want to delete empty folders"); string option = Console.ReadLine(); if (option=="y") { utility.DeleteEmptyFolder(); } }
private void ScriptChangesClicked(object sender, EventArgs args) { string catalogDirectory = FolderUtility.GetDirectory(String.Empty); using (Frontend.Client.Windows.StatusForm statusForm = new Frontend.Client.Windows.StatusForm(Strings.ComparingSchema)) { Dataphoria.EvaluateAndEdit(String.Format(".System.ScriptLibraryChanges('{0}', '{1}')", catalogDirectory.Replace("'", "''"), LibraryName), "d4"); } }
private void ButtonBrowseProjectLocationClick(object sender, EventArgs e) { var sfd = FolderUtility.CreateBrowseForFolder(textBoxProjectLocation.Text); if (sfd.ShowDialog(this) == DialogResult.OK) { textBoxProjectLocation.Text = Path.GetDirectoryName(sfd.FileName); } }
public IEnumerable <ApkEntry> GetApkEntries() { var items = new List <ApkEntry>(); int index = 1; using (var zf = new ReadOnlyZipFile(FileSystemPath)) { items.AddRange(zf.Entries.Select(entry => new ApkEntry(entry, index++, ResourceFolder))); } if (Directory.Exists(ResourceFolder)) { var files = FolderUtility.GetFilesRecursively(ResourceFolder, "*.*", string.Format("{0}build{0}apk", Path.DirectorySeparatorChar)); items.AddRange( files.Where( x => items.FirstOrDefault(y => y.FileSystemPath.Equals(x, StringComparison.OrdinalIgnoreCase)) == null).Select(path => new ApkEntry(path, ResourceFolder))); items.RemoveAll(x => x.RelativePath.EndsWith("apktool.yml", StringComparison.OrdinalIgnoreCase)); items.Sort((a, b) => string.Compare(a.RelativePath, b.RelativePath)); ChangePosition(items, "classes.dex", 0); ChangePosition(items, "AndroidManifest.xml", 0); ChangePosition(items, "META-INF/CERT.RSA", 0); ChangePosition(items, "META-INF/CERT.SF", 0); ChangePosition(items, "META-INF/MANIFEST.MF", 0); ChangePosition(items, "resources.arsc", -1); } var publicXmlFile = Path.Combine(ResourceFolder, "res", "values", "public.xml"); if (File.Exists(publicXmlFile)) { var xdoc = XDocument.Load(publicXmlFile); foreach (var item in items) { string type = ""; if (item.RelativePath.IndexOf("drawable", StringComparison.OrdinalIgnoreCase) > -1) { type = "drawable"; } else if (item.RelativePath.IndexOf("raw", StringComparison.OrdinalIgnoreCase) > -1) { type = "raw"; } if (type.Length > 0) { var name = Path.GetFileNameWithoutExtension(item.FileSystemPath) ?? ""; name = name.EndsWith(".9") ? name.Substring(0, name.Length - 2) : name; var xnode = xdoc.Descendants("public").FirstOrDefault(x => x.Attribute("type").Value == type && x.Attribute("name").Value == name); if (xnode != null) { item.ResourceId = xnode.Attribute("id").Value; } } } } return(items.ToArray()); }
public void RevertToOriginal() { if (!HasBackupFile) { return; } FileUtility.MoveFile(FileBackup, FileSystemPath); FolderUtility.DeleteDirectory(WorkingFolder); _containsClassesDex = -1; HandleContentUpdatedExternaly(); }
public void IsExcelFile_ReturnsFalse_Test(string filePath) { var documentUtilityMock = new Mock <IDocumentUtility>(); var appSettingsMock = new Mock <IAppSettingsUtility>(); appSettingsMock.Setup(_ => _.ExcelDocumentExtension).Returns("xlsx"); var folderUtility = new FolderUtility(documentUtilityMock.Object, documentUtilityMock.Object, appSettingsMock.Object); var isExcelFile = folderUtility.IsExcelFile(filePath); Assert.False(isExcelFile); }
public void IsWordFile_ReturnsTrue_Test(string filePath) { var documentUtilityMock = new Mock <IDocumentUtility>(); var appSettingsMock = new Mock <IAppSettingsUtility>(); appSettingsMock.Setup(_ => _.WordDocumentExtension).Returns("docx"); var folderUtility = new FolderUtility(documentUtilityMock.Object, documentUtilityMock.Object, appSettingsMock.Object); var isWordFile = folderUtility.IsWordFile(filePath); Assert.True(isWordFile); }
/// <summary> /// Retrieves all subfolders under R, RRO or MRO /// </summary> /// <param name="directory"></param> /// <returns></returns> private static IEnumerable <string> GetRSubfolders(string directory) { string root = Path.GetPathRoot(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)); string baseRFolder = Path.Combine(root + @"Program Files\", directory); try { return(FolderUtility.GetSubfolderRelativePaths(baseRFolder)); } catch (IOException) { // Don't do anything if there is no RRO installed } return(Enumerable.Empty <string>()); }
private CrcsProject(string fileSystemPath, CrcsSolution solution) : base(fileSystemPath, false, null) { Solution = solution; FrameWorkFolder = FindFrameWorkFolder(); _properties = new ProjectProperties(this); _properties.PropertyChanged += ProjectPropertiesPropertyChanged; string apkToolFrameWorkFolder = CrcsSettings.Current.ApkToolFrameWorkFolder; FolderUtility.DeleteDirectory(apkToolFrameWorkFolder); Directory.CreateDirectory(apkToolFrameWorkFolder); // Project = this; }
/// <summary> Creates a new ScriptableObject asset, saves it that the given path if it exists, then returns the ScriptableObject. </summary> /// <typeparam name="T"> The type of ScriptableObject to be created. </typeparam> /// <param name="path"> The path of folder where the asset will be saved if it exists. </param> /// <returns> The new ScriptableObject that was created. </returns> public static T CreateAsset <T>(string path) where T : ScriptableObject { T asset = ScriptableObject.CreateInstance <T>(); // Creates the instance of the scriptable object. if (!AssetDatabase.IsValidFolder(path)) // Checks to make sure the path exists. { FolderUtility.CreateFolders(path); } SaveAssetInProjectFolders(asset, path); // Creates the asset in the project folders. return(asset); // Returns the scriptable object. }
public void ProcessFile(object fileObject, Func <bool> isCanceled) { if (fileObject == null) { throw new ArgumentNullException("fileObject"); } var file = fileObject as ApkFile; if (file == null) { throw new Exception(string.Format("{0} can not handle object of type {1}", GetType().Name, fileObject.GetType().Name)); } if (FolderUtility.Empty(file.ResourceFolder)) { return; } MessageEngine.AddInformation(this, string.Format("Optimizing png files for {0}", file.Name)); int allFiles = 0; int optimizedFiles = 0; foreach (string pngFile in file.GetPngFilesToOptimize()) { if (isCanceled()) { return; } var arguments = new StringBuilder(); arguments.Append(" -o7 -quiet"); arguments.Append(" -out \"").Append(pngFile + ".oz").Append("\""); arguments.Append(" \"").Append(pngFile).Append("\""); var ep = new ExecuteProgram((message) => MessageEngine.AddError(this, message)); if (ep.Execute(_optiPngFile, arguments.ToString(), Path.GetDirectoryName(pngFile)) != 0) { throw new Exception(string.Format("Program {0} failed", Path.GetFileName(_optiPngFile))); } if (File.Exists(pngFile + ".oz")) { FileUtility.MoveFile(pngFile + ".oz", pngFile); optimizedFiles++; } allFiles++; } file.SetPngOptimized(); MessageEngine.AddInformation(this, string.Format("\t {0} of {1} png files optimized", optimizedFiles, allFiles)); }
/// <summary> /// This methos is making object instances and move files to folders /// </summary> /// <param name="folderPath"></param> static void MoveFiles(string folderPath) { FolderUtility utility = new FolderUtility(folderPath); Folder music = new Folder("Music", folderPath, utility.MusicFilesExtensions); Folder movies = new Folder("Movies", folderPath, utility.MoviesFilesExtensions); Folder pictures = new Folder("Pictures", folderPath, utility.PictureFilesExtensions); Folder text = new Folder("Documents", folderPath, utility.TextFilesExtensions); music.MoveFilesToThisFolder(); movies.MoveFilesToThisFolder(); pictures.MoveFilesToThisFolder(); text.MoveFilesToThisFolder(); DeleteOption(utility); PrintLogOption(utility); }
private string CheckLocationsOfDependency(string additionalDependency) { string path = LocationsOfDependencies.FirstOrDefault(x => File.Exists(Path.Combine(x, additionalDependency))); if (path != null) { return(GetFileNameProperCasing(path, additionalDependency.ToUpperInvariant())); } string[] files = FolderUtility.GetFilesRecursively(ProjectPath, additionalDependency, _rsprojPathExclusion).ToArray(); if (files.Length == 0) { return(null); } return(Path.GetFileName(files[0])); }
public void GetFooterText_DefaultNoPath_Test() { var documentUtilityMock = new Mock <IDocumentUtility>(); var appSettingsMock = new Mock <IAppSettingsUtility>(); appSettingsMock.Setup(_ => _.CustomFooterText).Returns(""); appSettingsMock.Setup(_ => _.UseCustomFooterText).Returns(false); appSettingsMock.Setup(_ => _.DefaultFooterText).Returns("footer text"); appSettingsMock.Setup(_ => _.AppendFilePathToFooterText).Returns(false); var folderUtility = new FolderUtility(documentUtilityMock.Object, documentUtilityMock.Object, appSettingsMock.Object); var headerText = folderUtility.GetFooterText("c:\\folder"); Assert.Equal("footer text", headerText); }
public void GetHeaderText_CustomWithNullEmptyPath_Test(string customHeaderText, bool appendPath, string expected) { var documentUtilityMock = new Mock <IDocumentUtility>(); var appSettingsMock = new Mock <IAppSettingsUtility>(); appSettingsMock.Setup(_ => _.CustomHeaderText).Returns(customHeaderText); appSettingsMock.Setup(_ => _.UseCustomHeaderText).Returns(true); appSettingsMock.Setup(_ => _.DefaultHeaderText).Returns("header text"); appSettingsMock.Setup(_ => _.AppendFilePathToHeaderText).Returns(appendPath); var folderUtility = new FolderUtility(documentUtilityMock.Object, documentUtilityMock.Object, appSettingsMock.Object); var headerText = folderUtility.GetHeaderText("c:\\folder"); Assert.Equal(expected, headerText); }
public void GetHeaderText_CustomWithPath_Test() { var documentUtilityMock = new Mock <IDocumentUtility>(); var appSettingsMock = new Mock <IAppSettingsUtility>(); appSettingsMock.Setup(_ => _.CustomHeaderText).Returns("custom header text"); appSettingsMock.Setup(_ => _.UseCustomHeaderText).Returns(true); appSettingsMock.Setup(_ => _.DefaultHeaderText).Returns("header text"); appSettingsMock.Setup(_ => _.AppendFilePathToHeaderText).Returns(true); var folderUtility = new FolderUtility(documentUtilityMock.Object, documentUtilityMock.Object, appSettingsMock.Object); var headerText = folderUtility.GetHeaderText("c:\\folder"); Assert.Equal("custom header text c:\\folder", headerText); }
public void Save() { var root = new XElement("Solution"); var projects = new XElement("Projects"); foreach (CrcsProject proj in _projects) { string relativePath = FolderUtility.GetRelativePath(SolutionPath, proj.FileSystemPath); var xitem = new XElement("Item", relativePath.Replace(Path.DirectorySeparatorChar, '\\'), new XAttribute("IncludeInBuild", proj.IncludeInBuild)); projects.Add(xitem); } foreach (string missingProj in _missingProjects) { projects.Add(new XElement("Item", missingProj, new XAttribute("MainProject", false))); } if (projects.HasElements) { root.Add(projects); } var properties = new XElement("Properties"); foreach (PropertyInfo prop in _properties.GetType().GetProperties()) { if (prop.CanRead && prop.CanWrite && prop.InProjectFile().StoreInProjectFile) { object value = prop.GetValue(_properties, null); if (value == null) { continue; } var xElement = new XElement("Item", new XAttribute("Name", prop.Name)); xElement.Value = value.ToString(); properties.Add(xElement); } } if (properties.HasElements) { root.Add(properties); } root.Save(FileSystemPath); _isDirty = false; if (TabItemControl != null) { TabItemControl.EvaluateDirty(); } }
public void ProcessFile(object fileObject, Func <bool> isCanceled) { if (fileObject == null) { throw new ArgumentNullException("fileObject"); } var file = fileObject as CompositFile; if (file == null) { throw new Exception(string.Format("{0} can not handle object of type {1}", GetType().Name, fileObject.GetType().Name)); } if (!file.CanDecompile) { return; } if (file.IsDeCompiled) { return; } MessageEngine.AddInformation(this, string.Format("Decompiling classes for {0}", file.Name)); Directory.CreateDirectory(file.ClassesFolder); string dexFile = null; string classesFile; if (file.ContainsClassesDex) { dexFile = FileUtility.ExtractToTempDir(file.FileSystemPath, "classes.dex"); if (dexFile == null) { throw new Exception(string.Format("classes.dex could not be extracted from {0} ", file.Name)); } classesFile = dexFile; } else { classesFile = file.OdexFile; } Decompile(file.Name, classesFile, file.ClassesFolder, file.IgnoreDecompileErrors, file.Project); if (dexFile != null) { FolderUtility.DeleteDirectory(dexFile); } }
private void Report_PrintProgress(object sender, PrintProgressEventArgs e) { var(status, extra) = FolderUtility.CheckAndCreateCurrentPath("Transport List"); if (status == FolderUtilityStatus.Success) { var path = $"{extra}" + $"TransportList_{ReportManagerContext.GetInstance().CurrentInput.SERIAL_NO}.pdf"; if (!Directory.Exists(path)) { (sender as TransportListReport)?.ExportToPdf(path); } } else if (status == FolderUtilityStatus.Error) { XtraMessageBox.Show($"Не удалось сохранить отчет\n{extra}"); } }
/// <summary> /// Applications entry point. /// </summary> /// <param name="args">Optionally supply command line arguments</param> internal static void Main(string[] args) { var stopwatch = new Stopwatch(); try { stopwatch.Start(); //Print mandatory application meta information on console CommandLineHelper.PrintCopyright(); //Process command line arguments if any and set configuration settings var settings = ProcessCommandLineArguments(args); var config = SetApplicationConfiguration(settings); if (settings.VanityCommandRequested) { return; } //Initiate file processing IFolderUtility _folderUtility = new FolderUtility(new WordUtility(), new ExcelUtility(), new AppSettingsUtility(config)); _folderUtility.StartFileProcessing(); //Print diagnostics of the process stopwatch.Stop(); Console.WriteLine(); CommandLineHelper.WriteLog($"Completed in {stopwatch.ElapsedMilliseconds}ms"); } catch (Exception ex) { CommandLineHelper.WriteError($"Error: {ex.Message}"); } finally { Console.ResetColor(); stopwatch.Reset(); #if DEBUG CommandLineHelper.WriteLog("\nProgram ended"); Console.Read(); #endif } }
private void AddFolder(string fullPath, Dictionary <string, bool> projectFiles = null) { List <string> filesAndEmptyFolders = FolderUtility.GetFilesAndEmptyFoldersRecursively(fullPath, "*.*", _rsprojPathExclusion).ToList(); filesAndEmptyFolders.Remove(FileSystemPath); filesAndEmptyFolders.Remove(Solution.FileSystemPath); filesAndEmptyFolders.Remove(Solution.FileSystemPath + ".user"); foreach (string fileSystemPath in filesAndEmptyFolders) { if (Directory.Exists(fileSystemPath)) { if (projectFiles != null && !projectFiles.ContainsKey(fileSystemPath)) { continue; } _items.Add(new ProjectFolder(fileSystemPath, true, this)); if (_initialized) { _isDirty = true; } } else { bool included = true; bool ignoreDecompileErrors = false; if (projectFiles != null) { if (projectFiles.ContainsKey(fileSystemPath)) { ignoreDecompileErrors = projectFiles[fileSystemPath]; } else { included = false; } } AddFile(fileSystemPath, included, ignoreDecompileErrors); } } }
/// <summary> Draws the right column based on the currently selected type. </summary> private void DrawRightColumnItems() { // Clears out old visual elements. rightColumnItems.Clear(); if (DataTypeSelected) { #region Sets up List. selectedDataEntry = visibleEntries.ToArray()[leftList.selectedIndex]; Type stringToType = Type.GetType(selectedDataEntry.assemblyName); List <UnityEngine.Object> objectArray = FolderUtility.FindAssetsByType(stringToType); selectedDataObjects = new List <DataType>(); foreach (UnityEngine.Object obj in objectArray) { selectedDataObjects.Add((DataType)obj); } #endregion #region Sets up ListView. Label itemLabel = new Label(); itemLabel.AddToClassList("list_item"); Func <VisualElement> makeItem = () => new Label(); // Using the itemLabel cause the list to not add the first result for some reason. Action <VisualElement, int> bindItem = (e, i) => (e as Label).text = selectedDataObjects.ToArray()[i].name; const int itemHeight = 20; rightList = new ListView(selectedDataObjects, itemHeight, makeItem, bindItem); rightList.AddToClassList("list"); rightList.selectionType = SelectionType.Single; rightList.onSelectionChanged += CheckForSelectedObject; rightColumnItems.Add(rightList); #endregion } }