コード例 #1
0
        static void Main(string[] args)
        {
            //Dependency injection setup beigns
            // create service collection
            var serviceCollection = new ServiceCollection();

            ConfigureServices(serviceCollection);
            // create service provider
            var serviceProvider = serviceCollection.BuildServiceProvider();
            //Dependency injection setup ends

            var filename = "ColorTattooPNGFile";
            var png      = new PngFile(filename);
            var svg      = new SvgFile("S1000Z0point8NoOverlapColorTattooPNGFile");
            var tsp      = new TspFile(filename);
            var tspSol   = new TspSolFile("S1000Z0point8NoOverlapColorTattooPNGFile");

            tsp.Dimension = 1000;

            //var stipplerServices = serviceProvider.GetRequiredService<IStippler>();
            //Console.WriteLine(stipplerServices.CallStippler(png, 1000, 0.8));

            var tspServices = serviceProvider.GetRequiredService <IGcodeCreator>();

            //Console.WriteLine(tspServices.ConvertCircleSVGtoTSP(svg));

            //Console.WriteLine(tspServices.ReorderSVGAccordingtoTSPsol(svg, tspSol, tsp));

            Console.Read();
        }
コード例 #2
0
        internal static CardType DetermineCardType(string path)
        {
            if (path.IsNullOrEmpty())
            {
                return(CardType.None);
            }

            using (var fS = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                using (var bR = new BinaryReader(fS))
                {
                    try
                    {
                        PngFile.SkipPng(bR);

                        string tag = bR.ReadString();
                        tag = tag.Remove(0, tag.IndexOf("【") + 1);
                        tag = tag.Remove(tag.IndexOf("】"));

                        switch (tag)
                        {
                        case "AIS_Chara":
                            return(CardType.AIGirl);

                        case "EroMakeChara":
                            return(CardType.EmotionCreators);

                        case "HoneySelectCharaFemale":
                            return(CardType.HoneySelectFemale);

                        case "HoneySelectCharaMale":
                            return(CardType.HoneySelectMale);

                        case "KoiKatuChara":
                        case "KoiKatuCharaS":
                        case "KoiKatuCharaSP":
                            return(CardType.Koikatsu);

                        case "PlayHome_Female":
                            return(CardType.PlayHomeFemale);

                        case "PlayHome_Male":
                            return(CardType.PlayHomeMale);

                        case "PremiumResortCharaFemale":
                            return(CardType.PremiumResortFemale);

                        case "PremiumResortCharaMale":
                            return(CardType.PremiumResortMale);

                        default:
                            return(CardType.Unknown);
                        }
                    }
                    catch { }
                }

                return(CardType.None);
            }
        }
コード例 #3
0
        private static bool PauseCtrl_CheckIdentifyingCode(string _path, ref bool __result)
        {
            var extension = Path.GetExtension(_path).ToLower();

            if (extension == ".png" || extension == ".dat")
            {
                using (FileStream input = new FileStream(_path, FileMode.Open, FileAccess.Read))
                    using (BinaryReader binaryReader = new BinaryReader(input))
                    {
                        //Skip png data
                        if (extension == ".png")
                        {
                            PngFile.SkipPng(binaryReader);
                        }
                        //Verify this is a pose, but without the sex check since poses load fine regardless
                        if (string.Compare(binaryReader.ReadString(), "【pose】") != 0)
                        {
                            __result = false;
                        }
                    }
                __result = true;
                return(false);
            }
            return(true);
        }
コード例 #4
0
        private static bool IsFileValid(string path)
        {
            if (!File.Exists(path))
            {
                return(false);
            }

            try
            {
                using (var fs = File.OpenRead(path))
                {
                    PngFile.SkipPng(fs);

                    var pos = fs.Position;
                    foreach (var tokenSequence in ValidStudioTokens)
                    {
                        if (Util.FindPosition(fs, tokenSequence) > 0)
                        {
                            return(true);
                        }

                        fs.Seek(pos, SeekOrigin.Begin);
                    }
                }

                LogInvalid();
                return(false);
            }
            catch (Exception e)
            {
                // If the check crashes then don't prevent loading the scene in case it's actually good and this code is not
                Logger.LogError(e);
                return(true);
            }
        }
