Exemplo n.º 1
0
        /// <summary>
        /// Gets a FilterData set to the default values.
        /// </summary>
        /// <returns></returns>The FilterData set to the default values.</param>
        public static FilterData DefaultFilter()
        {
            FilterData data = new FilterData();

            data.Category  = "Untitled";
            data.Title     = "Untitled";
            data.Author    = Environment.UserName;
            data.Copyright = string.Format(CultureInfo.InvariantCulture, "Copyright © {0} {1}", DateTime.Now.Year.ToString(CultureInfo.CurrentCulture), Environment.UserName);

            data.PopDialog = true;
            for (int i = 0; i < 4; i++)
            {
                data.MapLabel[i]  = string.Format(CultureInfo.InvariantCulture, "Map {0}:", i.ToString(CultureInfo.InvariantCulture));
                data.MapEnable[i] = false;
            }
            for (int i = 0; i < 8; i++)
            {
                data.ControlLabel[i]  = string.Format(CultureInfo.InvariantCulture, "ctl {0}", i.ToString(CultureInfo.InvariantCulture));
                data.ControlValue[i]  = 0;
                data.ControlEnable[i] = true;
            }

            for (int i = 0; i < 4; i++)
            {
                data.Source[i] = DefaultSourceCode[i];
            }

            return(data);
        }
Exemplo n.º 2
0
 public FilterBuilder(FilterData data, Version pdnVersion)
 {
     this.data          = data;
     this.pdnVersion    = pdnVersion;
     compilerParameters = new CompilerParameters();
     tempFolder         = new DirectoryInfo(Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()));
     disposed           = false;
     tempFolder.Create();
 }
Exemplo n.º 3
0
        /// <summary>
        /// Load the Filter Factory data from the specified 8bf file.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <param name="data">The data.</param>
        /// <returns>
        /// <c>true</c> if the 8bf file is a Filter Factory filter and the data was loaded successfully; otherwise, <c>false</c>
        /// </returns>
        /// <exception cref="ArgumentNullException"><paramref name="path"/> is null.</exception>
        public static bool LoadFrom8bf(string path, out FilterData data)
        {
            if (path == null)
            {
                throw new ArgumentNullException(nameof(path));
            }

            return(LoadBinFile(path, out data));
        }
Exemplo n.º 4
0
        private static void SaveAfs(Stream output, FilterData data)
        {
            if (output == null)
            {
                throw new ArgumentNullException(nameof(output));
            }

            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }

            using (StreamWriter sw = new StreamWriter(output, Windows1252))
            {
                sw.NewLine = "\r"; // Filter factory uses the Mac end of line format
                sw.WriteLine("%RGB-1.0");
                for (int i = 0; i < 8; i++)
                {
                    sw.WriteLine(data.ControlValue[i]);
                }

                for (int i = 0; i < 4; i++)
                {
                    if (data.Source[i].Length > 63) // split the items into lines 63 chars long
                    {
                        string        temp     = data.Source[i];
                        int           pos      = 0;
                        List <string> srcarray = new List <string>();
                        while ((temp.Length - pos) > 63)
                        {
                            string sub = temp.Substring(pos, 63);
                            pos += 63;

                            srcarray.Add(sub);

                            if ((temp.Length - pos) < 63)
                            {
                                string remain = temp.Substring(pos);
                                remain += "\r"; // add an extra return to write an extra line
                                srcarray.Add(remain);
                            }
                        }

                        foreach (var item in srcarray)
                        {
                            sw.WriteLine(item);
                        }
                    }
                    else
                    {
                        sw.WriteLine(data.Source[i] + "\r"); // add an extra return to write an extra line
                    }
                }
            }
        }
