Exemple #1
0
 public override bool CanConvert(ConvertInfo info)
 {
     return(!string.IsNullOrEmpty(monoPath) &&
            (
                info.InputType == Models.FileType.Character.Name ||
                info.InputType == Models.FileType.Image.Name ||
                info.InputType == Models.FileType.Rip.Name
            ));
 }
Exemple #2
0
 public override bool CanConvert(ConvertInfo info)
 {
     if (string.IsNullOrEmpty(ffmpegPath) || string.IsNullOrEmpty(timidityPath))
     {
         return(false);
     }
     return(info.InputType == Models.FileType.Audio.Name &&
            inputFormats.Contains(Path.GetExtension(info.FileName).ToLowerInvariant()) &&
            outputFormats.Contains(Path.GetExtension(info.OutFileName).ToLowerInvariant()));
 }
Exemple #3
0
        public override void Prepare(ConvertInfo info)
        {
            base.Prepare(info);
            var outFile  = Path.GetFileNameWithoutExtension(info.OutFileName);
            var maxWidth = info.GetProperty <int?>("max-width");

            if (maxWidth != null)
            {
                outFile += ".x" + maxWidth.Value;
            }
            info.OutFileName = outFile + Path.GetExtension(info.OutFileName);
        }
Exemple #4
0
        public override bool CanConvert(ConvertInfo info)
        {
            if (string.IsNullOrEmpty(ffmpegPath))
            {
                return(false);
            }
            var inExt  = Path.GetExtension(info.FileName).ToLowerInvariant();
            var outExt = Path.GetExtension(info.OutFileName).ToLowerInvariant();

            return(info.InputType == Models.FileType.Audio.Name &&
                   inputFormats.Contains(inExt) &&
                   outputFormats.Contains(outExt) &&
                   !string.Equals(inExt, outExt, StringComparison.OrdinalIgnoreCase));
        }
Exemple #5
0
        public override Task ConvertFile(ConvertInfo info, string inFile, string outFile)
        {
            var tcs  = new TaskCompletionSource <object>();
            var args = new StringBuilder();

            args.AppendFormat("-c '{0} \"{1}\" -Ow -o - ", timidityPath, inFile);
            args.AppendFormat("| {0} -i -", ffmpegPath);
            if (outFile.EndsWith(".ogg", StringComparison.OrdinalIgnoreCase))
            {
                args.Append(" -acodec libvorbis");
            }
            args.AppendFormat(" \"{0}\"", outFile);
            args.Append("'");
            var convertExe = "/bin/sh";

            Console.WriteLine("Executing: {0} {1}", convertExe, args);
            var process = new Process
            {
                EnableRaisingEvents = true,
                StartInfo           = new ProcessStartInfo
                {
                    FileName               = convertExe,
                    Arguments              = args.ToString(),
                    UseShellExecute        = false,
                    RedirectStandardOutput = true,                     // turn these off (with mono) to see output errors
                    RedirectStandardError  = false,
                    CreateNoWindow         = true
                }
            };

            process.Exited += (s, e) =>
            {
                if (process.ExitCode == 0)
                {
                    tcs.SetResult(true);
                }
                else
                {
                    tcs.SetException(new Exception(process.StandardOutput.ReadToEnd()));
                }
            };
            process.Start();
            return(tcs.Task);
        }
Exemple #6
0
        public override Task ConvertFile(ConvertInfo info, string inFile, string outFile)
        {
            var tcs  = new TaskCompletionSource <object>();
            var args = new StringBuilder();

            args.AppendFormat("\"{0}\" -alpha on -background none -flatten ", inFile);

            var maxWidth = info.GetProperty <int?>("max-width");

            if (maxWidth != null)
            {
                args.AppendFormat(" -resize '{0}>'", maxWidth.Value);
            }

            args.AppendFormat(" \"{0}\"", outFile);

            var process = new Process
            {
                EnableRaisingEvents = true,
                StartInfo           = new ProcessStartInfo
                {
                    FileName               = convertPath,
                    Arguments              = args.ToString(),
                    UseShellExecute        = false,
                    RedirectStandardOutput = true,                     // turn these off (with mono) to see output errors
                    RedirectStandardError  = false,
                    CreateNoWindow         = true
                }
            };

            process.Exited += (s, e) =>
            {
                if (process.ExitCode == 0)
                {
                    tcs.SetResult(true);
                }
                else
                {
                    tcs.SetException(new Exception(process.StandardOutput.ReadToEnd()));
                }
            };
            process.Start();
            return(tcs.Task);
        }
Exemple #7
0
        public override Task ConvertFile(ConvertInfo info, string inFile, string outFile)
        {
            var tcs = new TaskCompletionSource <object>();

            var options  = new List <ConversionOption>();
            var aspect   = info.GetProperty <bool?>("aspect");
            var use9x    = info.GetProperty <bool?>("use9x");
            var ice      = info.GetProperty <bool?>("ice");
            var zoom     = info.GetProperty <int?>("zoom");
            var maxWidth = info.GetProperty <int?>("max-width");

            if (aspect != null)
            {
                options.Add(new ConversionOption("text-aspect", aspect == true ? "dos" : "none"));
            }
            if (use9x != null)
            {
                options.Add(new ConversionOption("text-use9x", use9x == true ? "true" : "false"));
            }

            var parameters = new ConvertParameters
            {
                InputFileName  = inFile,
                InputFormat    = info.InputFormat,
                OutputFileName = outFile,
                MaxWidth       = maxWidth,
                Zoom           = zoom ?? 1f,
                Options        = options
            };

            try
            {
                Global.PabloEngine.Convert(parameters);
                tcs.SetResult(null);
            }
            catch (Exception ex)
            {
                tcs.SetException(ex);
            }

            return(tcs.Task);
        }
