예제 #1
0
        public static XElement GetEanElement(EAN ean)
        {
            var result = new XElement("Animation");

            result.SetAttributeValueWithDefault("Unknown", ean.Header.Unknown1);
            result.SetAttributeValueWithDefault("Duration", ean.Header.Duration);
            if (ean.Header.Zero1 != 0)
            {
                Warning.WriteLine($"EANHeader.Zero1: {ean.Header.Zero1} => 0");
            }
            if (ean.Header.Zero2 != 0)
            {
                Warning.WriteLine($"EANHeader.Zero1: {ean.Header.Zero2} => 0");
            }
            result.SetAttributeValueWithDefault("NodeChild", ean.Header.NodeChild);
            result.SetAttributeValueWithDefault("NodeSibling", ean.Header.NodeSibling);
            result.AddIfNotEmpty(GetKeyframeBlockElement(ean.BlockRotateX, "RotateX"));
            result.AddIfNotEmpty(GetKeyframeBlockElement(ean.BlockRotateY, "RotateY"));
            result.AddIfNotEmpty(GetKeyframeBlockElement(ean.BlockRotateZ, "RotateZ"));
            result.AddIfNotEmpty(GetKeyframeBlockElement(ean.BlockScaleX, "ScaleX"));
            result.AddIfNotEmpty(GetKeyframeBlockElement(ean.BlockScaleY, "ScaleY"));
            result.AddIfNotEmpty(GetKeyframeBlockElement(ean.BlockScaleZ, "ScaleZ"));
            result.AddIfNotEmpty(GetKeyframeBlockElement(ean.BlockTranslateX, "TranslateX"));
            result.AddIfNotEmpty(GetKeyframeBlockElement(ean.BlockTranslateY, "TranslateY"));
            result.AddIfNotEmpty(GetKeyframeBlockElement(ean.BlockTranslateZ, "TranslateZ"));
            return(result);
        }
예제 #2
0
 public Product GetProductByNumber(EAN number)
 {
     if (number == null)
     {
         throw new ArgumentNullException(nameof(number));
     }
     return(Products.SingleOrDefault(item => item.Number.Code == number.Code));
 }
예제 #3
0
        public void ApplyAnimation(string path, bool loop = true)
        {
            var ean = EAN.FromFile(path);
            var transforms = new Transform3DGroup();
            AxisAngleRotation3D x, y, z;

            transforms.Children.Add(new ScaleTransform3D(ean.BlockScaleX.DefaultValue, ean.BlockScaleY.DefaultValue,
                                                         ean.BlockScaleZ.DefaultValue));
            transforms.Children.Add(new RotateTransform3D(
                                        z = new AxisAngleRotation3D(new Vector3D(0, 0, 1), ean.BlockRotateZ.DefaultValue * ToDegree)));
            transforms.Children.Add(new RotateTransform3D(
                                        y = new AxisAngleRotation3D(new Vector3D(0, 1, 0), ean.BlockRotateY.DefaultValue * ToDegree)));
            transforms.Children.Add(new RotateTransform3D(
                                        x = new AxisAngleRotation3D(new Vector3D(1, 0, 0), ean.BlockRotateX.DefaultValue * ToDegree)));
            transforms.Children.Add(new TranslateTransform3D(ean.BlockTranslateX.DefaultValue,
                                                             ean.BlockTranslateY.DefaultValue,
                                                             ean.BlockTranslateZ.DefaultValue));
            foreach (var child in Model.Children)
            {
                child.Transform = transforms;
            }
            var repeatBehavior = loop ? RepeatBehavior.Forever : new RepeatBehavior(1);

            transforms.Children[0].BeginAnimation(ScaleTransform3D.ScaleZProperty,
                                                  GetAnimation(repeatBehavior, ean.Header.Duration, ean.BlockScaleZ));
            transforms.Children[0].BeginAnimation(ScaleTransform3D.ScaleYProperty,
                                                  GetAnimation(repeatBehavior, ean.Header.Duration, ean.BlockScaleY));
            transforms.Children[0].BeginAnimation(ScaleTransform3D.ScaleXProperty,
                                                  GetAnimation(repeatBehavior, ean.Header.Duration, ean.BlockScaleX));
            z.BeginAnimation(AxisAngleRotation3D.AngleProperty,
                             GetAnimation(repeatBehavior, ean.Header.Duration, ean.BlockRotateZ, ToDegree));
            y.BeginAnimation(AxisAngleRotation3D.AngleProperty,
                             GetAnimation(repeatBehavior, ean.Header.Duration, ean.BlockRotateY, ToDegree));
            x.BeginAnimation(AxisAngleRotation3D.AngleProperty,
                             GetAnimation(repeatBehavior, ean.Header.Duration, ean.BlockRotateX, ToDegree));
            transforms.Children[4].BeginAnimation(TranslateTransform3D.OffsetZProperty,
                                                  GetAnimation(repeatBehavior, ean.Header.Duration, ean.BlockTranslateZ));
            transforms.Children[4].BeginAnimation(TranslateTransform3D.OffsetYProperty,
                                                  GetAnimation(repeatBehavior, ean.Header.Duration, ean.BlockTranslateY));
            transforms.Children[4].BeginAnimation(TranslateTransform3D.OffsetXProperty,
                                                  GetAnimation(repeatBehavior, ean.Header.Duration, ean.BlockTranslateX));
        }
