Example #1
0
        public bool LoadDebugConfig()
        {
            if (!File.Exists(configdebugPath))
            {
                goto err;
            }
            EraStreamReader eReader = new EraStreamReader(false);

            if (!eReader.Open(configdebugPath))
            {
                goto err;
            }
            ScriptPosition pos = null;

            try
            {
                string line = null;
                while ((line = eReader.ReadLine()) != null)
                {
                    if ((line.Length == 0) || (line[0] == ';'))
                    {
                        continue;
                    }
                    pos = new ScriptPosition(eReader.Filename, eReader.LineNo, line);
                    string[] tokens = line.Split(new char[] { ':' });
                    if (tokens.Length < 2)
                    {
                        continue;
                    }
                    AConfigItem item = GetDebugItem(tokens[0].Trim());
                    if (item != null)
                    {
                        item.TryParse(tokens[1]);
                    }
#if UEMUERA_DEBUG
                    //else
                    //	throw new Exception("コンフィグファイルが変");
#endif
                }
            }
            catch (EmueraException ee)
            {
                ParserMediator.ConfigWarn(ee.Message, pos, 1, null);
                goto err;
            }
            catch (Exception exc)
            {
                ParserMediator.ConfigWarn(exc.GetType().ToString() + ":" + exc.Message, pos, 1, exc.StackTrace);
                goto err;
            }
            finally { eReader.Dispose(); }
            Config.SetDebugConfig(this);
            return(true);

err:
            Config.SetDebugConfig(this);
            return(false);
        }
Example #2
0
        // 1.52a改変部分 (単位の差し替えおよび前置、後置のためのコンフィグ処理)
        public void LoadReplaceFile(string filename)
        {
            var eReader = new EraStreamReader(false);

            if (!eReader.Open(filename))
            {
                return;
            }
            ScriptPosition pos = null;

            try
            {
                string line = null;
                while ((line = eReader.ReadLine()) != null)
                {
                    if (line.Length == 0 || line[0] == ';')
                    {
                        continue;
                    }
                    pos = new ScriptPosition(eReader.Filename, eReader.LineNo, line);
                    var tokens = line.Split(',', ':');
                    if (tokens.Length < 2)
                    {
                        continue;
                    }
                    var itemName = tokens[0].Trim();
                    tokens[1] = line.Substring(tokens[0].Length + 1);
                    if (string.IsNullOrEmpty(tokens[1].Trim()))
                    {
                        continue;
                    }
                    var item = GetReplaceItem(itemName);
                    if (item != null)
                    {
                        item.TryParse(tokens[1]);
                    }
                }
            }
            catch (EmueraException ee)
            {
                ParserMediator.Warn(ee.Message, pos, 1);
            }
            catch (Exception exc)
            {
                ParserMediator.Warn(exc.GetType() + ":" + exc.Message, pos, 1, exc.StackTrace);
            }
            finally
            {
                eReader.Dispose();
            }
        }