コード例 #5
0
 public static int GetProductNo(string path)
 {
     if (!File.Exists(path))
     {
         return(-1);
     }
     using (FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read))
     {
         using (BinaryReader br = new BinaryReader((Stream)fileStream))
         {
             try
             {
                 PngFile.SkipPng(br);
                 if (br.BaseStream.Length - br.BaseStream.Position != 0L)
                 {
                     return(br.ReadInt32());
                 }
                 OutputLog.Error("ただのPNGファイルの可能性があります。", true, "CharaLoad");
                 return(-1);
             }
             catch (EndOfStreamException ex)
             {
                 Debug.LogError((object)("データが破損している可能性があります:" + ex.GetType().Name));
                 return(-1);
             }
         }
     }
 }
コード例 #6
0
        public static bool PoseLoadPatch(OCIChar _ociChar, ref string _path, ref bool __result)
        {
            if (Path.GetExtension(_path).ToLower() == PngExt)
            {
                var fileInfo = new PauseCtrl.FileInfo(null);
                using (var fileStream = new FileStream(_path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                    using (var binaryReader = new BinaryReader(fileStream))
                    {
                        PngFile.SkipPng(binaryReader);

                        if (string.Compare(binaryReader.ReadString(), PauseCtrl.saveIdentifyingCode) != 0)
                        {
                            __result = false;
                            return(false);
                        }

                        int ver = binaryReader.ReadInt32();
                        binaryReader.ReadInt32();
                        binaryReader.ReadString();
                        fileInfo.Load(binaryReader, ver);
                    }

                fileInfo.Apply(_ociChar);
                __result = true;
                return(false);
            }

            return(true);
        }
コード例 #7
0
ファイル: PngFile.cs プロジェクト: request-time-out/A-Scripts
    public static long SkipPng(BinaryReader br)
    {
        long pngSize = PngFile.GetPngSize(br);

        br.BaseStream.Seek(pngSize, SeekOrigin.Current);
        return(pngSize);
    }
コード例 #8
0
        private static bool IsFileValid(string path)
        {
            if (!File.Exists(path))
            {
                return(false);
            }

            using (var f = File.OpenRead(path))
            {
                PngFile.SkipPng(f);

                var pos = f.Position;
                foreach (var tokenSequence in ValidStudioTokens)
                {
                    if (Util.TryReadUntilSequence(f, tokenSequence))
                    {
                        return(true);
                    }

                    f.Seek(pos, SeekOrigin.Begin);
                }
            }

            LogInvalid();
            return(false);
        }
コード例 #9
0
ファイル: PngFile.cs プロジェクト: request-time-out/A-Scripts
    public static long SkipPng(Stream st)
    {
        long pngSize = PngFile.GetPngSize(st);

        st.Seek(pngSize, SeekOrigin.Current);
        return(pngSize);
    }
コード例 #10
0
 public bool LoadFile(Stream st, int lang)
 {
     using (BinaryReader br = new BinaryReader(st))
     {
         try
         {
             PngFile.SkipPng(br);
             if (br.BaseStream.Length - br.BaseStream.Position == 0L)
             {
                 OutputLog.Error("ただのPNGファイルの可能性があります。", true, "CharaLoad");
                 this.lastLoadErrorCode = -5;
                 return(false);
             }
             this.loadProductNo = br.ReadInt32();
             if (this.loadProductNo > 100)
             {
                 OutputLog.Error("実行ファイルよりも新しい製品番号です。", true, "CharaLoad");
                 this.lastLoadErrorCode = -3;
                 return(false);
             }
             if (br.ReadString() != "【AIS_Clothes】")
             {
                 OutputLog.Error("ファイルの種類が違います", true, "CharaLoad");
                 this.lastLoadErrorCode = -1;
                 return(false);
             }
             this.loadVersion = new Version(br.ReadString());
             if (this.loadVersion > ChaFileDefine.ChaFileClothesVersion)
             {
                 OutputLog.Error("実行ファイルよりも新しいコーディネートファイルです。", true, "CharaLoad");
                 this.lastLoadErrorCode = -2;
                 return(false);
             }
             this.language       = br.ReadInt32();
             this.coordinateName = br.ReadString();
             int count = br.ReadInt32();
             if (this.LoadBytes(br.ReadBytes(count), this.loadVersion))
             {
                 if (lang != this.language)
                 {
                     this.coordinateName = string.Empty;
                 }
                 this.lastLoadErrorCode = 0;
                 return(true);
             }
             this.lastLoadErrorCode = -999;
             return(false);
         }
         catch (EndOfStreamException ex)
         {
             Debug.LogError((object)("データが破損している可能性があります:" + ex.GetType().Name));
             this.lastLoadErrorCode = -999;
             return(false);
         }
     }
 }
コード例 #11
0
        private static void RotateOrientation(string original_path, RotateDirection direction)
        {
            using (FSpot.ImageFile img = FSpot.ImageFile.Create(original_path)) {
                if (img is JpegFile)
                {
                    FSpot.JpegFile    jimg        = img as FSpot.JpegFile;
                    PixbufOrientation orientation = direction == RotateDirection.Clockwise
                                                ? PixbufUtils.Rotate90(img.Orientation)
                                                : PixbufUtils.Rotate270(img.Orientation);

                    jimg.SetOrientation(orientation);
                    jimg.SaveMetaData(original_path);
                }
                else if (img is PngFile)
                {
                    PngFile png       = img as PngFile;
                    bool    supported = false;

                    //FIXME there isn't much png specific here except the check
                    //the pixbuf is an accurate representation of the real file
                    //by checking the depth.  The check should be abstracted and
                    //this code made generic.
                    foreach (PngFile.Chunk c in png.Chunks)
                    {
                        PngFile.IhdrChunk ihdr = c as PngFile.IhdrChunk;

                        if (ihdr != null && ihdr.Depth == 8)
                        {
                            supported = true;
                        }
                    }

                    if (!supported)
                    {
                        throw new RotateException("Unable to rotate photo type", original_path);
                    }

                    string backup = ImageFile.TempPath(original_path);
                    using (Stream stream = File.Open(backup, FileMode.Truncate, FileAccess.Write)) {
                        using (Pixbuf pixbuf = img.Load()) {
                            PixbufOrientation fake = (direction == RotateDirection.Clockwise) ? PixbufOrientation.RightTop : PixbufOrientation.LeftBottom;
                            using (Pixbuf rotated = PixbufUtils.TransformOrientation(pixbuf, fake)) {
                                img.Save(rotated, stream);
                            }
                        }
                    }
                    File.Copy(backup, original_path, true);
                    File.Delete(backup);
                }
                else
                {
                    throw new RotateException("Unable to rotate photo type", original_path);
                }
            }
        }
コード例 #12
0
 public static CraftInfo.AboutInfo LoadAbout(string _path)
 {
     using (FileStream fileStream = new FileStream(_path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
     {
         using (BinaryReader binaryReader = new BinaryReader((Stream)fileStream))
         {
             PngFile.SkipPng(binaryReader);
             return(new CraftInfo.AboutInfo(binaryReader));
         }
     }
 }
コード例 #13
0
        public void Init()
        {
            using (var testDirectory = new TestDirectory())
            {
                var pngFile = new PngFile(testDirectory.DirectoryPath, new byte[] { 1, 2, 3 });

                Assert.IsFalse(string.IsNullOrEmpty(pngFile.Id));
                Assert.AreEqual(0, pngFile.Progress);
                Assert.IsTrue(File.Exists(Path.Combine(testDirectory.DirectoryPath, pngFile.Id)));
            }
        }
コード例 #14
0
 public bool Import(string _path)
 {
     using (FileStream fileStream = new FileStream(_path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
     {
         using (BinaryReader binaryReader = new BinaryReader((Stream)fileStream))
         {
             PngFile.SkipPng(binaryReader);
             Version _version = new Version(binaryReader.ReadString());
             this.Import(binaryReader, _version);
         }
     }
     return(true);
 }
コード例 #15
0
        public static void CompressPngToTexture2DContent(
            ParsedPath pngFileName,
            string compressionType,
            out Texture2DContent textureContent)
        {
            PngFile pngFile = PngFileReader.ReadFile(pngFileName);

            SquishMethod? squishMethod  = null;
            SurfaceFormat surfaceFormat = SurfaceFormat.Color;

            switch (compressionType.ToLower())
            {
            case "dxt1":
                squishMethod  = SquishMethod.Dxt1;
                surfaceFormat = SurfaceFormat.Dxt1;
                break;

            case "dxt3":
                squishMethod  = SquishMethod.Dxt3;
                surfaceFormat = SurfaceFormat.Dxt3;
                break;

            case "dxt5":
                squishMethod  = SquishMethod.Dxt5;
                surfaceFormat = SurfaceFormat.Dxt5;
                break;

            default:
            case "none":
                surfaceFormat = SurfaceFormat.Color;
                break;
            }

            BitmapContent bitmapContent;

            if (surfaceFormat != SurfaceFormat.Color)
            {
                byte[] rgbaData = Squish.CompressImage(
                    pngFile.RgbaData, pngFile.Width, pngFile.Height,
                    squishMethod.Value, SquishFit.IterativeCluster, SquishMetric.Default, SquishExtra.None);

                bitmapContent = new BitmapContent(surfaceFormat, pngFile.Width, pngFile.Height, rgbaData);
            }
            else
            {
                bitmapContent = new BitmapContent(SurfaceFormat.Color, pngFile.Width, pngFile.Height, pngFile.RgbaData);
            }

            textureContent = new Texture2DContent(bitmapContent);
        }
コード例 #16
0
 public static bool GetProductInfo(string path, out ChaFile.ProductInfo info)
 {
     info = new ChaFile.ProductInfo();
     if (!File.Exists(path))
     {
         return(false);
     }
     using (FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read))
     {
         using (BinaryReader br = new BinaryReader((Stream)fileStream))
         {
             long pngSize = PngFile.GetPngSize(br);
             if (pngSize != 0L)
             {
                 br.BaseStream.Seek(pngSize, SeekOrigin.Current);
                 if (br.BaseStream.Length - br.BaseStream.Position == 0L)
                 {
                     OutputLog.Warning("ただのPNGファイルの可能性があります。", true, "CharaLoad");
                     return(false);
                 }
             }
             try
             {
                 info.productNo = br.ReadInt32();
                 info.tag       = br.ReadString();
                 if (info.tag != "【AIS_Chara】")
                 {
                     OutputLog.Error("ファイルの種類が違います", true, "CharaLoad");
                     return(false);
                 }
                 info.version = new Version(br.ReadString());
                 if (info.version > ChaFileDefine.ChaFileVersion)
                 {
                     OutputLog.Error("実行ファイルよりも新しいファイルです。", true, "CharaLoad");
                     return(false);
                 }
                 info.language = br.ReadInt32();
                 info.userID   = br.ReadString();
                 info.dataID   = br.ReadString();
                 return(true);
             }
             catch (EndOfStreamException ex)
             {
                 Debug.LogError((object)("データが破損している可能性があります:" + ex.GetType().Name));
                 return(false);
             }
         }
     }
 }
コード例 #17
0
        private void SetPlayerParameter(GameCharaFileInfo _data)
        {
            this.objPlayerParameterWindow.SetActiveIfDifferent(true);
            this.txtPlayerCharaName.set_text(_data.name);
            this.riPlayerCard.set_texture((Texture)PngAssist.ChangeTextureFromByte(PngFile.LoadPngBytes(_data.FullPath), 0, 0, (TextureFormat)5, false));
            int           languageInt   = Singleton <GameSystem> .Instance.languageInt;
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.Append(_data.sex != 0 ? this.localizeFemale[languageInt] : this.localizeMale[languageInt]);
            if (_data.sex == 1 && _data.futanari)
            {
                stringBuilder.Append(this.localizeFutanari[languageInt]);
            }
            this.txtPlayerSex.set_text(stringBuilder.ToString());
        }
コード例 #18
0
        public async Task CreatePngFile()
        {
            var header = new IhdrChunk(752, 1334, 8, ColorType.TruecolorAlpha);
            var idat   = new IdatChunk(header, rawRgbaData, FilterType);
            var end    = new IendChunk();

            var pngFile = new PngFile()
            {
                header,
                idat,
                end
            };

            using (var ms = new MemoryStream())
                await pngFile.WriteFileAsync(ms);
        }
コード例 #19
0
 public void ProcessIsNotRunningException()
 {
     using (var testDirectory = new TestDirectory())
     {
         var pngFile = new PngFile(testDirectory.DirectoryPath, new byte[] { 1, 2, 3 });
         try
         {
             pngFile.CancelProcess();
             Assert.Fail($"Должно было возникнуть исключение ProcessIsNotRunningException.");
         }
         catch (ProcessIsNotRunningException) { }
         catch (Exception exc)
         {
             Assert.Fail($"Должно было возникнуть исключение ProcessIsNotRunningException, а не {exc.Message}.");
         }
     }
 }
コード例 #20
0
 public static Texture2D LoadTexture(string _path)
 {
     using (FileStream fileStream = new FileStream(_path, FileMode.Open, FileAccess.Read))
     {
         long pngSize = PngFile.GetPngSize((Stream)fileStream);
         if (pngSize == 0L)
         {
             return((Texture2D)null);
         }
         using (BinaryReader binaryReader = new BinaryReader((Stream)fileStream))
         {
             byte[] data   = binaryReader.ReadBytes((int)pngSize);
             int    width  = 0;
             int    height = 0;
             return(PngAssist.ChangeTextureFromPngByte(data, ref width, ref height, (TextureFormat)5, false));
         }
     }
 }
コード例 #21
0
        public string CallStippler(string pngFileName, int stipples, double sizingFactor)
        {
            pngFileName = FileNameParser.RemoveDotFileExtensionInFileName(pngFileName);
            var pngFile = new PngFile(pngFileName);
            var svgFile = new SvgFile(pngFile.FileName);

            try
            {
                var command   = GetConsoleCommand(pngFile.FullFileName, svgFile.FullFileName, stipples, sizingFactor);
                var startInfo = new ProcessStartInfo(Constants.VORONOI_RELATIVE_PATH, command);
                var p         = Process.Start(startInfo);
                p.WaitForExit();
                return($"The file {pngFile.FullFileName} has been successfully created!");
            }
            catch (Exception e)
            {
                return(e.Message);
            }
        }
コード例 #22
0
 public static Sprite LoadSpriteFromFile(string path)
 {
     using (FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read))
     {
         long pngSize = PngFile.GetPngSize((Stream)fileStream);
         if (pngSize == 0L)
         {
             return((Sprite)null);
         }
         using (BinaryReader binaryReader = new BinaryReader((Stream)fileStream))
         {
             byte[]    data      = binaryReader.ReadBytes((int)pngSize);
             int       width     = 0;
             int       height    = 0;
             Texture2D texture2D = PngAssist.ChangeTextureFromPngByte(data, ref width, ref height, (TextureFormat)5, false);
             return(Object.op_Equality((Object)null, (Object)texture2D) ? (Sprite)null : Sprite.Create(texture2D, new Rect(0.0f, 0.0f, (float)width, (float)height), new Vector2(0.5f, 0.5f)));
         }
     }
 }
コード例 #23
0
ファイル: Utils.cs プロジェクト: mushroom999/KoikatuPlugins
        public static Texture2D LoadTexture(byte[] bytes)
        {
            Texture2D result = null;

            using (MemoryStream memStream = new MemoryStream(bytes))
            {
                long pngSize = PngFile.GetPngSize(memStream);
                if (pngSize != 0L)
                {
                    using (BinaryReader binaryReader = new BinaryReader(memStream))
                    {
                        byte[] data = binaryReader.ReadBytes((int)pngSize);
                        int    width = 0, height = 0;
                        result = PngAssist.ChangeTextureFromPngByte(data, ref width, ref height);
                    }
                }
            }

            return(result);
        }
コード例 #24
0
 private static bool PauseCtrl_LoadName(string _path, ref string __result)
 {
     if (Path.GetExtension(_path).ToLower() == ".png")
     {
         using (FileStream input = new FileStream(_path, FileMode.Open, FileAccess.Read))
             using (BinaryReader binaryReader = new BinaryReader(input))
             {
                 PngFile.SkipPng(binaryReader);
                 if (string.Compare(binaryReader.ReadString(), "【pose】") != 0)
                 {
                     __result = string.Empty;
                 }
                 binaryReader.ReadInt32();
                 binaryReader.ReadInt32();
                 __result = binaryReader.ReadString();
             }
         return(false);
     }
     return(true);
 }
コード例 #25
0
ファイル: Util.cs プロジェクト: FairBear/KK_Wardrobe
        public static CardType LoadFile(string path, out byte[] saveData, out ChaFileControl result, out byte[] pngData)
        {
            if (Path.GetExtension(path) != Strings.CARD_EXTENSION)
            {
                goto UNKNOWN;
            }

            saveData = File.ReadAllBytes(path);

            ChaFileControl chara = new ChaFileControl();

            if (chara.LoadCharaFile(path))
            {
                result  = chara;
                pngData = chara.pngData;
                return(CardType.Character);
            }

            ChaFileCoordinate coord = new ChaFileCoordinate();

            if (coord.LoadFile(path))
            {
                KKABMXCoordToChara(coord, chara);
                KCOXCoordToChara(coord, chara);

                for (int i = 0; i < chara.coordinate.Length; i++)
                {
                    chara.coordinate[i] = coord;
                }

                result  = chara;
                pngData = PngFile.LoadPngBytes(path);
                return(CardType.Coordinate);
            }

UNKNOWN:
            saveData = null;
            result   = null;
            pngData  = null;
            return(CardType.Unknown);
        }
コード例 #26
0
        private static PngType GetPngType(string path)
        {
            using (var fileStream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
                using (var binaryReader = new BinaryReader(fileStream))
                {
                    string str;
                    try
                    {
                        PngFile.SkipPng(binaryReader);
                        binaryReader.ReadInt32();
                        str = binaryReader.ReadString();
                    }
                    catch (EndOfStreamException)
                    {
                        return(PngType.Unknown);
                    }

                    if (str.StartsWith(CharaToken, StringComparison.OrdinalIgnoreCase))
                    {
                        return(PngType.AIS_Chara);
                    }

                    if (str.StartsWith(HouseToken, StringComparison.OrdinalIgnoreCase))
                    {
                        return(PngType.AIS_Housing);
                    }

                    try
                    {
                        if (fileStream.TryReadUntilSequence(StudioTokenBytes))
                        {
                            return(PngType.KStudio);
                        }
                    }
                    catch (EndOfStreamException)
                    {
                    }
                }

            return(PngType.Unknown);
        }
コード例 #27
0
 public static CraftInfo LoadStatic(string _path)
 {
     using (FileStream fileStream = new FileStream(_path, FileMode.Open, FileAccess.Read, FileShare.Read))
     {
         if (fileStream.Length == 0L)
         {
             Debug.LogError((object)"空データ");
             return((CraftInfo)null);
         }
         using (BinaryReader br = new BinaryReader((Stream)fileStream))
         {
             PngFile.SkipPng(br);
             try
             {
                 br.ReadInt32();
                 br.ReadString();
                 Version version = new Version(br.ReadString());
                 br.ReadString();
                 br.ReadString();
                 br.ReadInt32();
                 if (version.CompareTo(new Version("0.0.2")) >= 0)
                 {
                     br.ReadInt32();
                 }
                 byte[] numArray = br.ReadBytes((int)(br.BaseStream.Length - br.BaseStream.Position));
                 if (!((IList <byte>)numArray).IsNullOrEmpty <byte>())
                 {
                     return((CraftInfo)MessagePackSerializer.Deserialize <CraftInfo>(numArray));
                 }
                 Debug.LogError((object)"画像データ");
                 return((CraftInfo)null);
             }
             catch (Exception ex)
             {
                 Debug.LogWarning((object)"画像データ");
                 return((CraftInfo)null);
             }
         }
     }
 }
コード例 #28
0
        private static PngType GetPngType(string path)
        {
            using (var fileStream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
                using (var binaryReader = new BinaryReader(fileStream))
                {
                    try
                    {
                        PngFile.SkipPng(binaryReader);
                        binaryReader.ReadInt32();
                    }
                    catch (EndOfStreamException)
                    {
                        return(PngType.Unknown);
                    }
                    try
                    {
                        if (binaryReader.ReadString() == CharaToken)
                        {
                            return(PngType.KoikatuChara);
                        }
                    }
                    catch (EndOfStreamException)
                    {
                    }

                    try
                    {
                        if (fileStream.TryReadUntilSequence(StudioTokenBytes))
                        {
                            return(PngType.KStudio);
                        }
                    }
                    catch (EndOfStreamException)
                    {
                    }
                }

            return(PngType.Unknown);
        }
コード例 #29
0
 public bool Load(string _path)
 {
     try
     {
         using (FileStream fileStream = new FileStream(_path, FileMode.Open, FileAccess.Read, FileShare.Read))
         {
             if (fileStream.Length == 0L)
             {
                 Debug.LogError((object)"空データ");
                 return(false);
             }
             using (BinaryReader br = new BinaryReader((Stream)fileStream))
             {
                 PngFile.SkipPng(br);
                 br.ReadInt32();
                 br.ReadString();
                 Version version = new Version(br.ReadString());
                 br.ReadString();
                 br.ReadString();
                 br.ReadInt32();
                 if (version.CompareTo(new Version("0.0.2")) >= 0)
                 {
                     br.ReadInt32();
                 }
                 return(this.Load(br.ReadBytes((int)(br.BaseStream.Length - br.BaseStream.Position))));
             }
         }
     }
     catch (Exception ex)
     {
         if (ex is FileNotFoundException)
         {
             Debug.Log((object)("指定されたデータは存在しません: " + _path));
             return(false);
         }
         Debug.LogException(ex);
         return(false);
     }
 }
コード例 #30
0
        public async Task Can_write_PNG_file(string imageName, FilterType type, int bitDepth)
        {
            var asm      = typeof(PngFileTests).GetTypeInfo().Assembly;
            var resource = asm.GetManifestResourceStream(imageName);

            byte[] rawRgbaData;

            using (var ms = new MemoryStream()) {
                await resource.CopyToAsync(ms);

                rawRgbaData = ms.ToArray();
            }

            var header = new IhdrChunk(752, 1334, bitDepth, ColorType.TruecolorAlpha);
            var idat   = new IdatChunk(header, rawRgbaData, type);
            var end    = new IendChunk();

            var pngFile = new PngFile()
            {
                header,
                idat,
                end
            };

            var path = Path.Combine(Path.GetDirectoryName(asm.Location), $"Zooey-{bitDepth}-{type}.png");

            using (var fs = new FileStream(path, FileMode.Create))
                await pngFile.WriteFileAsync(fs);

            Assert.True(File.Exists(path));
            Assert.Equal(3, pngFile.ChunkCount);

            var result = ToolHelper.RunPngCheck(path);

            Assert.Equal(0, result.ExitCode);
            System.Console.Write(result.StandardOutput);
        }