예제 #4
0
        /**
         * Perform GET request to set marketplace settings.
         *
         * @param marketplace the marketplace from which the products shall be exported Please see {@link ListMarketplaces } for choose available marketplace.
         * @param url         the marketplace-specific URL of your shop used for identification. On Amazon and ebay, for example, this should be set to your shop URL on the respective marketplace.
         * @param repricing   support Repricing.ON and Repricing.OFF (optional, default value Repricing.ON)
         * @param ean         support EAN.ON and EAN.OFF (optional)
         * @return response from monitor price server
         */

        public void SetMarketplaceSettings(ref String response,
                                           String marketplace,
                                           String url,
                                           Repricing repricing = Repricing.ON,
                                           EAN ean             = EAN.OFF)
        {
            CheckMarketplace(marketplace);


            String fullUrl = BASE_URL +
                             apiKey +
                             PATH_SEPAR +
                             Action.MARKETPLACE_SETTINGS.ToString().ToLower() +
                             QUERY_BEGIN +
                             GetQuery(marketplace, "marketplace") +
                             GetQuery(url, "url") +
                             GetQuery(repricing) +
                             GetQuery(ean);


            DoRequest(ref response, Method.GET, fullUrl);
        }
예제 #5
0
        public static string ConvertISBNToEAN(this string TargetISBN, string EANPrefix = "978")
        {
            int    nCheckSum;
            int    nTemp;
            string EAN;
            string ISBN;

            // Initialization
            nTemp     = 0;
            nCheckSum = 0;
            EAN       = "";

            if (TargetISBN.Length < CONST_ISBN_LEN)
            {
                ISBN = TargetISBN.PadLeft(CONST_ISBN_LEN, '0');
            }
            else
            {
                ISBN = TargetISBN;
            }

            if (!ISBN.IsISBNValid())
            {
                return("");
            }

            if (EANPrefix.Length != 3)
            {
                return("");
            }

            EAN = EANPrefix + ISBN.Substring(0, (CONST_ISBN_LEN - 1));

            nCheckSum = 0;
            for (uint i = 0; i < EAN.Length; i++)
            {
                char cTempVal = EAN.ToCharArray()[i];

                // Do not convert the number directly from a char, since we do not want the ASCII value
                // nTemp = Convert.ToInt32(cTempVal);

                nTemp = Convert.ToInt32(new String(new char[] { cTempVal }));

                if (nTemp > 0)
                {
                    if ((i % 2) == 0)
                    {
                        nCheckSum += nTemp;
                    }
                    else
                    {
                        nCheckSum += (3 * nTemp);
                    }
                }
            }

            nCheckSum = (CONST_ISBN_LEN - (nCheckSum % 10)) % 10;

            EAN += Convert.ToString(nCheckSum);

            return(EAN);
        }