Example #3
0
        private bool loadConfig(string confPath, bool fix)
        {
            if (!File.Exists(confPath))
            {
                return(false);
            }
            EraStreamReader eReader = new EraStreamReader(false);

            if (!eReader.Open(confPath))
            {
                return(false);
            }

            //加载二进制数据
            var bytes = File.ReadAllBytes(confPath);
            var md5s  = GenericUtils.CalcMd5ListForConfig(bytes);

            ScriptPosition pos  = null;
            int            md5i = 0;

            try
            {
                string line = null;
                //bool defineIgnoreWarningFiles = false;
                while ((line = eReader.ReadLine()) != null)
                {
                    var md5 = md5s[md5i++];
                    if ((line.Length == 0) || (line[0] == ';'))
                    {
                        continue;
                    }
                    pos = new ScriptPosition(eReader.Filename, eReader.LineNo, line);
                    string[] tokens = line.Split(new char[] { ':' });
                    if (tokens.Length < 2)
                    {
                        continue;
                    }
                    var         token_0 = tokens[0].Trim();
                    AConfigItem item    = GetConfigItem(token_0);
                    if (item == null)
                    {
                        token_0 = uEmuera.Utils.SHIFTJIS_to_UTF8(token_0, md5);
                        if (!string.IsNullOrEmpty(token_0))
                        {
                            item = GetConfigItem(token_0);
                        }
                    }
                    if (item != null)
                    {
                        //1806beta001 CompatiDRAWLINEの廃止、CompatiLinefeedAs1739へ移行
                        if (item.Code == ConfigCode.CompatiDRAWLINE)
                        {
                            item = GetConfigItem(ConfigCode.CompatiLinefeedAs1739);
                        }
                        //if ((item.Code == ConfigCode.IgnoreWarningFiles))
                        //{
                        //    if (!defineIgnoreWarningFiles)
                        //        (item.GetValue<List<string>>()).Clear();
                        //    defineIgnoreWarningFiles = true;
                        //    if ((item.Fixed) && (fix))
                        //        item.Fixed = false;
                        //}

                        if (item.Code == ConfigCode.TextEditor)
                        {
                            //パスの関係上tokens[2]は使わないといけない
                            if (tokens.Length > 2)
                            {
                                if (tokens[2].StartsWith("\\"))
                                {
                                    tokens[1] += ":" + tokens[2];
                                }
                                if (tokens.Length > 3)
                                {
                                    for (int i = 3; i < tokens.Length; i++)
                                    {
                                        tokens[1] += ":" + tokens[i];
                                    }
                                }
                            }
                        }
                        if (item.Code == ConfigCode.EditorArgument)
                        {
                            //半角スペースを要求する引数が必要なエディタがあるので別処理で
                            ((ConfigItem <string>)item).Value = tokens[1];
                            continue;
                        }
                        if (item.Code == ConfigCode.MaxLog && Program.AnalysisMode)
                        {
                            //解析モード時はここを上書きして十分な長さを確保する
                            tokens[1] = "10000";
                        }
                        if ((item.TryParse(tokens[1])) && (fix))
                        {
                            item.Fixed = true;
                        }
                    }
#if UEMUERA_DEBUG
                    //else
                    //	throw new Exception("コンフィグファイルが変");
#endif
                }
            }
            catch (EmueraException ee)
            {
                ParserMediator.ConfigWarn(ee.Message, pos, 1, null);
            }
            catch (Exception exc)
            {
                ParserMediator.ConfigWarn(exc.GetType().ToString() + ":" + exc.Message, pos, 1, exc.StackTrace);
            }
            finally { eReader.Dispose(); }
            return(true);
        }
Example #4
0
        public VariableToken GetVariableToken(string key, string subKey, bool allowPrivate)
        {
            VariableToken ret = null;

            if (Config.ICVariable)
            {
                key = key.ToUpper();
            }
            if (allowPrivate)
            {
                LogicalLine line = GlobalStatic.Process.GetScaningLine();
                if ((line != null) && (line.ParentLabelLine != null))
                {
                    ret = line.ParentLabelLine.GetPrivateVariable(key);
                    if (ret != null)
                    {
                        if (subKey != null)
                        {
                            throw new CodeEE("プライベート変数" + key + "に対して@が使われました");
                        }
                        return(ret);
                    }
                }
            }
            if (localvarTokenDic.ContainsKey(key))
            {
                if (localvarTokenDic[key].IsForbid)
                {
                    throw new CodeEE("呼び出された変数\"" + key + "\"は設定により使用が禁止されています");
                }
                LogicalLine line = GlobalStatic.Process.GetScaningLine();
                if (string.IsNullOrEmpty(subKey))
                {
                    //システムの入力待ち中にデバッグコマンドからLOCALを呼んだとき。
                    if ((line == null) || (line.ParentLabelLine == null))
                    {
                        throw new CodeEE("実行中の関数が存在しないため" + key + "を取得又は変更できませんでした");
                    }
                    subKey = line.ParentLabelLine.LabelName;
                }
                else
                {
                    ParserMediator.Warn("コード中でローカル変数を@付きで呼ぶことは推奨されません(代わりに*.ERHファイルの利用を検討してください)", line, 1, false, false);
                    if (Config.ICFunction)
                    {
                        subKey = subKey.ToUpper();
                    }
                }
                LocalVariableToken retLocal = localvarTokenDic[key].GetExistLocalVariableToken(subKey);
                if (retLocal == null)
                {
                    retLocal = localvarTokenDic[key].GetNewLocalVariableToken(subKey, line.ParentLabelLine);
                }
                return(retLocal);
            }
            if (varTokenDic.TryGetValue(key, out ret))
            {
                //一文字変数の禁止オプションを考えた名残
                //if (Config.ForbidOneCodeVariable && ret.CanForbid)
                //    throw new CodeEE("設定によりシステム一文字数値変数の使用が禁止されています(呼び出された変数:" + ret.Name +")");
                if (ret.IsForbid)
                {
                    if (!ret.CanForbid)
                    {
                        throw new ExeEE("CanForbidでない変数\"" + ret.Name + "\"にIsForbidがついている");
                    }
                    throw new CodeEE("呼び出された変数\"" + ret.Name + "\"は設定により使用が禁止されています");
                }
                if (subKey != null)
                {
                    throw new CodeEE("ローカル変数でない変数" + key + "に対して@が使われました");
                }
                return(ret);
            }
            if (subKey != null)
            {
                throw new CodeEE("@の使い方が不正です");
            }
            return(null);
        }
