Exemplo n.º 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);
        }
Exemplo n.º 2
0
        public static void LoadMacroFile(string filename)
        {
            var eReader = new EraStreamReader(false);

            if (!eReader.Open(filename))
            {
                return;
            }
            try
            {
                string line = null;
                while ((line = eReader.ReadLine()) != null)
                {
                    if (line.Length == 0 || line[0] == ';')
                    {
                        continue;
                    }
                    if (line.StartsWith(gID))
                    {
                        if (line.Length < gID.Length + 4)
                        {
                            continue;
                        }
                        var num = line[gID.Length] - '0';
                        if (num < 0 || num > 9)
                        {
                            continue;
                        }
                        if (line[gID.Length + 1] != ':')
                        {
                            continue;
                        }
                        groupName[num] = line.Substring(gID.Length + 2);
                    }
                    for (var i = 0; i < MaxMacro; i++)
                    {
                        if (line.StartsWith(macroName[i]))
                        {
                            macro[i] = line.Substring(macroName[i].Length);
                            break;
                        }
                    }
                }
            }
            catch
            {
            }
            finally
            {
                eReader.Dispose();
            }
        }
Exemplo n.º 3
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();
            }
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
        /// <summary>
        /// GAMEBASE読み込み。GAMEBASE.csvの存在は必須ではないので読み込み失敗したらなかったことにする。
        /// </summary>
        /// <param name="basePath"></param>
        /// <returns>読み込み続行するなら真、エラー終了なら偽</returns>
        public bool LoadGameBaseCsv(string basePath)
        {
            if (!File.Exists(basePath))
            {
                return(true);
            }
            ScriptPosition  pos     = null;
            EraStreamReader eReader = new EraStreamReader(false);

            if (!eReader.Open(basePath))
            {
                //output.PrintLine(eReader.Filename + "のオープンに失敗しました");
                return(true);
            }
            try
            {
                StringStream st = null;
                while ((st = eReader.ReadEnabledLine()) != null)
                {
                    string[] tokens = st.Substring().Split(',');
                    if (tokens.Length < 2)
                    {
                        continue;
                    }
                    string param = tokens[1].Trim();
                    pos = new ScriptPosition(eReader.Filename, eReader.LineNo, st.RowString);
                    switch (tokens[0])
                    {
                    case "コード":
                        if (tryatoi(tokens[1], out ScriptUniqueCode))
                        {
                            if (ScriptUniqueCode == 0L)
                            {
                                ParserMediator.Warn("コード:0のセーブデータはいかなるコードのスクリプトからも読めるデータとして扱われます", pos, 0);
                            }
                        }
                        break;

                    case "バージョン":
                        ScriptVersionDefined = tryatoi(tokens[1], out ScriptVersion);
                        break;

                    case "バージョン違い認める":
                        tryatoi(tokens[1], out ScriptCompatibleMinVersion);
                        break;

                    case "最初からいるキャラ":
                        tryatoi(tokens[1], out DefaultCharacter);
                        break;

                    case "アイテムなし":
                        tryatoi(tokens[1], out DefaultNoItem);
                        break;

                    case "タイトル":
                        ScriptTitle = tokens[1];
                        break;

                    case "作者":
                        ScriptAutherName = tokens[1];
                        break;

                    case "製作年":
                        ScriptYear = tokens[1];
                        break;

                    case "追加情報":
                        ScriptDetail = tokens[1];
                        break;

                    case "ウィンドウタイトル":
                        ScriptWindowTitle = tokens[1];
                        break;

                    case "動作に必要なEmueraのバージョン":
                        Compatible_EmueraVer = tokens[1];
                        if (!Regex.IsMatch(Compatible_EmueraVer, @"^\d+\.\d+\.\d+\.\d+$"))
                        {
                            ParserMediator.Warn("バージョン指定を読み取れなかったので処理を省略します", pos, 0);
                            break;
                        }
                        Version curerntVersion = new Version(GlobalStatic.MainWindow.InternalEmueraVer);
                        Version targetVersoin  = new Version(Compatible_EmueraVer);
                        if (curerntVersion < targetVersoin)
                        {
                            ParserMediator.Warn("このバリアント動作させるにはVer. " + GlobalStatic.MainWindow.EmueraVerText + "以降のバージョンのEmueraが必要です", pos, 2);
                            return(false);
                        }
                        break;
                    }
                }
            }
            catch
            {
                ParserMediator.Warn("GAMEBASE.CSVの読み込み中にエラーが発生したため、読みこみを中断します", pos, 1);
                return(true);
            }
            finally
            {
                eReader.Close();
            }
            if (ScriptWindowTitle == null)
            {
                if (string.IsNullOrEmpty(ScriptTitle))
                {
                    ScriptWindowTitle = "Emuera";
                }
                else
                {
                    ScriptWindowTitle = ScriptTitle + " " + ScriptVersionText;
                }
            }
            return(true);
        }
