Exemple #1
0
        protected override void Execute()
        {
            if (arguments.Length == 0)
            {
                Fail("No source file specified");
            }

            string sourceBasePath = Helpers.AbsolutePath(arguments[0]);
            string targetBasePath = arguments.Length > 1 ? Helpers.AbsolutePath(arguments[1]) : sourceBasePath;

            string[] files = null;
            if (Directory.Exists(sourceBasePath))
            {
                files = Directory.GetFiles(sourceBasePath, "*." + Constants.png, SearchOption.AllDirectories);
            }
            else if (File.Exists(sourceBasePath))
            {
                files          = new string[] { sourceBasePath };
                sourceBasePath = targetBasePath = "";
            }
            else
            {
                Fail("The specified source file does not exist");
            }

            for (int i = 0; i < files.Length; i++)
            {
                string sourcePath = files[i];
                string localPath  = Helpers.RelativePath(sourcePath, sourceBasePath);
                string targetPath = Path.ChangeExtension(Path.Combine(targetBasePath, localPath), Constants.ykg);

                currentFile = localPath;

                if (flags.Has('v'))
                {
                    Console.WriteLine();
                    Console.WriteLine("SourceBase: " + sourceBasePath);
                    Console.WriteLine("TargetBase: " + targetBasePath);
                    Console.WriteLine("Source:     " + sourcePath);
                    Console.WriteLine("Target:     " + targetPath);
                    Console.WriteLine("Local:      " + localPath);
                }

                Directory.CreateDirectory(Path.GetDirectoryName(targetPath));

                using (FileStream fs = new FileStream(targetPath, FileMode.Create)) {
                    YukaGraphics graphics = GraphicsFactory.Instance.FromSource(sourcePath);
                    GraphicsFactory.Instance.ToBinary(graphics, fs);
                }
            }
            currentFile = "";

            if (flags.Has('w'))
            {
                Console.ReadLine();
            }
        }
Exemple #2
0
 protected override void Execute()
 {
     if (arguments.Length == 0)
     {
         Task task = new HelpTask();
         task.arguments = new string[0];
         task.flags     = flags;
         task.Run();
     }
     else if (arguments[0].EndsWith(".patch.ykc"))
     {
         // patch mode
         Task task = null;
         for (int i = 1; i <= 5; i++)
         {
             if (Path.GetFileName(arguments[0]).Contains(".data0" + i + '.'))
             {
                 if (File.Exists(Path.Combine(Path.GetDirectoryName(arguments[0]), "data0" + i + ".ykc")))
                 {
                     flags.Set('v');
                     task = new PatchTask(new[] { arguments[0], Path.Combine(Path.GetDirectoryName(arguments[0]), "data0" + i + ".ykc") }, flags);
                 }
                 else if (File.Exists(Helpers.AbsolutePath("data0" + i + ".ykc")))
                 {
                     flags.Set('v');
                     task = new PatchTask(new[] { arguments[0], Path.Combine(Directory.GetCurrentDirectory(), "data0" + i + ".ykc") }, flags);
                 }
                 break;
             }
         }
         if (task == null)
         {
             Fail("Unable to determine patch target");
         }
         else
         {
             task.Run();
         }
         Console.ReadLine();
     }
     else if (Path.GetExtension(arguments[0]) == '.' + Constants.ykg)
     {
         string path = Path.Combine(Path.GetTempPath(), Path.ChangeExtension(Path.GetFileName(arguments[0]), Constants.png));
         using (FileStream fs = new FileStream(Helpers.AbsolutePath(arguments[0]), FileMode.Open)) {
             YukaGraphics g = GraphicsFactory.Instance.FromBinary(fs);
             g.bitmap.Save(path);
             System.Diagnostics.Process.Start(path);
         }
     }
     else if (Directory.Exists(arguments[0]))
     {
         string patchLogPath = Path.Combine(Helpers.AbsolutePath(arguments[0]), "patch.ypl");
         if (File.Exists(patchLogPath))
         {
             // TODO
         }
     }
     else if (Path.GetExtension(arguments[0]) == '.' + Constants.ypl)
     {
         flags.Set('v');
         flags.Set('w');
         new PatchTask(arguments, flags).Run();
     }
     else if (Path.GetExtension(arguments[0]) == '.' + Constants.ydr)
     {
         flags.Set('v');
         flags.Set('w');
         new DeployTask(arguments, flags).Run();
     }
     else
     {
         Fail("Unable to auto determine processing method");
     }
 }