コード例 #1
0
        /// <summary>
        /// Copy the given resource file into a given base folder.
        /// </summary>
        private void CopyResourceToFolder(string folder, string resourceFile, ResourceType resourceType)
        {
            var outputPath   = ResourceExtensions.GetNormalizedResourcePath(folder, resourceFile, resourceType);
            var outputFolder = Path.GetDirectoryName(outputPath);

            if (!Directory.Exists(outputFolder))
            {
                Directory.CreateDirectory(outputFolder);
            }

            // Collect last modification date
            var modified = File.GetLastWriteTime(resourceFile);

            if (modified > lastModified)
            {
                lastModified = modified;
            }

            // Copy the resource file
            File.Copy(resourceFile, outputPath, true);

            // Make sure file is not readonly.
            File.SetAttributes(outputPath, FileAttributes.Normal);

            // Post process
            ProcessResource(outputPath, resourceType);
        }
コード例 #2
0
        /// <summary>
        /// Process the output of AAPT to display property errors in VisualStudio.
        /// </summary>
        private static void ProcessAaptErrors(string output, string tempFolder, List <Tuple <string, ResourceType> > resources)
        {
#if DEBUG
            //Debugger.Launch();
#endif

            const string errorPrefix = "Error: ";
            const string errorLevel  = "error";

            var lines = output.Split(new[] { '\n', '\r' });
            var paths = resources.Select(x => Tuple.Create(x.Item1, ResourceExtensions.GetNormalizedResourcePath(tempFolder, x.Item1, x.Item2))).ToList();

            foreach (var line in lines)
            {
                var parts = SplitAaptErrorLine(line.Trim(), 4).ToArray();
                int lineNr;
                if ((parts.Length < 4) || !int.TryParse(parts[1], out lineNr))
                {
                    if (line.Length > 0)
                    {
                        Console.WriteLine(line);
                    }
                    continue;
                }

                // src:line:severity:remaining
                var msg = parts[3].Trim();
                if (msg.StartsWith(errorPrefix))
                {
                    msg = msg.Substring(errorPrefix.Length);
                }
                var url   = parts[0];
                var level = parts[2].Trim();

                var pathEntry = paths.FirstOrDefault(x => x.Item2 == url);
                url = (pathEntry != null) ? pathEntry.Item1 : url;

                switch (level.ToLowerInvariant())
                {
                case errorLevel:
                    DLog.Error(DContext.ResourceCompilerAaptError, url, 0, lineNr, msg);
                    break;

                default:
                    DLog.Warning(DContext.ResourceCompilerAaptError, url, 0, lineNr, msg);
                    break;
                }

                //Console.WriteLine(line); // DEBUG PURPOSES
            }
        }
コード例 #3
0
 /// <summary>
 /// Add all items to the command line
 /// </summary>
 private static void AddResources(IEnumerable <ITaskItem> items, ResourceType type, List <ITaskItem> outputItems, string tempFolder)
 {
     if (items == null)
     {
         return;
     }
     foreach (var x in items)
     {
         var resourceFile = x.ItemSpec;
         var outputPath   = ResourceExtensions.GetNormalizedResourcePath(tempFolder, resourceFile, type);
         var outputItem   = new TaskItem(outputPath);
         x.CopyMetadataTo(outputItem);
         outputItem.SetMetadata("TargetPath", outputPath);
         outputItems.Add(outputItem);
     }
 }