Example #5
0
        static void Main(string[] args)
        {
            ExeDir = Sys.ExeDir;
#if DEBUG
            //debugMode = true;

            //ExeDirにバリアントのパスを代入することでテスト実行するためのコード。
            //ローカルパスの末尾には\必須。
            //ローカルパスを記載した場合は頒布前に削除すること。
            ExeDir = @"";
#endif
            CsvDir     = ExeDir + "csv\\";
            ErbDir     = ExeDir + "erb\\";
            DebugDir   = ExeDir + "debug\\";
            DatDir     = ExeDir + "dat\\";
            ContentDir = ExeDir + "resources\\";
            //エラー出力用
            //1815 .exeが東方板のNGワードに引っかかるそうなので除去
            ExeName = Path.GetFileNameWithoutExtension(Sys.ExeName);

            //解析モードの判定だけ先に行う
            int argsStart = 0;
            if ((args.Length > 0) && (args[0].Equals("-DEBUG", StringComparison.CurrentCultureIgnoreCase)))
            {
                argsStart = 1;                //デバッグモードかつ解析モード時に最初の1っこ(-DEBUG)を飛ばす
                debugMode = true;
            }
            if (args.Length > argsStart)
            {
                //必要なファイルのチェックにはConfig読み込みが必須なので、ここではフラグだけ立てておく
                AnalysisMode = true;
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            ConfigData.Instance.LoadConfig();
            //二重起動の禁止かつ二重起動
            if ((!Config.AllowMultipleInstances) && (Sys.PrevInstance()))
            {
                MessageBox.Show("多重起動を許可する場合、emuera.configを書き換えて下さい", "既に起動しています");
                return;
            }
            if (!Directory.Exists(CsvDir))
            {
                MessageBox.Show("csvフォルダが見つかりません", "フォルダなし");
                return;
            }
            if (!Directory.Exists(ErbDir))
            {
                MessageBox.Show("erbフォルダが見つかりません", "フォルダなし");
                return;
            }
            if (debugMode)
            {
                ConfigData.Instance.LoadDebugConfig();
                if (!Directory.Exists(DebugDir))
                {
                    try
                    {
                        Directory.CreateDirectory(DebugDir);
                    }
                    catch
                    {
                        MessageBox.Show("debugフォルダの作成に失敗しました", "フォルダなし");
                        return;
                    }
                }
            }
            if (AnalysisMode)
            {
                AnalysisFiles = new List <string>();
                for (int i = argsStart; i < args.Length; i++)
                {
                    if (!File.Exists(args[i]) && !Directory.Exists(args[i]))
                    {
                        MessageBox.Show("与えられたファイル・フォルダは存在しません");
                        return;
                    }
                    if ((File.GetAttributes(args[i]) & FileAttributes.Directory) == FileAttributes.Directory)
                    {
                        List <KeyValuePair <string, string> > fnames = Config.GetFiles(args[i] + "\\", "*.ERB");
                        for (int j = 0; j < fnames.Count; j++)
                        {
                            AnalysisFiles.Add(fnames[j].Value);
                        }
                    }
                    else
                    {
                        if (Path.GetExtension(args[i]).ToUpper() != ".ERB")
                        {
                            MessageBox.Show("ドロップ可能なファイルはERBファイルのみです");
                            return;
                        }
                        AnalysisFiles.Add(args[i]);
                    }
                }
            }
            MainWindow win = null;
            while (true)
            {
                StartTime = WinmmTimer.TickCount;
                using (win = new MainWindow())
                {
                    Application.Run(win);
                    Content.AppContents.UnloadContents();
                    if (!Reboot)
                    {
                        break;
                    }

                    RebootWinState = win.WindowState;
                    if (win.WindowState == FormWindowState.Normal)
                    {
                        RebootClientY  = win.ClientSize.Height;
                        RebootLocation = win.Location;
                    }
                    else
                    {
                        RebootClientY  = 0;
                        RebootLocation = new Point();
                    }
                }
                //条件次第ではParserMediatorが空でない状態で再起動になる場合がある
                ParserMediator.ClearWarningList();
                ParserMediator.Initialize(null);
                GlobalStatic.Reset();
                //GC.Collect();
                Reboot = false;
                ConfigData.Instance.ReLoadConfig();
            }
        }
Example #6
0
        private bool loadConfig(string confPath, bool fix)
        {
            if (!File.Exists(confPath))
            {
                return(false);
            }
            var eReader = new EraStreamReader(false);

            if (!eReader.Open(confPath))
            {
                return(false);
            }
            ScriptPosition pos = null;

            try
            {
                string line = null;
                //bool defineIgnoreWarningFiles = false;
                while ((line = eReader.ReadLine()) != null)
                {
                    if (line.Length == 0 || line[0] == ';')
                    {
                        continue;
                    }
                    pos = new ScriptPosition(eReader.Filename, eReader.LineNo, line);
                    var tokens = line.Split(':');
                    if (tokens.Length < 2)
                    {
                        continue;
                    }
                    var item = GetConfigItem(tokens[0].Trim());
                    if (item != null)
                    {
                        //1806beta001 CompatiDRAWLINEの廃止、CompatiLinefeedAs1739へ移行
                        if (item.Code == ConfigCode.CompatiDRAWLINE)
                        {
                            item = GetConfigItem(ConfigCode.CompatiLinefeedAs1739);
                        }
                        //if ((item.Code == ConfigCode.IgnoreWarningFiles))
                        //{
                        //    if (!defineIgnoreWarningFiles)
                        //        (item.GetValue<List<string>>()).Clear();
                        //    defineIgnoreWarningFiles = true;
                        //    if ((item.Fixed) && (fix))
                        //        item.Fixed = false;
                        //}

                        if (item.Code == ConfigCode.TextEditor)
                        {
                            if (tokens.Length > 2)
                            {
                                if (tokens[2].StartsWith("\\"))
                                {
                                    tokens[1] += ":" + tokens[2];
                                }
                                if (tokens.Length > 3)
                                {
                                    for (var i = 3; i < tokens.Length; i++)
                                    {
                                        tokens[1] += ":" + tokens[i];
                                    }
                                }
                            }
                        }
                        if (item.Code == ConfigCode.EditorArgument)
                        {
                            //半角スペースを要求する引数が必要なエディタがあるので別処理で
                            ((ConfigItem <string>)item).Value = tokens[1];
                            continue;
                        }
                        if (item.TryParse(tokens[1]) && fix)
                        {
                            item.Fixed = true;
                        }
                    }
#if DEBUG
                    //else
                    //	throw new Exception("コンフィグファイルが変");
#endif
                }
            }
            catch (EmueraException ee)
            {
                ParserMediator.ConfigWarn(ee.Message, pos, 1, null);
            }
            catch (Exception exc)
            {
                ParserMediator.ConfigWarn(exc.GetType() + ":" + exc.Message, pos, 1, exc.StackTrace);
            }
            finally
            {
                eReader.Dispose();
            }
            return(true);
        }