예제 #1
0
        private static void _readFile <TKey>(string file, GDbTabWrapper <TKey, ReadableTuple <TKey> > tab)
        {
            try {
                FieldMapper fieldMapper = new FieldMapper(tab.GetDb <TKey>(tab.Settings.DbData).TabGenerator.MaxElementsToCopyInCustomMethods, tab.ProjectDatabase.AllTables);
                fieldMapper.DbDest = tab.Settings.DbData;

                if ((tab.Settings.DbData & ServerDbs.AllItemTables) != 0)
                {
                    if (file.IsExtension(".lua", ".lub"))
                    {
                        fieldMapper.DbImport = ServerDbs.CItems;

                        if ((tab.Settings.DbData & ServerDbs.ServerItems) != 0)
                        {
                            fieldMapper.Mapping = new DbAttribute[] {
                                ClientItemAttributes.IdentifiedDisplayName, ServerItemAttributes.Name,
                                ClientItemAttributes.UnidentifiedDisplayName, ServerItemAttributes.Name,
                                ClientItemAttributes.ClassNumber, ServerItemAttributes.ClassNumber,
                                ClientItemAttributes.NumberOfSlots, ServerItemAttributes.NumberOfSlots
                            };
                        }
                        else
                        {
                            fieldMapper.Mapping = new DbAttribute[] {
                                ClientItemAttributes.IdentifiedDisplayName, ClientItemAttributes.IdentifiedDisplayName,
                                ClientItemAttributes.IdentifiedDescription, ClientItemAttributes.IdentifiedDescription,
                                ClientItemAttributes.IdentifiedResourceName, ClientItemAttributes.IdentifiedResourceName,
                                ClientItemAttributes.UnidentifiedDisplayName, ClientItemAttributes.UnidentifiedDisplayName,
                                ClientItemAttributes.UnidentifiedDescription, ClientItemAttributes.UnidentifiedDescription,
                                ClientItemAttributes.UnidentifiedResourceName, ClientItemAttributes.UnidentifiedResourceName,
                                ClientItemAttributes.ClassNumber, ClientItemAttributes.ClassNumber,
                                ClientItemAttributes.NumberOfSlots, ClientItemAttributes.NumberOfSlots
                            };
                        }
                    }
                    else if (file.IsExtension(".txt", ".conf"))
                    {
                        if (file.Contains("item_db"))
                        {
                            fieldMapper.DbImport = ServerDbs.Items;

                            if ((tab.Settings.DbData & ServerDbs.ClientItems) != 0)
                            {
                                fieldMapper.Mapping = new DbAttribute[] {
                                    ServerItemAttributes.Name, ClientItemAttributes.IdentifiedDisplayName,
                                    ServerItemAttributes.ClassNumber, ClientItemAttributes.ClassNumber,
                                    ServerItemAttributes.NumberOfSlots, ClientItemAttributes.NumberOfSlots
                                };
                            }
                        }
                        else
                        {
                            fieldMapper.DbImport = ServerDbs.CItems;

                            if (file.Contains("idnum2itemdisplaynametable"))
                            {
                                if ((tab.Settings.DbData & ServerDbs.ClientItems) != 0)
                                {
                                    fieldMapper.Mapping = new DbAttribute[] { ClientItemAttributes.IdentifiedDisplayName, ClientItemAttributes.IdentifiedDisplayName }
                                }
                                ;
                                else
                                {
                                    fieldMapper.Mapping = new DbAttribute[] { ClientItemAttributes.IdentifiedDisplayName, ServerItemAttributes.Name }
                                };
                            }
                            else if (file.Contains("num2itemdisplaynametable"))
                            {
                                if ((tab.Settings.DbData & ServerDbs.ClientItems) != 0)
                                {
                                    fieldMapper.Mapping = new DbAttribute[] { ClientItemAttributes.UnidentifiedDisplayName, ClientItemAttributes.UnidentifiedDisplayName }
                                }
                                ;
                                else
                                {
                                    fieldMapper.Mapping = new DbAttribute[] { ClientItemAttributes.UnidentifiedDisplayName, ServerItemAttributes.Name }
                                };
                            }
                            else if (file.Contains("idnum2itemdesctable"))
                            {
                                if ((tab.Settings.DbData & ServerDbs.ClientItems) != 0)
                                {
                                    fieldMapper.Mapping = new DbAttribute[] { ClientItemAttributes.IdentifiedDescription, ClientItemAttributes.IdentifiedDescription };
                                }
                                else
                                {
                                    throw new Exception("File not supported.");
                                }
                            }
                            else if (file.Contains("num2itemdesctable"))
                            {
                                if ((tab.Settings.DbData & ServerDbs.ClientItems) != 0)
                                {
                                    fieldMapper.Mapping = new DbAttribute[] { ClientItemAttributes.UnidentifiedDescription, ClientItemAttributes.UnidentifiedDescription };
                                }
                                else
                                {
                                    throw new Exception("File not supported.");
                                }
                            }
                            else if (file.Contains("idnum2itemresnametable"))
                            {
                                if ((tab.Settings.DbData & ServerDbs.ClientItems) != 0)
                                {
                                    fieldMapper.Mapping      = new DbAttribute[] { ClientItemAttributes.IdentifiedResourceName, ClientItemAttributes.IdentifiedResourceName };
                                    fieldMapper.AllowCutLine = false;
                                }
                                else
                                {
                                    throw new Exception("File not supported.");
                                }
                            }
                            else if (file.Contains("num2itemresnametable"))
                            {
                                if ((tab.Settings.DbData & ServerDbs.ClientItems) != 0)
                                {
                                    fieldMapper.Mapping      = new DbAttribute[] { ClientItemAttributes.UnidentifiedResourceName, ClientItemAttributes.UnidentifiedResourceName };
                                    fieldMapper.AllowCutLine = false;
                                }
                                else
                                {
                                    throw new Exception("File not supported.");
                                }
                            }
                            else if (file.Contains("num2cardillustnametable"))
                            {
                                if ((tab.Settings.DbData & ServerDbs.ClientItems) != 0)
                                {
                                    fieldMapper.Mapping = new DbAttribute[] { ClientItemAttributes.Illustration, ClientItemAttributes.Illustration };
                                }
                                else
                                {
                                    throw new Exception("File not supported.");
                                }
                            }
                            else if (file.Contains("cardprefixnametable"))
                            {
                                if ((tab.Settings.DbData & ServerDbs.ClientItems) != 0)
                                {
                                    fieldMapper.Mapping = new DbAttribute[] { ClientItemAttributes.Affix, ClientItemAttributes.Affix };
                                }
                                else
                                {
                                    throw new Exception("File not supported.");
                                }
                            }
                            else
                            {
                                throw new Exception("File not supported.");
                            }
                        }
                    }
                    else
                    {
                        throw new Exception("File name not recognized (must be item_db or idnum2itemdisplaynametable.");
                    }

                    fieldMapper.Map(tab, file, fieldMapper.GetMappingFields());
                }
                else
                {
                    fieldMapper.DbImport = tab.Settings.DbData;
                    fieldMapper.Map(tab, file, fieldMapper.GetMappingFields());
                }
            }
            catch (OperationCanceledException) {
                throw new OperationCanceledException();
            }
            catch (Exception err) {
                ErrorHandler.HandleException(err);
            }
        }