public static string GenerateReturnMethod(FlowSystemEditorWindow flowEditor, FlowWindow exitWindow)
        {
            var file = Resources.Load("UI.Windows/Functions/Templates/TemplateReturnMethod") as TextAsset;

            if (file == null)
            {
                Debug.LogError("Functions Template Loading Error: Could not load template 'TemplateReturnMethod'");

                return(string.Empty);
            }

            var data = FlowSystem.GetData();

            if (data == null)
            {
                return(string.Empty);
            }

            var result = string.Empty;
            var part   = file.text;

            var functionContainer = exitWindow.GetFunctionContainer();

            var functionName           = functionContainer.title;
            var functionCallName       = functionContainer.directory;
            var classNameWithNamespace = Tpl.GetNamespace(exitWindow) + "." + Tpl.GetDerivedClassName(exitWindow);

            result +=
                part.Replace("{FUNCTION_NAME}", functionName)
                .Replace("{FUNCTION_CALL_NAME}", functionCallName)
                .Replace("{CLASS_NAME_WITH_NAMESPACE}", classNameWithNamespace);

            return(result);
        }
Exemple #2
0
        private void LoadTplFile(string newTplPath)
        {
            // Try to load the TPL file
            if (newTplPath != null)
            {
                try {
                    using (Stream tplStream = File.OpenRead(newTplPath)) {
                        Tpl     = new Tpl(tplStream, GcGame.SuperMonkeyBall1);
                        TplPath = newTplPath;
                        paneStageViewer.SetDrawTextures(true);
                    }
                }
                catch (Exception ex) {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    Tpl     = null;
                    TplPath = null;
                }
            }
            else
            {
                Tpl     = null;
                TplPath = null;
            }
            HaveUnsavedTplChanges = false;

            // Update texture list
            paneMaterials.UpdateTrees();
            //UpdateTextureButtons();

            // Update model viewer
            paneStageViewer.InvalidateGL();
        }
Exemple #3
0
        private async void RunTplQuery()
        {
            if (_running)
            {
                return;
            }

            try
            {
                _running = true;

                var query = Tpl.Create(_textBox.Text, out IReadOnlyList <LogMessage> parseErrors);
                if (query == null)
                {
                    errorPane.Visibility     = Visibility.Visible;
                    errorListBox.ItemsSource = parseErrors.Select(e => $"{e.Message}. Line: {e.Location.Line}, Col: {e.Location.Column}");
                }
                else
                {
                    errorPane.Visibility = Visibility.Collapsed;
                    Console.WriteLine("Pipeline Created");

                    //Execute
                    ProcessingOverlay.Visibility = Visibility.Visible;
                    textBoxHolder.Visibility     = Visibility.Hidden;

                    var sw = new System.Diagnostics.Stopwatch();
                    sw.Start();

                    var results = await Task.Run(() => query.Process());

                    sw.Stop();
                    TimeTextBlock.Text = sw.ElapsedMilliseconds + "ms";

                    var resultWindow = new ResultsGridWindow();
                    resultWindow.InitDataGrid(results);
                    resultWindow.Owner = this;
                    resultWindow.Show();
                }
            }
            catch (Exception e)
            {
                errorPane.Visibility     = Visibility.Visible;
                errorListBox.ItemsSource = new List <string>()
                {
                    e.Message
                };
                File.WriteAllText("Error.txt", e.ToString());
            }
            finally
            {
                _running = false;
                textBoxHolder.Visibility     = Visibility.Visible;
                ProcessingOverlay.Visibility = Visibility.Hidden;
            }
        }
        public static string GenerateTransitionMethod(FlowSystemEditorWindow flowEditor, FlowWindow windowFrom, FlowWindow windowTo)
        {
            var file = Resources.Load("UI.Windows/Functions/Templates/TemplateTransitionMethod") as TextAsset;

            if (file == null)
            {
                Debug.LogError("Functions Template Loading Error: Could not load template 'TemplateTransitionMethod'");

                return(string.Empty);
            }

            var data = FlowSystem.GetData();

            if (data == null)
            {
                return(string.Empty);
            }

            var result = string.Empty;
            var part   = file.text;

            // Function link
            var functionId = windowTo.GetFunctionId();

            // Find function container
            var functionContainer = data.GetWindow(functionId);

            if (functionContainer == null)
            {
                // Function not found
                return(string.Empty);
            }

            // Get function root window
            var root = data.GetWindow(functionContainer.functionRootId);
            //var exit = data.GetWindow(functionContainer.functionExitId);

            var functionName           = functionContainer.title;
            var functionCallName       = functionContainer.directory;
            var classNameWithNamespace = Tpl.GetNamespace(root) + "." + Tpl.GetDerivedClassName(root);
            var transitionMethods      = Tpl.GenerateTransitionMethods(windowTo);

            transitionMethods = transitionMethods.Replace("\r\n", "\r\n\t")
                                .Replace("\n", "\n\t");

            result +=
                part.Replace("{TRANSITION_METHODS}", transitionMethods)
                .Replace("{FUNCTION_NAME}", functionName)
                .Replace("{FUNCTION_CALL_NAME}", functionCallName)
                .Replace("{FLOW_FROM_ID}", windowFrom.id.ToString())
                .Replace("{FLOW_TO_ID}", windowTo.id.ToString())
                .Replace("{CLASS_NAME_WITH_NAMESPACE}", classNameWithNamespace);

            return(result);
        }