Exemplo n.º 5
0
 private FilterData(FilterData cloneMe)
 {
     title         = cloneMe.title;
     category      = cloneMe.category;
     copyright     = cloneMe.copyright;
     author        = cloneMe.author;
     mapEnable     = cloneMe.mapEnable.CloneT();
     mapLabel      = cloneMe.mapLabel.CloneT();
     controlEnable = cloneMe.controlEnable.CloneT();
     controlLabel  = cloneMe.controlLabel.CloneT();
     controlValue  = cloneMe.controlValue.CloneT();
     source        = cloneMe.source.CloneT();
     popDialog     = cloneMe.popDialog;
     fileName      = cloneMe.fileName;
 }
Exemplo n.º 6
0
        private static void SaveTxt(Stream output, FilterData data)
        {
            if (output == null)
            {
                throw new ArgumentNullException(nameof(output));
            }

            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }

            using (StreamWriter sw = new StreamWriter(output, Windows1252))
            {
                sw.WriteLine("{0}: {1}", "Category", data.Category);
                sw.WriteLine("{0}: {1}", "Title", data.Title);
                sw.WriteLine("{0}: {1}", "Copyright", data.Copyright);
                sw.WriteLine("{0}: {1}", "Author", data.Author);

                sw.WriteLine(Environment.NewLine);

                sw.WriteLine("R: {0}", data.Source[0] + Environment.NewLine);
                sw.WriteLine("G: {0}", data.Source[1] + Environment.NewLine);
                sw.WriteLine("B: {0}", data.Source[2] + Environment.NewLine);
                sw.WriteLine("A: {0}", data.Source[3] + Environment.NewLine);

                sw.WriteLine(Environment.NewLine);
                for (int i = 0; i < 8; i++)
                {
                    if (data.ControlEnable[i])
                    {
                        sw.WriteLine(string.Format(CultureInfo.InvariantCulture, "ctl[{0}]: {1}", i.ToString(CultureInfo.InvariantCulture), data.ControlLabel[i]));
                    }
                }

                sw.WriteLine(Environment.NewLine);

                for (int i = 0; i < 8; i++)
                {
                    if (data.ControlEnable[i])
                    {
                        sw.WriteLine(string.Format(CultureInfo.InvariantCulture, "val[{0}]: {1}", i.ToString(CultureInfo.InvariantCulture), data.ControlValue[i]));
                    }
                }
            }
        }
Exemplo n.º 7
0
        private static bool HasControls(FilterData data)
        {
            bool ctlused = false;
            bool mapused = false;

            for (int i = 0; i < 4; i++)
            {
                mapused |= data.MapEnable[i];
            }

            for (int i = 0; i < 8; i++)
            {
                ctlused |= data.ControlEnable[i];
            }

            return(mapused | ctlused);
        }
Exemplo n.º 8
0
        private static bool LoadBinFile(String fileName, out FilterData data)
        {
            if (String.IsNullOrEmpty(fileName))
            {
                throw new ArgumentException("fileName is null or empty.", nameof(fileName));
            }

            data = null;
            bool result = false;

            using (SafeLibraryHandle hm = UnsafeNativeMethods.LoadLibraryEx(fileName, IntPtr.Zero, LOAD_LIBRARY_AS_DATAFILE))
            {
                if (!hm.IsInvalid)
                {
                    byte[] ffdata = null;

                    GCHandle gch          = GCHandle.Alloc(ffdata);
                    bool     needsRelease = false;
                    try
                    {
                        hm.DangerousAddRef(ref needsRelease);
                        IntPtr hMod = hm.DangerousGetHandle();
                        if (!UnsafeNativeMethods.EnumResourceNames(hMod, "PARM", new EnumResNameDelegate(EnumRes), GCHandle.ToIntPtr(gch)))
                        {
                            ffdata = (byte[])gch.Target;
                            if (ffdata != null)
                            {
                                data   = GetFilterDataFromParmBytes(ffdata);
                                result = true;
                            }
                        }
                    }
                    finally
                    {
                        gch.Free();
                        if (needsRelease)
                        {
                            hm.DangerousRelease();
                        }
                    }
                }
            }

            return(result);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Loads a Filter Factory file, automatically determining the type.
        /// </summary>
        /// <param name="fileName">The FileName to load.</param>
        /// <param name="data">The output filter_data</param>
        /// <returns>True if successful otherwise false.</returns>
        /// <exception cref="System.ArgumentNullException">The FileName is null.</exception>
        /// <exception cref="System.ArgumentException">The FileName is Empty.</exception>
        public static bool LoadFile(string fileName, out FilterData data)
        {
            bool loaded = false;

            if (fileName == null)
            {
                throw new ArgumentNullException(nameof(fileName));
            }

            if (string.IsNullOrEmpty(fileName))
            {
                throw new ArgumentException("fileName must not be empty", nameof(fileName));
            }

            data = null;

            if (Path.GetExtension(fileName).Equals(".8BF", StringComparison.OrdinalIgnoreCase))
            {
                loaded = LoadBinFile(fileName, out data);
            }
            else
            {
                using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read))
                {
                    byte[] buf = new byte[8];

                    fs.ProperRead(buf, 0, 8);
                    if (Encoding.ASCII.GetString(buf, 0, 4).Equals("%RGB"))
                    {
                        data   = LoadAfs(fs);
                        loaded = true;
                    }
                    else if (Encoding.ASCII.GetString(buf, 0, 8).Equals("Category"))
                    {
                        data   = LoadTxt(fs);
                        loaded = true;
                    }
                }
            }

            return(loaded);
        }
