Example #1
0
        void AddIcons(Project buildProject, AbsoluteDirectoryPath preambleDir, AbsoluteDirectoryPath projectDir)
        {
            var iconsAsm = typeof(SimulatorBuilder).Assembly;

            var icons = new[]
            {
                "Android_HDPI.png",
                "Android_LDPI.png",
                "Android_MDPI.png",
                "Android_XHDPI.png",
                "Android_XXHDPI.png",
                "Android_XXXHDPI.png",
                "iOS_iPad_29_1x.png",
                "iOS_iPad_29_2x.png",
                "iOS_iPad_40_2x.png",
                "iOS_iPad_76_1x.png",
                "iOS_iPad_76_2x.png",
                "iOS_iPhone_29_2x.png",
                "iOS_iPhone_29_3x.png",
                "iOS_iPhone_40_2x.png",
                "iOS_iPhone_40_3x.png",
                "iOS_iPhone_60_2x.png",
                "iOS_iPhone_60_3x.png",
            };

            foreach (var icon in icons)
            {
                try
                {
                    var fileName        = new FileName(icon);
                    var dstPath         = preambleDir / fileName;
                    var srcResourceName = "Fuse.Preview.Icons." + icon;

                    using (_fileSystem.BackupAndDeleteFile(dstPath))
                    {
                        using (var dst = _fileSystem.CreateNew(dstPath))
                            using (var src = iconsAsm.GetManifestResourceStream(srcResourceName))
                            {
                                if (src == null)
                                {
                                    throw new Exception("Embedded resource not found: " + srcResourceName);
                                }
                                src.CopyTo(dst);
                            }
                    }

                    var relativeIconPath = dstPath.RelativeTo(projectDir).NativeRelativePath.ToUnixPath();

                    var platform = StringSplitting.BeforeFirst(icon, "_");
                    var name     = StringSplitting.BeforeLast(StringSplitting.AfterFirst(icon, "_"), ".");

                    buildProject.MutableProperties[platform + ".Icons." + name] = new SourceValue(buildProject.Source, relativeIconPath);
                }
                catch (Exception)
                {
                    // TODO: probably report something?
                }
            }
        }
Example #2
0
 public static void ForceWriteText(this IFileSystem fileSystem, AbsoluteFilePath dst, string contents)
 {
     // TODO: What does this do, or why?
     using (var backup = fileSystem.BackupAndDeleteFile(dst))
     {
         try
         {
             fileSystem.Create(dst.ContainingDirectory);
             fileSystem.WriteNewText(dst, contents);
         }
         catch (Exception)
         {
             backup.Restore();
             throw;
         }
     }
 }
Example #3
0
 void CopyAndReplaceVariables(AbsoluteFilePath src, AbsoluteFilePath dst)
 {
     using (var backup = _fileSystem.BackupAndDeleteFile(dst))
     {
         try
         {
             var templateDocument = _fileSystem.ReadAllText(src, 5);
             var newDocument      = _templateParser.PreprocessIncludeRegions(templateDocument);
             newDocument = _templateParser.ReplaceVariables(newDocument);
             _fileSystem.WriteNewText(dst, newDocument);
         }
         catch (Exception)
         {
             backup.Restore();
             throw;
         }
     }
 }