Exemple #5
0
        protected void Application_Start(object sender, EventArgs e)
        {
            var cfg = Config.LoadConfig();

            Tpl.Configuration(Server.MapPath("~/tpl/"));
            Loger.Init();
            CacheHelper.Init(cfg.cache);
            //Wx.Mp.Init(new Wx.Mp.Wxcfg() { appid = "wxb8288a0ed0f2cc7f", appsecret = "1a55599a01fe52767029848fb3b44061" });
            //WxHelper.Init(cfg.wxcfg);
            //SmsHelper.Init(cfg.smscfg);
        }
Exemple #6
0
        private void importObjMtlToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (!CheckSaveUnsavedChanges())
            {
                return;
            }

            if (ofdLoadObj.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            List <string> modelWarningLog;
            ObjMtlModel   model;

            try {
                model = new ObjMtlModel(ofdLoadObj.FileName, out modelWarningLog);
                if (modelWarningLog.Count != 0)
                {
                    ObjMtlWarningLogDialog warningDlg = new ObjMtlWarningLogDialog(modelWarningLog);
                    if (warningDlg.ShowDialog() != DialogResult.Yes)
                    {
                        return;
                    }
                }
            }
            catch (Exception ex) {
                MessageBox.Show("Error loading the OBJ file. " + ex.Message, "Error loading the OBJ file.",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            Dictionary <Bitmap, int> textureIndexMapping;

            Tpl = new Tpl(model, out textureIndexMapping);
            Gma = new Gma(model, textureIndexMapping);
            paneStageViewer.SetDrawTextures(true);

            // Set TPL / GMA as changed
            HaveUnsavedGmaChanges = true;
            HaveUnsavedTplChanges = true;

            // Update model list
            paneModels.UpdateTree();
            paneModels.UpdateModelButtons();

            // Update material tab
            paneMaterials.UpdateTrees();

            //UpdateTextureButtons();

            // Update stage viewer
            paneStageViewer.InvalidateGL();
        }
Exemple #7
0
 public static Tpl <Urls, Future <Either <ConfigFetchError, WWWWithHeaders> > > withTimeout(
     this Tpl <Urls, Future <Either <ConfigFetchError, WWWWithHeaders> > > tpl,
     Duration timeout, ITimeContext timeContext = default(ITimeContext)
     )
 {
     timeContext = timeContext.orDefault();
     return(tpl.map2((urls, future) =>
                     future
                     .timeout(timeout, () => (ConfigFetchError) new ConfigTimeoutError(urls, timeout), timeContext)
                     .map(e => e.flatten())
                     ));
 }
        public static string GenerateReturnMethod(FlowSystemEditorWindow flowEditor, FD.FlowWindow exitWindow)
        {
            var file = UnityEngine.Resources.Load("UI.Windows/Functions/Templates/TemplateReturnMethod") as TextAsset;

            if (file == null)
            {
                if (UnityEngine.UI.Windows.Constants.LOGS_ENABLED == true)
                {
                    UnityEngine.Debug.LogError("Functions Template Loading Error: Could not load template 'TemplateReturnMethod'");
                }

                return(string.Empty);
            }

            var data = FlowSystem.GetData();

            if (data == null)
            {
                return(string.Empty);
            }

            var result = string.Empty;
            var part   = file.text;

            var functionContainer = exitWindow.GetFunctionContainer();

            if (functionContainer == null)
            {
                // Function not found
                return(string.Empty);
            }

            var exit = data.GetWindow(functionContainer.functionExitId);

            var functionName           = functionContainer.title;
            var functionCallName       = functionContainer.directory;
            var classNameWithNamespace = Tpl.GetClassNameWithNamespace(exit);

            result +=
                part.Replace("{FUNCTION_NAME}", functionName)
                .Replace("{FUNCTION_CALL_NAME}", functionCallName)
                .Replace("{CLASS_NAME_WITH_NAMESPACE}", classNameWithNamespace);

            return(result);
        }
Exemple #9
0
        public static Tpl <Urls, Future <Either <ConfigFetchError, WWWWithHeaders> > > checkingContentType(
            this Tpl <Urls, Future <Either <ConfigFetchError, WWWWithHeaders> > > tpl,
            string expectedContentType = "application/json"
            ) => tpl.map2((urls, future) =>
                          future.map(wwwE => wwwE.flatMapRight(headers => {
            var contentType = headers["CONTENT-TYPE"].getOrElse("undefined");
            // Sometimes we get redirected to internet paygate, which returns HTML
            // instead of our content.
            if (contentType != expectedContentType)
            {
                return(Either <ConfigFetchError, WWWWithHeaders> .Left(
                           new ConfigWrongContentType(urls, expectedContentType, contentType)
                           ));
            }

            return(wwwE);
        }))
                          );
Exemple #10
0
        /* LinkedList like to Iter wrapper. */
        private static Iter <A, Tpl <LinkedListNode <A>, int, bool> > llIter <A>(
            int elements, Tpl <LinkedListNode <A>, int, bool> context
            )
        {
            var cache = Iter <A, Tpl <LinkedListNode <A>, int, bool> > .fnCache(".-llIter");

            if (elements == 0)
            {
                return(cache.empty);
            }
            return((cache.fns ?? (cache.fns = cache.build(
                                      // list node, index, reverse
                                      ctx => { var node = ctx._1; var index = ctx._2; var rev = ctx._3;
                                               var newNode = rev ? node.Previous : node.Next;
                                               return newNode == null
            ? F.none <Tpl <LinkedListNode <A>, int, bool> >()
            : F.some(F.t(newNode, index + (rev ? -1 : 1), rev)); },
                                      ctx => ctx._1.Value,
                                      ctx => F.some(elementsLeft(ctx._1.List.Count, ctx._2, ctx._3))
                                      ))).iter(context));
        }
 /// <summary>
 /// Serves as a hash function for a particular type.
 /// </summary>
 /// <returns>A hash code for the current object.</returns>
 public override int GetHashCode()
 {
     unchecked
     {
         int result = 17;
         result = result * 23 + base.GetHashCode();
         result = result * 23 + ((Name != null) ? Name.GetHashCode() : 0);
         result = result * 23 + Type.GetHashCode();
         result = result * 23 + Editable.GetHashCode();
         result = result * 23 + Mandatory.GetHashCode();
         result = result * 23 + Hidden.GetHashCode();
         result = result * 23 + Hideable.GetHashCode();
         result = result * 23 + Width.GetHashCode();
         result = result * 23 + ((Text != null) ? Text.GetHashCode() : 0);
         result = result * 23 + Xtype.GetHashCode();
         result = result * 23 + Align.GetHashCode();
         result = result * 23 + ((Tooltip != null) ? Tooltip.GetHashCode() : 0);
         result = result * 23 + Sortable.GetHashCode();
         result = result * 23 + SortDirection.GetHashCode();
         result = result * 23 + ((Format != null) ? Format.GetHashCode() : 0);
         result = result * 23 + DecimalPlaces.GetHashCode();
         result = result * 23 + ((DataUrl != null) ? DataUrl.GetHashCode() : 0);
         result = result * 23 + ((DefaultValue != null) ? DefaultValue.GetHashCode() : 0);
         result = result * 23 + ((Description != null) ? Description.GetHashCode() : 0);
         result = result * 23 + Rank.GetHashCode();
         result = result * 23 + ReadOnly.GetHashCode();
         result = result * 23 + MaxLength.GetHashCode();
         result = result * 23 + ((Validator != null) ? Validator.GetHashCode() : 0);
         result = result * 23 + ((SearchFieldDefinition != null) ? SearchFieldDefinition.GetHashCode() : 0);
         result = result * 23 + SingleComboFilter.GetHashCode();
         result = result * 23 + AllowComboCustomValue.GetHashCode();
         result = result * 23 + SearchComboFromLeft.GetHashCode();
         result = result * 23 + LoadWhenVisible.GetHashCode();
         result = result * 23 + Nullable.GetHashCode();
         result = result * 23 + ((Tpl != null) ? Tpl.GetHashCode() : 0);
         result = result * 23 + MinCharSearch.GetHashCode();
         result = result * 23 + ((AdditionalWhereSqlTemp != null) ? AdditionalWhereSqlTemp.GetHashCode() : 0);
         return(result);
     }
 }
Exemple #12
0
        private bool SaveTplFile()
        {
            // If there isn't currently any path set (e.g. we've just imported a model),
            // we have to request one to the user
            if (TplPath == null)
            {
                if (sfdSaveTpl.ShowDialog() != DialogResult.OK)
                {
                    return(false);
                }

                TplPath = sfdSaveTpl.FileName;
            }

            using (Stream tplStream = File.OpenWrite(TplPath)) {
                Tpl.Save(tplStream, GcGame.SuperMonkeyBall1);
            }

            HaveUnsavedTplChanges = false;
            //UpdateTextureButtons();
            return(true);
        }
Exemple #13
0
 public static Tpl <Urls, Future <Either <ConfigFetchError, WWWWithHeaders> > > checkingServerHeader(
     this Tpl <Urls, Future <Either <ConfigFetchError, WWWWithHeaders> > > tpl,
     string headerName, string expectedValue
     ) => tpl.map2((urls, future) =>
                   future.map(wwwE => {
     var headersOpt = wwwE.fold(
         err => F.opt(err as ConfigWWWError).map(_ => _.wwwWithHeaders),
         _ => _.some()
         );
     return(headersOpt.fold(
                wwwE,
                headers => {
         var actual = headers[headerName];
         return actual.exists(expectedValue)
       ? wwwE
       : Either <ConfigFetchError, WWWWithHeaders> .Left(new ConfigServerCheckFailed(
                                                             urls, headerName, expectedValue, actual
                                                             ));
     }
                ));
 })
                   );
        /*public override string OnCompilerTransitionGeneration(FD.FlowWindow window) {
         *
         *      return Tpl.GenerateTransitionMethods(window);
         *
         * }
         *
         * public override string OnCompilerTransitionAttachedGeneration(FD.FlowWindow windowFrom, FD.FlowWindow windowTo, bool everyPlatformHasUniqueName) {
         *
         *      if (windowTo.IsFunction() == true &&
         *          windowTo.IsSmall() == true &&
         *          windowTo.IsContainer() == false &&
         *          windowTo.GetFunctionId() > 0) {
         *
         *              return FlowFunctionsTemplateGenerator.GenerateTransitionMethod(this.flowEditor, windowFrom, windowTo);
         *
         *      }
         *
         *      return base.OnCompilerTransitionAttachedGeneration(windowFrom, windowTo, everyPlatformHasUniqueName);
         *
         * }*/

        public override string OnCompilerTransitionAttachedGeneration(FD.FlowWindow windowFrom, FD.FlowWindow windowTo, bool everyPlatformHasUniqueName)
        {
            if (windowTo.IsLinker() == true &&
                windowTo.GetLinkerId() > 0)
            {
                var result = string.Empty;

                var linkerWindow = FlowSystem.GetWindow(windowTo.GetLinkerId());

                var className = linkerWindow.directory;
                var classNameWithNamespace = Tpl.GetNamespace(linkerWindow) + "." + Tpl.GetDerivedClassName(linkerWindow);

                result += TemplateGenerator.GenerateWindowLayoutTransitionMethod(windowTo, linkerWindow, className, classNameWithNamespace);

                WindowSystem.CollectCallVariations(linkerWindow.GetScreen(), (listTypes, listNames) => {
                    result += TemplateGenerator.GenerateWindowLayoutTransitionTypedMethod(windowTo, linkerWindow, className, classNameWithNamespace, listTypes, listNames);
                });

                return(result);
            }

            return(base.OnCompilerTransitionAttachedGeneration(windowFrom, windowTo, everyPlatformHasUniqueName));
        }
Exemple #15
0
        private void LoadTplFile(string newTplPath)
        {
            // Try to load the TPL file
            if (newTplPath != null)
            {
                try
                {
                    using (Stream tplStream = File.OpenRead(newTplPath))
                    {
                        tpl     = new Tpl(tplStream, GetSelectedGame());
                        tplPath = newTplPath;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    tpl     = null;
                    tplPath = null;
                }
            }
            else
            {
                tpl     = null;
                tplPath = null;
            }
            haveUnsavedTplChanges = false;

            // Update texture list
            UpdateTextureTree();
            UpdateTextureButtons();
            UpdateTextureDisplay();

            // Update model viewer
            reloadOnNextRedraw = true;
            glControlModel.Invalidate();
        }
Exemple #16
0
 public static Tpl <Tpl <Tpl <A, B>, C>, D> unflatten <A, B, C, D>(this Tpl <A, B, C, D> _) =>
 F.t(F.t(F.t(_._1, _._2), _._3), _._4);
Exemple #17
0
 public static Tpl <Tpl <A, B>, C> unflatten <A, B, C>(this Tpl <A, B, C> t) =>
 F.t(F.t(t._1, t._2), t._3);
        public static string GenerateTransitionTypedMethod(FlowSystemEditorWindow flowEditor, FD.FlowWindow windowFrom, FD.FlowWindow windowTo, System.Type[] parameters, string[] parameterNames)
        {
            var file = UnityEngine.Resources.Load("UI.Windows/Functions/Templates/TemplateTransitionTypedMethod") as TextAsset;

            if (file == null)
            {
                Debug.LogError("Functions Template Loading Error: Could not load template 'TemplateTransitionTypedMethod'");

                return(string.Empty);
            }

            var data = FlowSystem.GetData();

            if (data == null)
            {
                return(string.Empty);
            }

            var result = string.Empty;
            var part   = file.text;

            // Function link
            var functionId = windowTo.GetFunctionId();

            // Find function container
            var functionContainer = data.GetWindow(functionId);

            if (functionContainer == null)
            {
                // Function not found
                return(string.Empty);
            }

            // Get function root window
            var root = data.GetWindow(functionContainer.functionRootId);
            //var exit = data.GetWindow(functionContainer.functionExitId);

            var functionName           = functionContainer.title;
            var functionCallName       = functionContainer.directory;
            var classNameWithNamespace = Tpl.GetNamespace(root) + "." + Tpl.GetDerivedClassName(root);
            var transitionMethods      = Tpl.GenerateTransitionMethods(windowTo);

            transitionMethods = transitionMethods.Replace("\r\n", "\r\n\t")
                                .Replace("\n", "\n\t");

            var definition  = parameters.Select((x, i) => ME.Utilities.FormatParameter(x) + " " + parameterNames[i]).ToArray();
            var call        = parameterNames;
            var description = parameters.Select((x, i) => "/// <param name=\"" + parameterNames[i] + "\">" + parameterNames[i] + " to OnParametersPass</param>").ToArray();

            result +=
                part.Replace("{TRANSITION_METHODS}", transitionMethods)
                .Replace("{FUNCTION_NAME}", functionName)
                .Replace("{FUNCTION_CALL_NAME}", functionCallName)
                .Replace("{FLOW_FROM_ID}", windowFrom.id.ToString())
                .Replace("{FLOW_TO_ID}", windowTo.id.ToString())
                .Replace("{CLASS_NAME_WITH_NAMESPACE}", classNameWithNamespace)
                .Replace("{PARAMETERS_DEFINITION}", string.Join(", ", definition))
                .Replace("{PARAMETERS_CALL}", string.Join(", ", call))
                .Replace("{PARAMETERS_DESCRIPTION}", string.Join(System.Environment.NewLine, description));

            return(result);
        }
Exemple #19
0
 public static Tpl <A, B, C> flatten <A, B, C>(this Tpl <Tpl <A, B>, C> t) => F.t(t._1._1, t._1._2, t._2);
        public static string GenerateTransitionMethod(FlowSystemEditorWindow flowEditor, FD.FlowWindow windowFrom, FD.FlowWindow windowTo)
        {
            var file = UnityEngine.Resources.Load("UI.Windows/ABTesting/Templates/TemplateTransitionMethod") as TextAsset;

            if (file == null)
            {
                if (UnityEngine.UI.Windows.Constants.LOGS_ENABLED == true)
                {
                    UnityEngine.Debug.LogError("ABTesting Template Loading Error: Could not load template 'TemplateTransitionMethod'");
                }

                return(string.Empty);
            }

            var data = FlowSystem.GetData();

            if (data == null)
            {
                return(string.Empty);
            }

            if (windowTo.IsABTest() == false)
            {
                return(string.Empty);
            }

            var result = string.Empty;
            var part   = file.text;

            var methodPatternDefault = "(item, h, wh) => WindowSystemFlow.DoFlow<{0}>(this, item, h, wh, false, null)";
            var methods    = string.Empty;
            var methodList = new List <string>();

            foreach (var item in windowTo.abTests.items)
            {
                var window = FlowSystem.GetWindow(item.attachItem.targetId);

                if (window.IsFunction() == true)
                {
                    var winFunc = FlowSystem.GetWindow(window.functionId);
                    if (winFunc != null)
                    {
                        window = FlowSystem.GetWindow(winFunc.functionRootId);
                    }
                    else
                    {
                        window = null;
                    }
                }

                if (window == null)
                {
                    methodList.Add("null");
                }
                else
                {
                    var classNameWithNamespace = Tpl.GetClassNameWithNamespace(window);
                    methodList.Add(string.Format(methodPatternDefault, classNameWithNamespace));
                }
            }

            methods = string.Join(", ", methodList.ToArray());

            result +=
                part.Replace("{METHOD_NAMES}", methods)
                .Replace("{FLOW_FROM_ID}", windowFrom.id.ToString())
                .Replace("{FLOW_TO_ID}", windowTo.id.ToString());

            return(result);
        }
Exemple #21
0
 public static Tpl <A, B, C, D> flatten <A, B, C, D>(this Tpl <Tpl <Tpl <A, B>, C>, D> _) =>
 t(_._1._1._1, _._1._1._2, _._1._2, _._2);
Exemple #22
0
 public Rope <byte> serialize(Tpl <A, B> a) =>
 aRW.serialize(a._1) + bRW.serialize(a._2);
Exemple #23
0
 public static Tpl <A, BB> map2 <A, B, BB>(this Tpl <A, B> t, Fn <A, B, BB> f) => F.t(t._1, f(t._1, t._2));
Exemple #24
0
 public static Tpl <AA, B> map1 <A, AA, B>(this Tpl <A, B> t, Fn <A, B, AA> f) => F.t(f(t._1, t._2), t._2);
Exemple #25
0
 public static Tpl <A, B, C, D, E, F> flatten <A, B, C, D, E, F>(this Tpl <Tpl <Tpl <Tpl <Tpl <A, B>, C>, D>, E>, F> _) =>
 t(_._1._1._1._1._1, _._1._1._1._1._2, _._1._1._1._2, _._1._1._2, _._1._2, _._2);
Exemple #26
0
        private void tsBtnImportObjMtl_Click(object sender, EventArgs e)
        {
            if (!CheckSaveUnsavedChanges())
            {
                return;
            }

            if (ofdLoadObj.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            List <string> modelWarningLog;
            ObjMtlModel   model;

            try
            {
                model = new ObjMtlModel(ofdLoadObj.FileName, out modelWarningLog);
                if (modelWarningLog.Count != 0)
                {
                    ObjMtlWarningLogDialog warningDlg = new ObjMtlWarningLogDialog(modelWarningLog);
                    if (warningDlg.ShowDialog() != DialogResult.Yes)
                    {
                        return;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error loading the OBJ file. " + ex.Message, "Error loading the OBJ file.",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            Dictionary <Bitmap, int> textureIndexMapping;

            tpl = new Tpl(model, out textureIndexMapping);
            gma = new Gma(model, textureIndexMapping);

            // Set TPL / GMA as changed
            haveUnsavedGmaChanges = true;
            haveUnsavedTplChanges = true;

            // Update model list
            UpdateModelTree();
            UpdateModelButtons();
            UpdateModelDisplay();

            // Update material tab
            UpdateMaterialList();
            UpdateMaterialDisplay();

            // Update texture list
            UpdateTextureTree();
            UpdateTextureButtons();
            UpdateTextureDisplay();

            // Update model viewer
            reloadOnNextRedraw = true;
            glControlModel.Invalidate();
        }
Exemple #27
0
        private void backgroundWorkerRunTests_DoWork(object sender, DoWorkEventArgs e)
        {
            RunTestsWorkerParams args = (RunTestsWorkerParams)e.Argument;

            // Find the list of files to process in the input directory
            string[] fileNames = Directory.EnumerateFiles(args.inputPath, "*.*", SearchOption.AllDirectories).Where(fn =>
                                                                                                                    (args.runLzTest && fn.EndsWith(".lz")) ||
                                                                                                                    (args.runArcTest && fn.EndsWith(".arc")) ||
                                                                                                                    (args.runTplTest && fn.EndsWith(".tpl")) ||
                                                                                                                    (args.runGmaTest && fn.EndsWith(".gma"))).ToArray();

            // Process each file
            int nErrors = 0;

            for (int i = 0; i < fileNames.Length; i++)
            {
                string fileName = fileNames[i];

                byte[] originalFileData = File.ReadAllBytes(fileName);

                try
                {
                    // Load and resave the file using the appropiate class
                    MemoryStream originalStream = new MemoryStream(originalFileData);
                    MemoryStream resavedStream  = new MemoryStream();

                    if (args.runLzTest && fileName.EndsWith(".lz"))
                    {
                        MemoryStream decodedStream = new MemoryStream();
                        Lz.Unpack(originalStream, decodedStream, args.game);
                        decodedStream.Position = 0;
                        Lz.Pack(decodedStream, resavedStream, args.game);
                    }
                    else if (args.runArcTest && fileName.EndsWith(".arc"))
                    {
                        ArcContainer arc = new ArcContainer(originalStream);
                        arc.Save(resavedStream);
                    }
                    else if (args.runTplTest && fileName.EndsWith(".tpl"))
                    {
                        Tpl tpl = new Tpl(originalStream, args.game);
                        tpl.Save(resavedStream, args.game);
                    }
                    else if (args.runGmaTest && fileName.EndsWith(".gma"))
                    {
                        Gma gma = new Gma(originalStream, args.game);
                        gma.Save(resavedStream, args.game);
                    }

                    // Check that the resaved file is equal to the original file
                    byte[] resavedFileData = resavedStream.ToArray();

                    if (!ByteArrayUtils.ByteArrayDataEquals(originalFileData, resavedFileData))
                    {
                        if (args.saveDiffErrors)
                        {
                            File.WriteAllBytes(fileName + "-error", resavedFileData);
                        }

                        throw new Exception("The resaved file is different than the original file.\n");
                    }
                }
                catch (Exception ex)
                {
                    txtLog.Invoke(new Action(() => txtLog.AppendText(
                                                 string.Format("{0}: {1}\n", fileName, ex.Message))));
                    nErrors++;
                }

                backgroundWorkerRunTests.ReportProgress(i * 100 / fileNames.Length);
                if (backgroundWorkerRunTests.CancellationPending)
                {
                    return;
                }
            }

            backgroundWorkerRunTests.ReportProgress(100);
            txtLog.Invoke(new Action(() => txtLog.AppendText(
                                         string.Format("Test finished. {0} tested, {1} errors.\n", fileNames.Length, nErrors))));
        }