Exemplo n.º 10
0
        private static string GetSubmenuCategory(FilterData data)
        {
            string cat = string.Empty;

            switch (data.Category.ToUpperInvariant())
            {
            case "ARTISTIC":
                cat = "SubmenuNames.Artistic";
                break;

            case "BLURS":
                cat = "SubmenuNames.Blurs";
                break;

            case "DISTORT":
                cat = "SubmenuNames.Distort";
                break;

            case "NOISE":
                cat = "SubmenuNames.Noise";
                break;

            case "PHOTO":
                cat = "SubmenuNames.Photo";
                break;

            case "RENDER":
                cat = "SubmenuNames.Render";
                break;

            case "STYLIZE":
                cat = "SubmenuNames.Stylize";
                break;

            default:
                cat = "\"" + data.Category + "\"";
                break;
            }

            return(cat);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Saves a filter_data Source as either an .afs or .txt Source code
        /// </summary>
        /// <param name="FileName">The output FileName to save as</param>
        /// <param name="data">The filter_data to save</param>
        public static void SaveFile(string FileName, FilterData data)
        {
            if (String.IsNullOrEmpty(FileName))
            {
                throw new ArgumentException("FileName is null or empty.", nameof(FileName));
            }

            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }

            using (FileStream fs = new FileStream(FileName, FileMode.OpenOrCreate, FileAccess.Write))
            {
                if (Path.GetExtension(FileName).Equals(".afs", StringComparison.OrdinalIgnoreCase))
                {
                    SaveAfs(fs, data);
                }
                else
                {
                    SaveTxt(fs, data);
                }
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// Creates the filter environment data
        /// </summary>
        /// <param name="srcSurface">The source surface</param>
        /// <param name="data">The filter data.</param>
        /// <returns>A handle to the created filter environment.</returns>
        public static SafeEnvironmentDataHandle CreateEnvironmentData(Surface srcSurface, FilterData data)
        {
            BitmapData sourceBitmapData = new BitmapData
            {
                width     = srcSurface.Width,
                height    = srcSurface.Height,
                stride    = srcSurface.Stride,
                pixelSize = ColorBgra.SizeOf,
                scan0     = srcSurface.Scan0.Pointer
            };

            if (IntPtr.Size == 8)
            {
                return(ffeval64.CreateEnvironmentData(ref sourceBitmapData, data.Source, data.ControlValue));
            }
            else
            {
                return(ffeval86.CreateEnvironmentData(ref sourceBitmapData, data.Source, data.ControlValue));
            }
        }
Exemplo n.º 13
0
        private static string BuildFilterData(FilterData data)
        {
            string ret = string.Empty;

            using (StringWriter sw = new StringWriter(CultureInfo.InvariantCulture))
            {
                sw.WriteLine("new FilterData {");
                sw.WriteLine("Author = \"{0}\",", data.Author);
                sw.WriteLine("Category =  \"{0}\",", data.Category);
                sw.WriteLine("Title =  \"{0}\",", data.Title);
                sw.WriteLine("Copyright = \"{0}\",", data.Copyright);
                sw.WriteLine("MapEnable = new bool[4] {0},{1},{2},{3}",
                             new object[] { "{ " + GetBooleanKeywordString(data.MapEnable[0]),
                                            GetBooleanKeywordString(data.MapEnable[1]),
                                            GetBooleanKeywordString(data.MapEnable[2]),
                                            GetBooleanKeywordString(data.MapEnable[3]) + "}," });
                sw.WriteLine("MapLabel = new string[4] {0}\",\"{1}\",\"{2}\",\"{3}",
                             "{ \"" + data.MapLabel[0],
                             data.MapLabel[1],
                             data.MapLabel[2],
                             data.MapLabel[3] + "\" },");

                sw.WriteLine("ControlEnable = new bool[8] {0},{1},{2},{3},{4},{5},{6},{7} ",
                             new object[] { "{ " + GetBooleanKeywordString(data.ControlEnable[0]),
                                            GetBooleanKeywordString(data.ControlEnable[1]),
                                            GetBooleanKeywordString(data.ControlEnable[2]),
                                            GetBooleanKeywordString(data.ControlEnable[3]),
                                            GetBooleanKeywordString(data.ControlEnable[4]),
                                            GetBooleanKeywordString(data.ControlEnable[5]),
                                            GetBooleanKeywordString(data.ControlEnable[6]),
                                            GetBooleanKeywordString(data.ControlEnable[7]) + "}," });
                sw.WriteLine("ControlLabel = new string[8] {0}\",\"{1}\",\"{2}\",\"{3}\",\"{4}\",\"{5}\",\"{6}\",\"{7}",
                             "{ \"" + data.ControlLabel[0],
                             data.ControlLabel[1],
                             data.ControlLabel[2],
                             data.ControlLabel[3],
                             data.ControlLabel[4],
                             data.ControlLabel[5],
                             data.ControlLabel[6],
                             data.ControlLabel[7] + "\" },");
                sw.WriteLine("ControlValue = new int[8] {0},{1},{2},{3},{4},{5},{6},{7} ",
                             "{ " + data.ControlValue[0].ToString(CultureInfo.InvariantCulture),
                             data.ControlValue[1].ToString(CultureInfo.InvariantCulture),
                             data.ControlValue[2].ToString(CultureInfo.InvariantCulture),
                             data.ControlValue[3].ToString(CultureInfo.InvariantCulture),
                             data.ControlValue[4].ToString(CultureInfo.InvariantCulture),
                             data.ControlValue[5].ToString(CultureInfo.InvariantCulture),
                             data.ControlValue[6].ToString(CultureInfo.InvariantCulture),
                             data.ControlValue[7].ToString(CultureInfo.InvariantCulture) + "},");
                sw.WriteLine("Source = new string[4]  {0}\",\"{1}\",\"{2}\",\"{3}",
                             "{ \"" + data.Source[0],
                             data.Source[1],
                             data.Source[2],
                             data.Source[3] + "\" },");
                sw.WriteLine("PopDialog = {0},", GetBooleanKeywordString(data.PopDialog));
                sw.WriteLine("};");

                ret = sw.ToString();
            }
            return(ret);
        }
Exemplo n.º 14
0
        /// <summary>
        /// Extracts a filter from the current location in the FFL
        /// </summary>
        /// <param name="reader">The BimaryReader to read from.</param>
        /// <returns>The extracted filter data.</returns>
        /// <exception cref="System.ArgumentNullException">The BinaryReader is null.</exception>
        private static FilterData GetFilterfromFFL(StreamReader reader)
        {
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }

            FilterData data = new FilterData
            {
                FileName  = ReadFFLString(reader),
                Category  = ReadFFLString(reader),
                Title     = ReadFFLString(reader),
                Author    = ReadFFLString(reader),
                Copyright = ReadFFLString(reader)
            };

            for (int i = 0; i < 4; i++)
            {
                string map = ReadFFLString(reader);
                if (!string.IsNullOrEmpty(map))
                {
                    data.MapLabel[i]  = map;
                    data.MapEnable[i] = true;
                }
                else
                {
                    data.MapLabel[i]  = string.Format(CultureInfo.InvariantCulture, "Map {0}:", i.ToString(CultureInfo.InvariantCulture));
                    data.MapEnable[i] = false;
                }
            }
            for (int i = 0; i < 8; i++)
            {
                string ctl = ReadFFLString(reader);
                if (!string.IsNullOrEmpty(ctl))
                {
                    data.ControlLabel[i]  = ctl;
                    data.ControlEnable[i] = true;
                }
                else
                {
                    data.ControlLabel[i]  = string.Format(CultureInfo.InvariantCulture, "Control: {0}", i.ToString(CultureInfo.InvariantCulture));
                    data.ControlEnable[i] = false;
                }
            }

            for (int i = 0; i < 8; i++)
            {
                string cv = ReadFFLString(reader);
                data.ControlValue[i] = int.Parse(cv, CultureInfo.InvariantCulture);
            }

            for (int i = 0; i < 4; i++)
            {
                string src = ReadFFLString(reader);
                if (!string.IsNullOrEmpty(src))
                {
                    data.Source[i] = src;
                }
                else
                {
                    data.Source[i] = DefaultSourceCode[i];
                }
            }

            return(data);
        }
Exemplo n.º 15
0
        /// <summary>
        /// Builds the filter_data values from the Filter Factory PARM ReSource
        /// </summary>
        /// <param name="parmbytes">The PARM reSource byte array</param>
        /// <returns>The filter data constructed from the PARM resource.</returns>
        private static FilterData GetFilterDataFromParmBytes(byte[] parmbytes)
        {
            if (parmbytes == null || parmbytes.Length == 0)
            {
                throw new ArgumentException("parmbytes is null or empty.", nameof(parmbytes));
            }

            MemoryStream ms   = null;
            FilterData   data = new FilterData();

            try
            {
                ms = new MemoryStream(parmbytes);
                using (BinaryReader br = new BinaryReader(ms, Windows1252))
                {
                    ms = null;

#if false
                    int cbsize     = br.ReadInt32();
                    int standalone = br.ReadInt32();
#else
                    br.BaseStream.Position += 8L;
#endif

                    for (int i = 0; i < 8; i++)
                    {
                        data.ControlValue[i] = br.ReadInt32();
                    }
                    data.PopDialog = br.ReadInt32() != 0;

                    br.BaseStream.Position += 12; // Skip the 3 unknown data values

                    for (int i = 0; i < 4; i++)
                    {
                        data.MapEnable[i] = br.ReadInt32() != 0;
                    }

                    for (int i = 0; i < 8; i++)
                    {
                        data.ControlEnable[i] = br.ReadInt32() != 0;
                    }
                    data.Category = StringFromASCIIBytes(br.ReadBytes(252)); // read the Category

                    //Michael Johannhanwahr's protect flag...
#if false
                    int iProtected = br.ReadInt32(); // 1 means protected
#else
                    br.BaseStream.Position += 4L;
#endif
                    data.Title     = StringFromASCIIBytes(br.ReadBytes(256));
                    data.Copyright = StringFromASCIIBytes(br.ReadBytes(256));
                    data.Author    = StringFromASCIIBytes(br.ReadBytes(256));

                    for (int i = 0; i < 4; i++)
                    {
                        data.MapLabel[i] = StringFromASCIIBytes(br.ReadBytes(256));
                    }

                    for (int i = 0; i < 8; i++)
                    {
                        data.ControlLabel[i] = StringFromASCIIBytes(br.ReadBytes(256));
                    }

                    for (int i = 0; i < 4; i++)
                    {
                        data.Source[i] = StringFromASCIIBytes(br.ReadBytes(1024));
                    }
                }
            }
            finally
            {
                ms?.Close();
            }

            return(data);
        }
Exemplo n.º 16
0
        private static FilterData LoadTxt(Stream infile)
        {
            if (infile == null)
            {
                throw new ArgumentNullException(nameof(infile));
            }

            FilterData data = new FilterData();

            infile.Position = 0L;

            string line     = string.Empty;
            bool   ctlread  = false;
            bool   inforead = false;
            bool   srcread  = false;
            bool   valread  = false;

            using (StreamReader sr = new StreamReader(infile, Windows1252))
            {
                while ((line = sr.ReadLine()) != null)
                {
                    if (!string.IsNullOrEmpty(line))
                    {
                        if (!inforead)
                        {
                            int i = 0;
                            while (i < 4)
                            {
                                if (!string.IsNullOrEmpty(line))
                                {
                                    string[] split = line.Split(new char[] { ':' }, StringSplitOptions.None);

                                    if (!string.IsNullOrEmpty(split[1]))
                                    {
                                        switch (split[0])
                                        {
                                        case "Category":
                                            data.Category = split[1].Trim();
                                            break;

                                        case "Title":
                                            data.Title = split[1].Trim();
                                            break;

                                        case "Copyright":
                                            data.Copyright = split[1].Trim();
                                            break;

                                        case "Author":
                                            data.Author = split[1].Trim();
                                            break;
                                        }
                                    }
                                    line = sr.ReadLine();
                                    i++;
                                }
                            }
                            inforead = true;
                        }
                        else if (line.StartsWith("Filename", StringComparison.Ordinal))
                        {
                            continue;
                        }
                        else
                        {
                            if (!srcread)
                            {
                                int i = 0;
                                while (i < 4)
                                {
                                    if (!string.IsNullOrEmpty(line))
                                    {
                                        string id  = line.Substring(0, 1).ToUpperInvariant();
                                        string src = line.Substring(2, (line.Length - 2)).Trim();

                                        if (!string.IsNullOrEmpty(src))
                                        {
                                            if (src.Length > 1024)
                                            {
                                                throw new FormatException(Resources.SourceCodeTooLong);
                                            }

                                            switch (id)
                                            {
                                            case "R":
                                                data.Source[0] = src;
                                                break;

                                            case "G":
                                                data.Source[1] = src;
                                                break;

                                            case "B":
                                                data.Source[2] = src;
                                                break;

                                            case "A":
                                                data.Source[3] = src;
                                                break;
                                            }
                                        }
                                        i++;
                                    }

                                    line = sr.ReadLine();
                                }
                                srcread = true;
                            }
                            else
                            {
                                if (!ctlread)
                                {
                                    while (!string.IsNullOrEmpty(line) && line.StartsWith("ctl", StringComparison.Ordinal))
                                    {
                                        string lbl = line.Substring(7, (line.Length - 7)).Trim();
                                        int    cn  = int.Parse(line[4].ToString(), CultureInfo.InvariantCulture); // get the control number
                                        if (!string.IsNullOrEmpty(lbl))
                                        {
                                            data.ControlLabel[cn]  = lbl;
                                            data.ControlEnable[cn] = true;
                                        }
                                        line = sr.ReadLine();
                                    }

                                    bool[] mapsUsed = UsesMap(data.Source);
                                    for (int i = 0; i < 4; i++)
                                    {
                                        data.MapLabel[i]  = string.Format(CultureInfo.InvariantCulture, "Map: {0}", i.ToString(CultureInfo.InvariantCulture));
                                        data.MapEnable[i] = mapsUsed[i];
                                    }
                                    data.PopDialog = HasControls(data);

                                    ctlread = true;
                                }
                                else
                                {
                                    while (!string.IsNullOrEmpty(line) && line.StartsWith("val", StringComparison.Ordinal))
                                    {
                                        string lbl = line.Substring(7, (line.Length - 7)).Trim();
                                        int    cn  = int.Parse(line[4].ToString(), CultureInfo.InvariantCulture); // get the control number
                                        if (!string.IsNullOrEmpty(lbl))
                                        {
                                            data.ControlValue[cn] = int.Parse(lbl, CultureInfo.InvariantCulture);
                                        }
                                        line = sr.ReadLine();
                                    }
                                    valread = true;
                                }
                            }
                        }
                    }
                }
            }
            if (!ctlread && !valread)
            {
                bool[] mapsUsed = UsesMap(data.Source);
                bool[] ctlsUsed = UsesCtl(data.Source);
                for (int i = 0; i < 4; i++)
                {
                    data.MapLabel[i]  = string.Format(CultureInfo.InvariantCulture, "Map: {0}", i.ToString(CultureInfo.InvariantCulture));
                    data.MapEnable[i] = mapsUsed[i];
                }
                for (int i = 0; i < 8; i++)
                {
                    data.ControlLabel[i]  = string.Format(CultureInfo.InvariantCulture, "Control: {0}", i.ToString(CultureInfo.InvariantCulture));
                    data.ControlEnable[i] = ctlsUsed[i];
                }
                data.PopDialog = HasControls(data);
            }

            return(data);
        }
Exemplo n.º 17
0
        private static FilterData LoadAfs(Stream infile)
        {
            if (infile == null)
            {
                throw new ArgumentNullException(nameof(infile));
            }

            FilterData data = new FilterData();

            infile.Position = 9L; // we have already read the signature skip it
            string line    = string.Empty;
            bool   ctlread = false;
            bool   srcread = false;

            using (StreamReader reader = new StreamReader(infile, Windows1252))
            {
                if (!ctlread)
                {
                    for (int i = 0; i < 8; i++)
                    {
                        line = ReadAfsString(reader);
                        if (!string.IsNullOrEmpty(line) && line.Length <= 3)
                        {
                            data.ControlValue[i] = int.Parse(line, CultureInfo.InvariantCulture);
                        }
                    }
                    ctlread = true;
                }

                if (!srcread)
                {
                    StringBuilder builder = new StringBuilder(1024);
                    int           i       = 0;
                    while (i < 4)
                    {
                        line = ReadAfsString(reader);
                        if (line == null)
                        {
                            data.Source[i] = builder.ToString();
                            builder.Length = 0;
                            i++;
                        }
                        else
                        {
                            if (line.Length > 0)
                            {
                                if ((builder.Length + line.Length) > 1024)
                                {
                                    throw new FormatException(Resources.SourceCodeTooLong);
                                }

                                builder.Append(line);
                            }
                        }
                    }

                    srcread = true;
                }
            }

            data.Category = "Filter Factory";
            FileStream fs = infile as FileStream;
            string     Title;

            if (fs != null)
            {
                Title = Path.GetFileName(fs.Name);
            }
            else
            {
                Title = "Untitled";
            }
            data.Title     = Title;
            data.Author    = "Unknown";
            data.Copyright = "Copyright © Unknown";
            bool[] mapsUsed = UsesMap(data.Source);
            bool[] ctlsUsed = UsesCtl(data.Source);
            for (int i = 0; i < 4; i++)
            {
                data.MapLabel[i]  = string.Format(CultureInfo.InvariantCulture, "Map: {0}", new object[] { i.ToString(CultureInfo.InvariantCulture) });
                data.MapEnable[i] = mapsUsed[i];
            }
            for (int i = 0; i < 8; i++)
            {
                data.ControlLabel[i]  = string.Format(CultureInfo.InvariantCulture, "Control: {0}", new object[] { i.ToString(CultureInfo.InvariantCulture) });
                data.ControlEnable[i] = ctlsUsed[i];
            }
            data.PopDialog = HasControls(data);

            return(data);
        }