Exemple #8
0
        public override void Prepare(ConvertInfo info)
        {
            base.Prepare(info);

            var outFile = Path.GetFileNameWithoutExtension(info.OutFileName);
            var zoom    = info.GetProperty <int?>("zoom");

            if (zoom != null)
            {
                outFile += ".z" + zoom.Value;
            }
            var maxWidth = info.GetProperty <int?>("max-width");

            if (maxWidth != null)
            {
                outFile += ".x" + maxWidth.Value;
            }
            var aspect = info.GetProperty <bool?>("aspect");

            if (aspect != null)
            {
                outFile += aspect == true ? ".da" : ".na";
            }
            var use9x = info.GetProperty <bool?>("use9x");

            if (use9x != null)
            {
                outFile += use9x == true ? ".9x" : ".8x";
            }
            var ice = info.GetProperty <bool?>("ice");

            if (ice != null)
            {
                outFile += ice == true ? ".ice" : ".blink";
            }
            info.OutFileName = outFile + Path.GetExtension(info.OutFileName);
        }
Exemple #9
0
        public override async Task <Stream> Convert(ConvertInfo info)
        {
            var packDir = Path.Combine(Global.SixteenColorsCacheLocation, info.Pack.Name);

            var outFileName = Path.Combine(packDir, info.OutFileName);

            if (!File.Exists(outFileName))
            {
                // save raw input file to cache
                var inFileName = Path.Combine(packDir, info.FileName);
                Directory.CreateDirectory(Path.GetDirectoryName(inFileName));
                if (!File.Exists(inFileName))
                {
                    await info.ExtractFile(inFileName);

                                        #if DEBUG
                    if (!File.Exists(inFileName))
                    {
                        throw new FileNotFoundException("File was not extracted", inFileName);
                    }
                                        #endif
                }

                await ConvertFile(info, inFileName, outFileName);

                if (File.Exists(outFileName))
                {
                    return(File.OpenRead(outFileName));
                }
            }
            else
            {
                return(File.OpenRead(outFileName));
            }
            return(null);
        }
Exemple #10
0
 public override bool CanConvert(ConvertInfo info)
 {
     return(info.InputType == Models.FileType.Character.Name || info.InputType == Models.FileType.Image.Name || info.InputType == Models.FileType.Rip.Name);
 }
Exemple #11
0
 public virtual void Prepare(ConvertInfo info)
 {
 }
Exemple #12
0
 public abstract Task <Stream> Convert(ConvertInfo info);
Exemple #13
0
 public abstract bool CanConvert(ConvertInfo info);
Exemple #14
0
 public static Converter GetConverter(ConvertInfo info)
 {
     return(converters.FirstOrDefault(r => r.CanConvert(info)));
 }
Exemple #15
0
        public override Task ConvertFile(ConvertInfo info, string inFile, string outFile)
        {
            var tcs        = new TaskCompletionSource <object>();
            var convertExe = "PabloDraw.Console.exe";
            var appPath    = HttpContext.Current.Request.MapPath("~/Util");

            convertExe = Path.Combine(appPath, convertExe);
            var args = new StringBuilder();

            args.AppendFormat(" --convert \"{0}\" --out \"{1}\"", inFile, outFile);


            var zoom = info.GetProperty <int?>("zoom");

            if (zoom != null)
            {
                args.AppendFormat(" --zoom {0:0.00}", zoom.Value / 100f);
            }
            var maxWidth = info.GetProperty <int?>("max-width");

            if (maxWidth != null)
            {
                args.AppendFormat(" --max-width {0}", maxWidth.Value);
            }
            args.Append(" --platform win");

            if (!string.IsNullOrEmpty(monoPath))
            {
                // use mono to execute the command
                args.Insert(0, convertExe + " ");
                convertExe = monoPath;
            }
            // todo: logging
            // Console.WriteLine("Executing: {0} {1}", convertExe, args);

            var process = new Process
            {
                EnableRaisingEvents = true,
                StartInfo           = new ProcessStartInfo
                {
                    FileName               = convertExe,
                    Arguments              = args.ToString(),
                    WorkingDirectory       = appPath,
                    UseShellExecute        = false,
                    RedirectStandardOutput = true,                     // turn these off (with mono) to see output errors
                    RedirectStandardError  = true,
                    CreateNoWindow         = true
                }
            };

            process.Exited += (s, e) =>
            {
                if (process.ExitCode == 0)
                {
                    tcs.SetResult(true);
                }
                else
                {
                    tcs.SetException(new Exception(process.StandardOutput.ReadToEnd()));
                }
            };
            process.Start();
            return(tcs.Task);
        }
Exemple #16
0
 public abstract Task ConvertFile(ConvertInfo info, string inFile, string outFile);
Exemple #17
0
 public override bool CanConvert(ConvertInfo info)
 {
     return(!string.IsNullOrEmpty(convertPath) && info.InputType == Models.FileType.Image.Name);
 }