Exemplo n.º 6
0
        //1756 Process.Load.csより移動
        public static void LoadEraExRenameFile(string filepath)
        {
            if (RenameDic != null)
            {
                RenameDic.Clear();
            }
            //とにかく辞書を作る。辞書がnullのときは UseRenameFileがNOの時のみ
            RenameDic = new Dictionary <string, string>();
            EraStreamReader eReader = new EraStreamReader(false);

            if ((!File.Exists(filepath)) || (!eReader.Open(filepath)))
            {
                return;
            }
            string         line = null;
            ScriptPosition pos  = null;
            Regex          reg  = new Regex(@"\\,", RegexOptions.Compiled);

            try
            {
                while ((line = eReader.ReadLine()) != null)
                {
                    if (line.Length == 0)
                    {
                        continue;
                    }
                    if (line.StartsWith(";"))
                    {
                        continue;
                    }
                    string[] baseTokens = reg.Split(line);
                    if (!baseTokens[baseTokens.Length - 1].Contains(","))
                    {
                        continue;
                    }
                    string[] last = baseTokens[baseTokens.Length - 1].Split(',');
                    baseTokens[baseTokens.Length - 1] = last[0];
                    string[] tokens = new string[2];
                    tokens[0] = string.Join(",", baseTokens);
                    tokens[1] = last[1];
                    pos       = new ScriptPosition(eReader.Filename, eReader.LineNo, line);
                    //右がERB中の表記、左が変換先になる。
                    string value = tokens[0].Trim();
                    string key   = string.Format("[[{0}]]", tokens[1].Trim());
                    RenameDic[key] = value;
                    pos            = null;
                }
            }
            catch (Exception e)
            {
                if (pos != null)
                {
                    throw new CodeEE(e.Message, pos);
                }
                else
                {
                    throw new CodeEE(e.Message);
                }
            }
            finally
            {
                eReader.Close();
            }
        }
Exemplo n.º 7
0
        private bool loadHeaderFile(string filepath, string filename)
        {
            StringStream   st       = null;
            ScriptPosition position = null;
            //EraStreamReader eReader = new EraStreamReader(false);
            //1815修正 _rename.csvの適用
            //eramakerEXの仕様的には.ERHに適用するのはおかしいけど、もうEmueraの仕様になっちゃってるのでしかたないか
            var eReader = new EraStreamReader(true);

            if (!eReader.Open(filepath, filename))
            {
                throw new CodeEE(eReader.Filename + "のオープンに失敗しました");
            }
            try
            {
                while ((st = eReader.ReadEnabledLine()) != null)
                {
                    if (!noError)
                    {
                        return(false);
                    }
                    position = new ScriptPosition(filename, eReader.LineNo, st.RowString);
                    LexicalAnalyzer.SkipWhiteSpace(st);
                    if (st.Current != '#')
                    {
                        throw new CodeEE("ヘッダーの中に#で始まらない行があります", position);
                    }
                    st.ShiftNext();
                    var sharpID = LexicalAnalyzer.ReadSingleIdentifier(st);
                    if (sharpID == null)
                    {
                        ParserMediator.Warn("解釈できない#行です", position, 1);
                        return(false);
                    }
                    if (Config.ICFunction)
                    {
                        sharpID = sharpID.ToUpper();
                    }
                    LexicalAnalyzer.SkipWhiteSpace(st);
                    switch (sharpID)
                    {
                    case "DEFINE":
                        analyzeSharpDefine(st, position);
                        break;

                    case "FUNCTION":
                    case "FUNCTIONS":
                        analyzeSharpFunction(st, position, sharpID == "FUNCTIONS");
                        break;

                    case "DIM":
                    case "DIMS":
                        analyzeSharpDim(st, position, sharpID == "DIMS");
                        break;

                    default:
                        throw new CodeEE("#" + sharpID + "は解釈できないプリプロセッサです", position);
                    }
                }
            }
            catch (CodeEE e)
            {
                if (e.Position != null)
                {
                    position = e.Position;
                }
                ParserMediator.Warn(e.Message, position, 2);
                return(false);
            }
            finally
            {
                eReader.Close();
            }
            return(true);
        }
Exemplo n.º 8
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);
        }