コード例 #1
0
ファイル: Batch.cs プロジェクト: comorebi-notes/neko-jinja
            /* ----------------------------------------------- Functions */
            #region Functions
            public static bool Exec(ref Setting settingBatchImporter,
                                    ref LibraryEditor_SpriteStudio6.Import.Setting settingImportInitial,
                                    string nameFileList,                                                /* Full-Path */
                                    string nameFileLog                                                  /* Full-Path */
                                    )
            {
//				const string messageLogPrefix = "Batch-Importer";

                if (true == string.IsNullOrEmpty(nameFileList))
                {
                    return(false);
                }

                /* Copy Setting (for Overwriting) */
                LibraryEditor_SpriteStudio6.Import.Setting settingImport = settingImportInitial;

                /* Get BaseDirectory (External File) */
#if false
                /* MEMO: Base directory is asset's directory when specify relative path in ListFile. */
//				string nameDirectoryBaseExternal = LibraryEditor_SpriteStudio6.Utility.File.NamePathRootNative;
#else
                /* MEMO: Base directory is ListFile's directory when specify relative path in ListFile. */
                string nameFile;
                string nameExternal;
                LibraryEditor_SpriteStudio6.Utility.File.PathSplit(out NameFolderBaseExternal, out nameFile, out nameExternal, nameFileList);
#endif
                NameFolderBaseExternal = PathNormalizeDelimiter(NameFolderBaseExternal, true);

                NameFolderRootAsset = "/";
                NameFolderRootAsset = PathNormalizeDelimiter(NameFolderRootAsset, true);

                NameBaseFolderSetting = string.Copy(NameFolderBaseExternal);
                NameBaseFolderAsset   = string.Copy(NameFolderRootAsset);
                NameBaseFolderData    = string.Copy(NameFolderBaseExternal);

                /* Set Log-File */
                System.IO.StreamWriter streamLog = null;
                if (false == string.IsNullOrEmpty(nameFileLog))
                {
                    streamLog = new System.IO.StreamWriter(nameFileLog, false, System.Text.Encoding.Default);                           /* Overwrite */
                }
                LibraryEditor_SpriteStudio6.Utility.Log.StreamExternal = streamLog;

                /* Open List-File */
                System.IO.StreamReader streamList = new System.IO.StreamReader(nameFileList, System.Text.Encoding.Default);

                /* Log Date */
                System.DateTimeOffset dateTime = System.DateTimeOffset.Now;
                LibraryEditor_SpriteStudio6.Utility.Log.Message("[Date imported] " + dateTime.ToString(), true, false);                                                   /* External-File only */
                LibraryEditor_SpriteStudio6.Utility.Log.Message("[In charge] " + System.Environment.MachineName + " (" + System.Environment.UserName + ")", true, false); /* External-File only */

                /* Decode List-File (1 Line) */
                Mode = LibraryEditor_SpriteStudio6.Import.Setting.KindMode.SS6PU;
                int    indexLine     = 0;
                string textLine      = "";
                string textLineValid = "";
                bool   flagValid;
                while (0 <= streamList.Peek())
                {
                    /* Read & Trim 1-Line */
                    flagValid = true;
                    textLine  = streamList.ReadLine();
                    indexLine++;
                    switch (LibraryEditor_SpriteStudio6.Utility.ExternalText.TypeGetLine(out textLineValid, textLine))
                    {
                    case LibraryEditor_SpriteStudio6.Utility.ExternalText.KindType.COMMAND:
                        /* Setting Command */
                        flagValid = DecodeCommand(ref settingBatchImporter, ref settingImport, indexLine, textLineValid);
                        break;

                    case LibraryEditor_SpriteStudio6.Utility.ExternalText.KindType.NORMAL:
                        /* File-Name to import */
                        flagValid = ImportFile(ref settingBatchImporter, ref settingImport, indexLine, textLineValid);
                        break;

                    case LibraryEditor_SpriteStudio6.Utility.ExternalText.KindType.IGNORE:
                        /* Remarks */
                        flagValid = true;
                        break;

                    default:
                        LogError("Syntax Error [" + textLine + "]", indexLine);
                        flagValid = false;
                        break;
                    }

                    /* Check Stopping-Processing */
                    if ((false == flagValid) && (false == settingBatchImporter.FlagNotBreakOnError))
                    {
                        return(false);
                    }
                }

                /* Close List-File */
                if (null != streamList)
                {
                    streamList.Close();
                    streamList = null;
                }

                /* Close Log-File */
                if (null != streamLog)
                {
                    streamLog.Close();
                    streamLog = null;
                }
                LibraryEditor_SpriteStudio6.Utility.Log.StreamExternal = null;

                return(true);
            }
