Пример #1
0
        // create the resources file in the desired path
        public static void CreateXamlRes(string path, bool openInEditor)
        {
            StringsXMLEditor.CreateDocument(path);
            VsUtils.AddFileIfUnexisting(VsUtils.GetCurrentProject(), path);
            Ensurer.EnsureAppXaml();

            if (openInEditor)
            {
                VsUtils.OpenInEditor(path);
            }

            Ensurer.EnsureEverything();
        }
Пример #2
0
        // ensure the strings.xml file exists
        public static void EnsureStringResources(Project project = null)
        {
            if (project == null)
            {
                project = VsUtils.GetCurrentProject();
            }
            var resFile = Resourcer.GetResourcePath(Resourcer.GetStringsResName());

            if (!File.Exists(resFile)) // if the file doesn't exist, create it
            {
                StringsXMLEditor.CreateDocument(resFile);
            }

            VsUtils.AddFileIfUnexisting(VsUtils.GetCurrentProject(), resFile);
        }
Пример #3
0
        // ensure that the resource manager class exists, or that it's coplete
        public static void EnsureResourceManager(Project project = null)
        {
            var managerFile = Resourcer.GetResourcesManagerPath();

            if (File.Exists(managerFile)) // if the file exists, ensure it has the required methods
            {
                var source = File.ReadAllText(managerFile, Encoding.UTF8);

                var rc1 = source.Contains(resCheck1);
                var rc2 = source.Contains(resCheck2);
                var rc3 = source.Contains(resCheck3);
                if (!rc1 || !rc2 || !rc3) // seems like it doesn't have everything!
                {
                    var bracketRegex = new Regex(Settings.ResourcesManagerName + @"\s*{");
                    var match        = bracketRegex.Match(source); // the class may exist

                    var newFile = new StringBuilder();
                    if (match.Success) // there's a match, append only the missing code to the existing class
                    {
                        var bracket = match.Index + match.Length;
                        newFile.Append(source.Substring(0, bracket));

                        if (!rc1)
                        {
                            newFile.AppendLine(resPart1);
                        }
                        if (!rc2)
                        {
                            newFile.AppendLine(resPart2);
                        }
                        if (!rc3)
                        {
                            newFile.AppendLine(resPart3);
                        }

                        newFile.Append(source.Substring(bracket));
                    }
                    else // no match (no resourcemanager class), append the entire code
                    {
                        if (!source.Contains(resManagerUsing))
                        {
                            newFile.AppendLine(resManagerUsing);
                        }

                        newFile.AppendLine(source);
                        newFile.AppendLine(getResManagerSource());
                    }

                    File.WriteAllText(managerFile, newFile.ToString());
                }
            }
            else // file doesn't exist, just create it
            {
                createResourceManagerFile(managerFile);
            }

            if (project == null)
            {
                project = VsUtils.GetCurrentProject();
            }
            VsUtils.AddFileIfUnexisting(project, managerFile);
        }