예제 #6
0
파일: Compiler.cs 프로젝트: bundie1990/EDGE
        public static Tuple <Exception, string, List <FileEntry> > Compile(bool exFormat, string file,
                                                                           string directory = null)
        {
            var list     = new List <FileEntry>();
            var fileName = Path.GetFileNameWithoutExtension(file);

            if (string.IsNullOrWhiteSpace(directory))
            {
                directory = Path.GetDirectoryName(file);
            }
            string inputPath  = Path.Combine(Path.GetDirectoryName(file), fileName),
                   outputPath = Path.Combine(directory, fileName);

            Warning.Start();
            try
            {
                switch ((Path.GetExtension(file) ?? string.Empty).ToLowerInvariant())
                {
                case ".bin":
                    switch (fileName.ToLowerInvariant())
                    {
                    case "cos":
                        var array = new short[181];
                        using (var stream = File.OpenRead(file))
                            using (var reader = new BinaryReader(stream))
                                for (var i = 0; i <= 180; i++)
                                {
                                    array[i] = reader.ReadInt16();
                                }
                        File.WriteAllText(outputPath += ".txt",
                                          string.Join(Environment.NewLine, array.Select(value => value / 256.0)));
                        list.Add(new FileEntry(outputPath, "cos.txt"));
                        break;

                    case "font":
                        DecompileFont(file, ref outputPath);
                        list.Add(new FileEntry(outputPath, "font.xml"));
                        break;

                    default:
                    {
                        var index = 0;
                        foreach (var path in Level.CreateFromCompiled(file).Decompile(outputPath))
                        {
                            list.Add(new FileEntry(path, index == 0 ? "level.xml"
                                        : index == 1 ? "level.png" : "level.z.png"));
                            index++;
                        }
                        break;
                    }
                    }
                    break;

                case ".xml":
                    var root = XHelper.Load(file).Elements().First();
                    switch (root.Name.LocalName.ToLowerInvariant())
                    {
                    case "level":
                    {
                        var index = 0;
                        foreach (var path in Level.CreateFromDecompiled(inputPath)
                                 .Compile(outputPath + ".bin"))
                        {
                            list.Add(new FileEntry(path, index == 0 ? "level.bin" : "model.eso"));
                            index++;
                        }
                        break;
                    }

                    case "animation":
                        AssetHelper.ParseEan(root, fileName).Save(outputPath = Path.Combine(directory,
                                                                                            AssetUtil.CrcFullName(fileName, "models") + ".ean"));
                        list.Add(new FileEntry(outputPath, "animation.ean"));
                        break;

                    case "material":
                    {
                        string name;
                        Helper.AnalyzeFileName(out name, out outputPath, fileName);
                        var ema = AssetHelper.ParseEma(root, name);
                        ema.Save(Path.Combine(directory, outputPath += ".ema"));
                        list.Add(new FileEntry(outputPath, "material.ema"));
                        break;
                    }

                    case "models":
                    {
                        string name;
                        Helper.AnalyzeFileName(out name, out outputPath, fileName);
                        var eso = AssetHelper.ParseEso(root, name);
                        eso.Save(Path.Combine(directory, outputPath += ".eso"));
                        list.Add(new FileEntry(outputPath, "model.eso"));
                        break;
                    }

                    case "font":
                    {
                        CompileFont(inputPath, out outputPath, root);
                        list.Add(new FileEntry(outputPath, "font.bin"));
                        break;
                    }
                    }
                    break;

                case ".loc":
                    LOC.FromFile(file).SaveXls(outputPath += ".xls");
                    list.Add(new FileEntry(outputPath, "text.xls"));
                    break;

                case ".xls":
                    LocHelper.FromXls(file).Save(outputPath += ".loc");
                    list.Add(new FileEntry(outputPath, "text.loc"));
                    break;

                case ".etx":
                    var etx = ETX.FromFile(file);
                    etx.GetBitmap().Save(outputPath = Path.Combine(directory, etx.AssetHeader.Name + ".png"));
                    list.Add(new FileEntry(outputPath, "texture.png"));
                    break;

                case ".png":
                {
                    var name = AssetUtil.CrcFullName(fileName, "textures") + ".etx";
                    (exFormat ? (ETX)ETX1804.CreateFromImage(file) : ETX1803.CreateFromImage(file))
                    .Save(outputPath = Path.Combine(directory, name));
                    list.Add(new FileEntry(outputPath, "texture.etx"));
                    break;
                }

                case ".ean":
                    var ean = EAN.FromFile(file);
                    File.WriteAllText(outputPath = Path.Combine(directory,
                                                                Helper.GetDecompiledFileName(fileName, ean) + ".xml"),
                                      AssetHelper.GetEanElement(ean).ToString());
                    list.Add(new FileEntry(outputPath, "animation.xml"));
                    break;

                case ".ema":
                {
                    var ema = EMA.FromFile(file);
                    File.WriteAllText(outputPath = Path.Combine(directory,
                                                                Helper.GetDecompiledFileName(fileName, ema) + ".xml"),
                                      AssetHelper.GetEmaElement(ema).ToString());
                    list.Add(new FileEntry(outputPath, "material.xml"));
                    break;
                }

                case ".eso":
                {
                    var eso = ESO.FromFile(file);
                    File.WriteAllText(outputPath = Path.Combine(directory,
                                                                Helper.GetDecompiledFileName(fileName, eso) + ".xml"),
                                      AssetHelper.GetEsoElement(eso).ToString());
                    list.Add(new FileEntry(outputPath, "model.xml"));
                    break;
                }

                case ".txt":
                    using (var stream = new FileStream(outputPath += ".bin", FileMode.Create,
                                                       FileAccess.Write, FileShare.Read))
                    {
                        var writer = new BinaryWriter(stream);
                        foreach (var num in File.ReadAllText(file)
                                 .Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries)
                                 .Select(double.Parse))
                        {
                            writer.Write((short)Math.Round(num * 256));
                        }
                    }
                    list.Add(new FileEntry(outputPath, "cos.bin"));
                    break;

                default:
                    switch (Path.GetFileName(file))
                    {
                    case "audio":
                        if (Directory.Exists(outputPath = Path.Combine(directory, "sfx")))
                        {
                            Directory.Delete(outputPath, true);
                        }
                        Directory.CreateDirectory(outputPath);
                        string xsb = Path.Combine(file, "sfx.xsb"), xwb = Path.Combine(file, "sfx.xwb");
                        int    offset;
                        using (var stream = new FileStream(xsb, FileMode.Open))
                        {
                            stream.Position = 0x2A;
                            using (var reader = new BinaryReader(stream)) offset = reader.ReadInt32();
                        }
                        var unxwb = new Process {
                            StartInfo = new ProcessStartInfo(
                                Path.Combine(CurrentApp.Directory, "Resources/Libraries/unxwb.exe"),
                                FormattableString.Invariant($"-d \"{outputPath}\" -b \"{xsb}\" {offset} \"{xwb}\""))
                            {
                                UseShellExecute = false, CreateNoWindow = true
                            }
                        };
                        unxwb.Start();
                        unxwb.WaitForExit();
                        list.Add(new FileEntry(outputPath, "sfx"));
                        break;

                    case "sfx":
                        Directory.CreateDirectory(outputPath = Path.Combine(directory, "audio"));
                        string tempPath       = Helper.GetRandomDirectory(),
                               tempInputPath  = Path.Combine(tempPath, "sfx"),
                               tempOutputPath = Path.Combine(tempPath, "audio");

                        /************************************************************************************
                        *     create temp input dir because it's still occupied for unknown reason;        *
                        *     create temp output dir because COMException will be thrown if output dir and *
                        * temp input dir is not under the same drive.                                      *
                        ************************************************************************************/
                        Directory.CreateDirectory(tempInputPath);
                        var projectPath = GenerateXactProject(file, tempInputPath);
                        using (var project = new CXACTMasterProject())
                        {
                            project.Create();
                            project.Load(projectPath, new CXACTMasterProjectCallback(), 0);
                            project.Build(new CXACTMasterProjectCallback(), tempOutputPath, false, false);
                        }
                        foreach (var path in Directory.EnumerateFiles(tempOutputPath))
                        {
                            var target = Path.Combine(outputPath, Path.GetFileName(path));
                            File.Delete(target);
                            File.Move(path, target);
                        }
                        try
                        {
                            Directory.Delete(tempPath, true);
                        }
                        catch
                        {
                            Trace.WriteLine(tempPath, "Delete tempPath failed");
                        }
                        list.Add(new FileEntry(outputPath, "audio"));
                        break;

                    default:
                        throw new NotSupportedException(Localization.DecompileUnrecognizedFile);
                    }
                    break;
                }
                return(new Tuple <Exception, string, List <FileEntry> >(null, Warning.Fetch(), list));
            }
            catch (Exception exc)
            {
                return(new Tuple <Exception, string, List <FileEntry> >(exc, Warning.Fetch(), list));
            }
            finally
            {
                Warning.Clear();
            }
        }
예제 #7
0
        public static EAN GetEANFromHash(this Product product)
        {
            var hash = GetAllDigitHash(product.Name, 9, _modulusEan9);

            return(EAN.NewEAN(hash));
        }