コード例 #2
0
ファイル: Batch.cs プロジェクト: comorebi-notes/neko-jinja
            private static bool DecodeCommand(ref Setting settingBatchImporter,
                                              ref LibraryEditor_SpriteStudio6.Import.Setting settingImport,
                                              int indexLine,
                                              string textLine
                                              )
            {
                /* Check Text */
                string[] textSplit = LibraryEditor_SpriteStudio6.Utility.ExternalText.LineDecodeCommand(textLine);
                if (null == textSplit)
                {
                    LogError("Command Line empty [" + textLine + "]", indexLine);
                    return(false);
                }

                /* Decode Command */
                int countArgument = textSplit.Length;

                switch (textSplit[0])
                {
                case TextKeyNameBaseFolderSetting:
                    if (1 >= countArgument)
                    {                                   /* Set default */
                        NameBaseFolderSetting = string.Copy(NameFolderBaseExternal);
                    }
                    else
                    {
                        NameBaseFolderSetting = PathGetNormalizedAbsolute(textSplit[1], NameBaseFolderSetting, true);
                        if (null == NameBaseFolderSetting)
                        {                                       /* Error */
                            LogError("Path contains illegal characters. [" + textSplit[1] + "]", indexLine);
                            NameBaseFolderSetting = string.Copy(NameFolderBaseExternal);
                            return(false);
                        }
                    }
                    return(true);

                case TextKeyNameBaseFolderAsset:
                    if (1 >= countArgument)
                    {                                   /* Set default */
                        NameBaseFolderAsset = string.Copy(NameFolderRootAsset);
                    }
                    else
                    {
                        NameBaseFolderAsset = PathGetNormalizedAbsolute(textSplit[1], NameBaseFolderAsset, true);
                        if (null == NameBaseFolderAsset)
                        {                                       /* Error */
                            LogError("Path contains illegal characters. [" + textSplit[1] + "]", indexLine);
                            NameBaseFolderAsset = string.Copy(NameFolderRootAsset);
                            return(false);
                        }
                    }
                    return(true);

                case TextKeyNameBaseFolderData:
                    if (1 >= countArgument)
                    {                                   /* Set default */
                        NameBaseFolderAsset = string.Copy(NameFolderBaseExternal);
                    }
                    else
                    {
                        NameBaseFolderData = PathGetNormalizedAbsolute(textSplit[1], NameBaseFolderData, true);
                        if (null == NameBaseFolderData)
                        {                                       /* Error */
                            LogError("Path contains illegal characters. [" + textSplit[1] + "]", indexLine);
                            NameBaseFolderData = string.Copy(NameFolderBaseExternal);
                            return(false);
                        }
                    }
                    return(true);

                case TextKeyNameBaseSettingFile:
                {
                    string nameSettingFile = PathGetNormalizedAbsolute(textSplit[1], NameBaseFolderSetting, false);
                    if (true == settingImport.ImportFile(nameSettingFile))
                    {
                        /* MEMO: Overwrite only when decoding is successful. */
                        settingBatchImporter.SettingOverwriteImport(settingImport);
                    }
                    else
                    {                                           /* Error */
                        LogError("Setting File Not Found [" + textSplit[1] + "]", indexLine);
                        return(false);
                    }
                }
                    return(true);

                case LibraryEditor_SpriteStudio6.Import.Setting.TextKeyMode:
                {
                    LibraryEditor_SpriteStudio6.Import.Setting.KindMode mode = LibraryEditor_SpriteStudio6.Import.Setting.ImportCommonMode(textSplit[1]);
                    if (LibraryEditor_SpriteStudio6.Import.Setting.KindMode.SS6PU <= mode)
                    {                                           /* Valid */
                        Mode = mode;
                    }
                    else
                    {                                           /* Invalid */
                        LogError("Invalid Import-Mode [" + textSplit[1] + "]", indexLine);
                        return(false);
                    }
                }
                    return(true);

                default:
                    break;
                }

                /* MEMO: Interpret as change of individual setting of Importer when not command dedicated to Batch-Importer. */
                /* MEMO: When individual setting change, not overwrite with Batch-Importer setting. */
                if (false == settingImport.Import(textLine))
                {
                    LogError("Unknown Command [" + textLine + "]", indexLine);
                    return(false);
                }

                return(true);
            }