public void TestFieldParse()
        {
            String    smaliText = File.ReadAllText("Tests\\Files\\Utility.smali");
            SmaliFile file      = new SmaliFile(smaliText);

            Assert.AreEqual(7, file.Fields.Count);

            Assert.AreEqual("private static final String[] HOSTS_FILES;", file.Fields[0].ToString());
        }
        public void TestMethodParse()
        {
            String    smaliText = File.ReadAllText("Tests\\Files\\GifAnimationDrawable.smali");
            SmaliFile file      = new SmaliFile(smaliText);

            File.WriteAllText("Tests\\Results\\GifAnimationDrawable.java", file.ToString());

            //Assert.AreEqual(17, file.Methods.Count);
        }
        public void TestClassParse()
        {
            String    smaliText = File.ReadAllText("Tests\\Files\\Utility.smali");
            SmaliFile file      = new SmaliFile(smaliText);

            Assert.AreEqual("Utils", file.ClassName);
            Assert.AreEqual("com.perk.livetv.aphone.utils", file.Package);
            Assert.AreEqual("public", file.Modifiers);

            Assert.AreEqual("Object", file.SuperClass);
        }
Example #4
0
        /// <summary>
        /// Проверяет текущий файл на соответствие настройкам
        /// </summary>
        /// <param name="file">Файл</param>
        /// <param name="extension">Расширение файла</param>
        public static bool CheckFileWithSettings(string file, string extension)
        {
            if (extension != ".xml" && GlobalVariables.AppSettings.OnlyXml)
            {
                return(false);
            }

            if (extension == ".xml")
            {
                if (!GlobalVariables.AppSettings.EmptyXml)
                {
                    try
                    {
                        var details = XmlFile.Create(file).Details;

                        return(details != null && details.Count != 0);
                    }
                    catch (XmlParserException)
                    {
                        return(false);
                    }
                }
            }
            else if (extension == ".smali")
            {
                if (!GlobalVariables.AppSettings.EmptySmali && !SmaliFile.HasLines(file))
                {
                    return(false);
                }
            }
            else if (GlobalVariables.AppSettings.ImageExtensions.Contains(extension))
            {
                if (!GlobalVariables.AppSettings.Images)
                {
                    return(false);
                }
            }
            else if (GlobalVariables.AppSettings.OtherExtensions.Contains(extension))
            {
                if (!GlobalVariables.AppSettings.OtherFiles)
                {
                    return(false);
                }
            }

            return(true);
        }
Example #5
0
        /// <summary>
        /// Загружает файл в редактор
        /// </summary>
        /// <param name="pathToFile">Файл</param>
        public static void LoadFile(string pathToFile)
        {
            var ext = Path.GetExtension(pathToFile);

            if (!GlobalVariables.EditableFileExtenstions.Contains(ext))
            {
                Process.Start(pathToFile);
                return;
            }
            
            IEditableFile file;

            try
            {
                switch (ext)
                {
                    case ".xml":
                        file = XmlFile.Create(pathToFile);
                        break;
                    default: //".smali":
                        file = new SmaliFile(pathToFile);
                        break;
                }
            }
            catch (IOException ex)
            {
                // todo: add to string resources
                MessBox.ShowDial($"Не удалось загрузить файл из-за ошибки системы.\nСообщение: {ex.Message}", StringResources.ErrorLower);
                return;
            }

            WindowManager.ActivateWindow<EditorWindow>();

            ManualEventManager.GetEvent<AddEditableFilesEvent>()
                .Publish(new AddEditableFilesEvent(file));

            ManualEventManager.GetEvent<EditorScrollToFileAndSelectEvent>()
                .Publish(new EditorScrollToFileAndSelectEvent(f => f.FileName.Equals(file.FileName, StringComparison.Ordinal)));
        }