public void LogFileLogsErrorMessageWhenFileSizeIsTooLarge()
        {
            int maxFileSize = Convert.ToInt32(Constants.MaximumAllowedFileSizeInBytes);

            byte[] contents = Enumerable.Range(0, maxFileSize + 1).Select(p => byte.MaxValue).ToArray();
            var    ex       = new FileSizeTooLargeException(contents.Length, Constants.MaximumAllowedFileSizeInBytes);

            Logger logger = new Logger();

            using (TemporaryFile sourceFile = new TemporaryFile())
            {
                File.WriteAllBytes(sourceFile.FileName, contents);

                using (FilesContainer filesContainer = new FilesContainer(logger))
                {
                    LoggedFile file = filesContainer.LogFile(sourceFile.FileName, null);
                }
            }

            LogMessage message = logger.DataContainer.LogMessages.FirstOrDefault();

            Assert.IsNotNull(message);
            Assert.AreEqual(LogLevel.Error, message.LogLevel);
            Assert.IsTrue(message.Message.Contains(ex.Message));
        }
        public void LogFileCreatesAPhysicalCopyOfTheSourceFile()
        {
            using (TemporaryFile sourceFile = new TemporaryFile())
            {
                File.WriteAllText(sourceFile.FileName, "Source file content");

                string copiedFilePath   = null;
                bool   exists           = false;
                long   sourceFileLength = sourceFile.GetSize();

                using (FilesContainer filesContainer = new FilesContainer(new Logger()))
                {
                    LoggedFile file = filesContainer.LogFile(sourceFile.FileName, null);
                    copiedFilePath = file.FilePath;

                    exists = File.Exists(copiedFilePath);
                    Assert.IsTrue(exists);
                    Assert.AreEqual(sourceFileLength, file.FileSize);
                }

                exists = File.Exists(copiedFilePath);
                Assert.IsFalse(exists);

                exists = File.Exists(sourceFile.FileName);
                Assert.IsTrue(exists);
            }
        }
示例#3
0
        public void Create_Folder_And_Put_File_Inside()
        {
            //Объявляем переменные, которые могут понадобится
            var user = new User(TestDataProvider.Email, TestDataProvider.Password);

            //Логинимся
            MailHomePage home = new MailHomePage(driver);

            home.Login(user);

            //Переходим к меню и передаем инстанс драйвера дальше
            MailMainMenu   menu  = home.GoToMenu();
            CloudMainMenu  cMenu = menu.GoToCloud();
            FilesContainer file  = cMenu.ContentLoaded();

            //Работаем внутри блока с файлами, вызываем контекстное меню и создаем папку
            file.ContextClick();
            file.CtxCreate();
            file.CtxCreateFolder();
            file.InputFolderNameAndAccept();
            //Возвращаемся на главную, после создания папки
            cMenu.GoToHome();
            //Перетаскиваем файл в папку
            file.MoveFileToFolder();
            file.AcceptMoving();
        }
示例#4
0
        public TheGame(IMemory m, Cache cache)
        {
            pM               = m;
            pCache           = cache;
            pTheGame         = this;
            Instance         = this;
            Address          = m.Read <long>(m.BaseOffsets[OffsetsName.GameStateOffset] + m.AddressOfProcess);
            _AreaChangeCount = new TimeCache <int>(() => M.Read <int>(M.AddressOfProcess + M.BaseOffsets[OffsetsName.AreaChangeCount]), 50);

            AllGameStates = ReadHashMap(Address + 0x48);

            PreGameStatePtr         = AllGameStates["PreGameState"].Address;
            LoginStatePtr           = AllGameStates["LoginState"].Address;
            SelectCharacterStatePtr = AllGameStates["SelectCharacterState"].Address;
            WaitingStatePtr         = AllGameStates["WaitingState"].Address;
            InGameStatePtr          = AllGameStates["InGameState"].Address;
            LoadingStatePtr         = AllGameStates["LoadingState"].Address;
            EscapeStatePtr          = AllGameStates["EscapeState"].Address;
            LoadingState            = AllGameStates["AreaLoadingState"].AsObject <AreaLoadingState>();
            IngameState             = AllGameStates["InGameState"].AsObject <IngameState>();

            _inGame = new FrameCache <bool>(
                () => IngameState.Address != 0 && IngameState.Data.Address != 0 && IngameState.ServerData.Address != 0 && !IsLoading /*&&
                                                                                                                                      * IngameState.ServerData.IsInGame*/);

            Files              = new FilesContainer(m);
            DataOff            = Extensions.GetOffset <IngameStateOffsets>(nameof(IngameStateOffsets.Data));
            CurrentAreaHashOff = Extensions.GetOffset <IngameDataOffsets>(nameof(IngameDataOffsets.CurrentAreaHash));
        }
示例#5
0
        public TheGame(IMemory m, Cache cache)
        {
            pM                      = m;
            pCache                  = cache;
            pTheGame                = this;
            Instance                = this;
            Address                 = m.Read <long>(m.BaseOffsets[OffsetsName.GameStateOffset] + m.AddressOfProcess);
            _AreaChangeCount        = new TimeCache <int>(() => M.Read <int>(M.AddressOfProcess + M.BaseOffsets[OffsetsName.AreaChangeCount]), 50);
            AllGameStates           = ReadList(Address);
            PreGameStatePtr         = AllGameStates[GameStateE.PreGameState].Address;
            LoginStatePtr           = AllGameStates[GameStateE.LoginState].Address;
            SelectCharacterStatePtr = AllGameStates[GameStateE.SelectCharacterState].Address;
            WaitingStatePtr         = AllGameStates[GameStateE.WaitingState].Address;
            InGameStatePtr          = AllGameStates[GameStateE.InGameState].Address;
            LoadingStatePtr         = AllGameStates[GameStateE.LoadingState].Address;
            EscapeStatePtr          = AllGameStates[GameStateE.EscapeState].Address;

            LoadingState = new AreaLoadingState(AllGameStates[GameStateE.AreaLoadingState]);
            IngameState  = new IngameState(AllGameStates[GameStateE.InGameState]);

            _inGame = new FrameCache <bool>(
                () => IngameState.Address != 0 && IngameState.Data.Address != 0 && IngameState.Data.ServerData.Address != 0 && !IsLoading /*&&
                                                                                                                                           * IngameState.ServerData.IsInGame*/);

            Files = new FilesContainer(m);
        }
        public void GenerateFileNameHandlesVariousInputs(string input, string expectedValue)
        {
            FilesContainer filesContainer = new FilesContainer(new Logger());

            string value = filesContainer.NormalizeFileName(input);

            Assert.AreEqual(expectedValue, value);
        }
        public void GetLoggedFilesReturnsEmptyList()
        {
            FilesContainer filesContainer = new FilesContainer(new Logger());

            List <LoggedFile> loggedFiles = filesContainer.GetLoggedFiles();

            Assert.IsNotNull(loggedFiles);
            Assert.AreEqual(0, loggedFiles.Count);
        }
        public void FileNameAlwaysHasValue(string fileName)
        {
            using (FilesContainer filesContainer = new FilesContainer(new Logger()))
            {
                LoggedFile loggedFile = filesContainer.LogAsFile("Content", fileName);

                Assert.IsNotNull(loggedFile.FileName);
            }
        }
        public void EmptyStringIsIgnored(string content)
        {
            using (FilesContainer filesContainer = new FilesContainer(new Logger()))
            {
                LoggedFile loggedFile = filesContainer.LogAsFile(content, "File.txt");

                Assert.IsNull(loggedFile);
            }
        }
        public void EmptyByteArrayIsIgnored()
        {
            using (FilesContainer filesContainer = new FilesContainer(new Logger()))
            {
                LoggedFile loggedFile = filesContainer.LogAsFile(new byte[] { }, "File.txt");

                Assert.IsNull(loggedFile);
            }
        }
        public void GetLoggedFilesIsNotReferenced()
        {
            using (FilesContainer filesContainer = new FilesContainer(new Logger()))
            {
                List <LoggedFile> loggedFiles = filesContainer.GetLoggedFiles();

                filesContainer.LogAsFile("Content", null);

                Assert.AreEqual(0, loggedFiles.Count);
            }
        }
示例#12
0
 private void PrintFileBuffer(FilesContainer filebuffer, DirectoryInfo directoryPath)
 {
     Console.WriteLine("\n--- Writing Dictionaty ---");
     string[] keys = filebuffer.GetKeys();
     foreach (string key in keys)
     {
         StringBuilder shortPath = new StringBuilder(key);
         shortPath.Remove(0, directoryPath.FullName.Length);
         Console.WriteLine($"[{shortPath}] -> somefile...(null={filebuffer.GetValueByKey(key)==null})");
     }
     Console.WriteLine("--- End Writing Dictionary ---\n");
 }
        public void DisposeUpdatesTheDisposedField()
        {
            FilesContainer filesContainer = new FilesContainer(new Logger());

            bool disposedBefore = filesContainer._disposed;

            filesContainer.Dispose();

            bool disposedAfter = filesContainer._disposed;

            Assert.IsFalse(disposedBefore);
            Assert.IsTrue(disposedAfter);
        }
        public void LogStringAsFileCreatesAPhysicalFile()
        {
            using (FilesContainer filesContainer = new FilesContainer(new Logger()))
            {
                string contents = "String file content";

                LoggedFile file = filesContainer.LogAsFile(contents, null);

                FileInfo fi = new FileInfo(file.FilePath);

                Assert.IsTrue(fi.Exists);
                Assert.IsNotNull(file.FileName);
                Assert.AreEqual(fi.Length, file.FileSize);
            }
        }
        public void LogByteArrayAsFileCreatesAPhysicalFile()
        {
            using (FilesContainer filesContainer = new FilesContainer(new Logger()))
            {
                byte[] contents = Encoding.UTF8.GetBytes("Byte[] file content");

                LoggedFile file = filesContainer.LogAsFile(contents, null);

                FileInfo fi = new FileInfo(file.FilePath);

                Assert.IsTrue(fi.Exists);
                Assert.IsNotNull(file.FileName);
                Assert.AreEqual(fi.Length, file.FileSize);
            }
        }
        public void DisposeAlsoDisposesTheTemporaryFiles()
        {
            FilesContainer filesContainer = new FilesContainer(new Logger());

            filesContainer.LogAsFile("Content", null);
            filesContainer.LogAsFile("Content", null);

            List <TemporaryFile> temporaryFiles = filesContainer._temporaryFiles;

            filesContainer.Dispose();

            foreach (TemporaryFile item in temporaryFiles)
            {
                Assert.IsTrue(item._disposed);
            }
        }
        public void LogFileCopiesTheContentsOfTheSourceFile()
        {
            using (TemporaryFile sourceFile = new TemporaryFile())
            {
                string sourceContent = "Source file content";

                File.WriteAllText(sourceFile.FileName, sourceContent);

                using (FilesContainer filesContainer = new FilesContainer(new Logger()))
                {
                    LoggedFile file = filesContainer.LogFile(sourceFile.FileName, null);

                    string content = File.ReadAllText(file.FilePath);

                    Assert.AreEqual(sourceContent, content);
                }
            }
        }
        public void LogStringAsFileLogsErrorMessageWhenFileSizeIsTooLarge()
        {
            int    maxFileSize = Convert.ToInt32(Constants.MaximumAllowedFileSizeInBytes);
            string contents    = string.Join(string.Empty, Enumerable.Range(0, maxFileSize + 1).Select(p => "0"));
            var    ex          = new FileSizeTooLargeException(contents.Length, Constants.MaximumAllowedFileSizeInBytes);

            Logger logger = new Logger();

            using (FilesContainer filesContainer = new FilesContainer(logger))
            {
                LoggedFile file = filesContainer.LogAsFile(contents, null);
            }

            LogMessage message = logger.DataContainer.LogMessages.FirstOrDefault();

            Assert.IsNotNull(message);
            Assert.AreEqual(LogLevel.Error, message.LogLevel);
            Assert.IsTrue(message.Message.Contains(ex.Message));
        }
        public void LogFileLogsErrorMessageWhenFileWasNotFound()
        {
            string fileName = null;

            using (TemporaryFile tempFile = new TemporaryFile())
            {
                fileName = tempFile.FileName;
            }

            var ex = new LogFileException(fileName, new FileNotFoundException(null, fileName));

            Logger logger = new Logger();

            using (FilesContainer filesContainer = new FilesContainer(logger))
            {
                LoggedFile file = filesContainer.LogFile(fileName);
            }

            LogMessage message = logger.DataContainer.LogMessages.FirstOrDefault();

            Assert.IsNotNull(message);
            Assert.AreEqual(LogLevel.Error, message.LogLevel);
            Assert.IsTrue(message.Message.Contains(ex.Message));
        }
示例#20
0
 public FileController()
 {
     files       = FilesContainer.getInstance();
     directories = new List <directory>();
 }
示例#21
0
        public ModValue(ItemMod mod, FilesContainer fs, int iLvl, BaseItemType baseItem)
        {
            try
            {
                var baseClassName = baseItem.ClassName.ToLower().Replace(' ', '_');
                Record    = fs.Mods.records[mod.RawName];
                AffixType = Record.AffixType;
                AffixText = string.IsNullOrEmpty(Record.UserFriendlyName) ? Record.Key : Record.UserFriendlyName;
                IsCrafted = Record.Domain == ModDomain.Master;
                StatValue = new[] { mod.Value1, mod.Value2, mod.Value3, mod.Value4 };
                Tier      = -1;
                var subOptimalTierDistance = 0;

                if (fs.Mods.recordsByTier.TryGetValue(Tuple.Create(Record.Group, Record.AffixType),
                                                      out var allTiers))
                {
                    var tierFound = false;
                    TotalTiers = 0;
                    var keyRcd             = Record.Key.Where(char.IsLetter).ToArray();
                    var optimizedListTiers = allTiers.Where(x => x.Key.StartsWith(new string(keyRcd))).ToList();

                    foreach (var tmp in optimizedListTiers)
                    {
                        /*if(Math.Abs(Record.Key.Length-tmp.Key.Length)>2)
                         *  continue;*/
                        var keyrcd = tmp.Key.Where(char.IsLetter).ToArray();

                        if (!keyrcd.SequenceEqual(keyRcd))
                        {
                            continue;
                        }

                        int baseChance;

                        if (!tmp.TagChances.TryGetValue(baseClassName, out baseChance))
                        {
                            baseChance = -1;
                        }

                        int defaultChance;

                        if (!tmp.TagChances.TryGetValue("default", out defaultChance))
                        {
                            defaultChance = 0;
                        }

                        var tagChance = -1;

                        foreach (var tg in baseItem.Tags)
                        {
                            if (tmp.TagChances.ContainsKey(tg))
                            {
                                tagChance = tmp.TagChances[tg];
                            }
                        }

                        var moreTagChance = -1;

                        foreach (var tg in baseItem.MoreTagsFromPath)
                        {
                            if (tmp.TagChances.ContainsKey(tg))
                            {
                                moreTagChance = tmp.TagChances[tg];
                            }
                        }

                        #region GetOnlyValidMods

                        switch (baseChance)
                        {
                        case 0:
                            break;

                        case -1:     //baseClass name not found in mod tags.
                            switch (tagChance)
                            {
                            case 0:
                                break;

                            case -1:         //item tags not found in mod tags.
                                switch (moreTagChance)
                                {
                                case 0:
                                    break;

                                case -1:             //more item tags not found in mod tags.
                                    if (defaultChance > 0)
                                    {
                                        TotalTiers++;

                                        if (tmp.Equals(Record))
                                        {
                                            Tier      = TotalTiers;
                                            tierFound = true;
                                        }

                                        if (!tierFound && tmp.MinLevel <= iLvl)
                                        {
                                            subOptimalTierDistance++;
                                        }
                                    }

                                    break;

                                default:
                                    TotalTiers++;

                                    if (tmp.Equals(Record))
                                    {
                                        Tier      = TotalTiers;
                                        tierFound = true;
                                    }

                                    if (!tierFound && tmp.MinLevel <= iLvl)
                                    {
                                        subOptimalTierDistance++;
                                    }
                                    break;
                                }

                                break;

                            default:
                                TotalTiers++;

                                if (tmp.Equals(Record))
                                {
                                    Tier      = TotalTiers;
                                    tierFound = true;
                                }

                                if (!tierFound && tmp.MinLevel <= iLvl)
                                {
                                    subOptimalTierDistance++;
                                }
                                break;
                            }

                            break;

                        default:
                            TotalTiers++;

                            if (tmp.Equals(Record))
                            {
                                Tier      = TotalTiers;
                                tierFound = true;
                            }

                            if (!tierFound && tmp.MinLevel <= iLvl)
                            {
                                subOptimalTierDistance++;
                            }
                            break;
                        }

                        #endregion
                    }

                    if (Tier == -1 && !string.IsNullOrEmpty(Record.Tier))
                    {
                        /*var tierNumber = Record.Tier.Split(' ')[1];
                         * tierNumber = tierNumber.Replace('M', ' ');*/
                        var tierNumber = new string(Record.Tier.Where(x => char.IsDigit(x)).ToArray());

                        if (int.TryParse(tierNumber, out var result))
                        {
                            Tier       = result;
                            TotalTiers = optimizedListTiers.Count;
                        }
                    }

                    /*else if (string.IsNullOrEmpty(Record.Tier))
                     * {
                     *  Tier = -1;
                     *  totalTiers = 0;
                     * }*/
                }

                double hue = TotalTiers == 1 ? 180 : 120 - Math.Min(subOptimalTierDistance, 3) * 40;
                Color = ConvertHelper.ColorFromHsv(hue, TotalTiers == 1 ? 0 : 1, 1);
            }
            catch (Exception e)
            {
                DebugWindow.LogMsg(e?.StackTrace, 1, Color.GreenYellow);
            }
        }
示例#22
0
        public CustomItem(LabelOnGround item, FilesContainer fs, float distance, Dictionary <string, int> weightsRules, bool isMetamorphItem = false)
        {
            if (isMetamorphItem)
            {
                IsMetaItem    = true;
                LabelOnGround = item;
                Distance      = distance;
                var itemItemOnGround = item.ItemOnGround;
                var worldIcon        = itemItemOnGround?.GetComponent <MinimapIcon>();
                if (worldIcon == null)
                {
                    return;
                }
                //var groundItem = worldItem.ItemEntity;
                WorldIcon  = worldIcon;
                GroundItem = itemItemOnGround;
                Path       = GroundItem?.Path;

                if (Path != null && Path.Length < 1)
                {
                    DebugWindow.LogMsg($"World2: {worldIcon.Address:X} P: {Path}", 2);
                    DebugWindow.LogMsg($"Ground2: {GroundItem.Address:X} P {Path}", 2);
                    return;
                }

                IsTargeted = () =>
                {
                    var isTargeted = itemItemOnGround.GetComponent <Targetable>()?.isTargeted;
                    return(isTargeted != null && (bool)isTargeted);
                };

                var baseItemType = fs.BaseItemTypes.Translate(Path);

                if (baseItemType != null)
                {
                    ClassName = baseItemType.ClassName;
                    BaseName  = baseItemType.BaseName;
                    Width     = baseItemType.Width;
                    Height    = baseItemType.Height;
                    if (weightsRules.TryGetValue(BaseName, out var w))
                    {
                        Weight = w;
                    }
                }

                IsValid = true;
            }
            else
            {
                isMetamorphItem = false;
                LabelOnGround   = item;
                Distance        = distance;
                var itemItemOnGround = item.ItemOnGround;
                var worldItem        = itemItemOnGround?.GetComponent <WorldItem>();
                if (worldItem == null)
                {
                    return;
                }
                var groundItem = worldItem.ItemEntity;
                GroundItem = groundItem;
                Path       = groundItem?.Path;
                if (GroundItem == null)
                {
                    return;
                }

                if (Path != null && Path.Length < 1)
                {
                    DebugWindow.LogMsg($"World: {worldItem.Address:X} P: {Path}", 2);
                    DebugWindow.LogMsg($"Ground: {GroundItem.Address:X} P {Path}", 2);
                    return;
                }

                IsTargeted = () =>
                {
                    var isTargeted = itemItemOnGround.GetComponent <Targetable>()?.isTargeted;
                    return(isTargeted != null && (bool)isTargeted);
                };

                var baseItemType = fs.BaseItemTypes.Translate(Path);

                if (baseItemType != null)
                {
                    ClassName = baseItemType.ClassName;
                    BaseName  = baseItemType.BaseName;
                    Width     = baseItemType.Width;
                    Height    = baseItemType.Height;
                    if (weightsRules.TryGetValue(BaseName, out var w))
                    {
                        Weight = w;
                    }
                }

                var WeaponClass = new List <string>
                {
                    "One Hand Mace",
                    "Two Hand Mace",
                    "One Hand Axe",
                    "Two Hand Axe",
                    "One Hand Sword",
                    "Two Hand Sword",
                    "Thrusting One Hand Sword",
                    "Bow",
                    "Claw",
                    "Dagger",
                    "Sceptre",
                    "Staff",
                    "Wand"
                };

                if (GroundItem.HasComponent <Quality>())
                {
                    var quality = GroundItem.GetComponent <Quality>();
                    Quality = quality.ItemQuality;
                }

                if (GroundItem.HasComponent <Base>())
                {
                    var @base = GroundItem.GetComponent <Base>();
                    IsElder  = @base.isElder;
                    IsShaper = @base.isShaper;
                }

                if (GroundItem.HasComponent <Mods>())
                {
                    var mods = GroundItem.GetComponent <Mods>();
                    Rarity       = mods.ItemRarity;
                    IsIdentified = mods.Identified;
                    ItemLevel    = mods.ItemLevel;
                    IsFractured  = mods.HaveFractured;
                }

                if (GroundItem.HasComponent <Sockets>())
                {
                    var sockets = GroundItem.GetComponent <Sockets>();
                    IsRGB       = sockets.IsRGB;
                    Sockets     = sockets.NumberOfSockets;
                    LargestLink = sockets.LargestLinkSize;
                }

                if (WeaponClass.Any(ClassName.Equals))
                {
                    IsWeapon = true;
                }

                MapTier = GroundItem.HasComponent <Map>() ? GroundItem.GetComponent <Map>().Tier : 0;
                IsValid = true;
            }
        }
示例#23
0
        public SellitItem(NormalInventoryItem item, FilesContainer fs)
        {
            NormalInventoryItem = item;
            Rect       = item.GetClientRectCache;
            Center     = item.GetClientRectCache.Center;
            ItemEntity = item.Item;

            Path = ItemEntity.Path;
            var baseItemType = fs.BaseItemTypes.Translate(Path);

            if (baseItemType != null)
            {
                ClassName = baseItemType.ClassName;
                BaseName  = baseItemType.BaseName;
                Width     = baseItemType.Width;
                Height    = baseItemType.Height;
            }


            if (ItemEntity.HasComponent <Quality>())
            {
                var quality = ItemEntity.GetComponent <Quality>();
                Quality = quality.ItemQuality;
            }

            if (ItemEntity.HasComponent <Base>())
            {
                var abase = ItemEntity.GetComponent <Base>();
                IsElder  = abase.isElder;
                IsShaper = abase.isShaper;
            }

            if (ItemEntity.HasComponent <Mods>())
            {
                var mods = ItemEntity.GetComponent <Mods>();
                Rarity       = mods.ItemRarity;
                IsIdentified = mods.Identified;
                ItemLevel    = mods.ItemLevel;
                IsFractured  = mods.HaveFractured;
                if (ItemLevel >= 60 && ItemLevel <= 74)
                {
                    IsCrItemLevel = true;
                }
            }

            if (ItemEntity.HasComponent <Sockets>())
            {
                var sockets = ItemEntity.GetComponent <Sockets>();
                IsRGB       = sockets.IsRGB;
                Sockets     = sockets.NumberOfSockets;
                LargestLink = sockets.LargestLinkSize;
            }

            var ArmourClass = new List <string>
            {
                "Belt",
                "Helmet",
                "Body Armour",
                "Boots",
                "Gloves"
            };

            if (ArmourClass.Any(ClassName.Equals))
            {
                IsArmour = true;
            }

            switch (ClassName)
            {
            case "Amulet":
                ItemType = ItemTypes.Amulet;
                IsAmulet = true;
                break;

            case "Ring":
                ItemType = ItemTypes.Ring;
                IsRing   = true;
                break;

            case "Belt":
                ItemType = ItemTypes.Belt;
                IsBelt   = true;
                break;

            case "Helmet":
                ItemType = ItemTypes.Helmet;
                IsHelmet = true;
                break;

            case "Body Armour":
                ItemType    = ItemTypes.BodyArmour;
                IsBodyArmor = true;
                break;

            case "Boots":
                ItemType = ItemTypes.Boots;
                IsBoots  = true;
                break;

            case "Gloves":
                ItemType = ItemTypes.Gloves;
                IsGloves = true;
                break;

            case "Two Hand Mace":
            case "Two Hand Axe":
            case "Two Hand Sword":
            case "Bow":
            case "Staff":
                IsWeapon          = true;
                ItemType          = ItemTypes.TwoHandedWeapon;
                IsTwoHandedWeapon = true;
                break;

            case "Shield":
            case "Quivers":
            case "One Hand Mace":
            case "One Hand Axe":
            case "One Hand Sword":
            case "Thrusting One Hand Sword":
            case "Claw":
            case "Dagger":
            case "Sceptre":
            case "Wand":
                IsWeapon          = true;
                ItemType          = ItemTypes.OneHandedWeapon;
                IsOneHandedWeapon = true;
                break;
            }

            var WeaponClass = new List <string>
            {
                "Two Hand Axe",
                "Two Hand Mace",
                "Two Hand Sword",
                "One Hand Axe",
                "Bow",
                "Staff",
                "One Hand Sword",
                "One Hand Mace",
                "Thrusting One Hand Sword",
                "Claw",
                "Dagger",
                "Sceptre",
                "Wand"
            };

            if (ItemEntity?.Path?.Contains(@"/Weapons/") == true)
            {
                IsWeapon = true;
            }
            if (WeaponClass.Any(ClassName.Equals))
            {
                IsWeapon = true;
            }

            MapTier = ItemEntity.HasComponent <Map>() ? ItemEntity.GetComponent <Map>().Tier : 0;
        }
示例#24
0
        public void StartTest()
        {
            Console.WriteLine("\n--- TestFilesContainer ---");

            // Получим список путей ко всем файлам в указанной дирректории
            string[] filesPaths = Directory.GetFiles(directoryPath.FullName, "*", SearchOption.AllDirectories);

            Console.WriteLine("Get all inner files");

            // Получим из путей файлы и запишем их в буффер
            List <byte[]> filesInBytes = new List <byte[]>();

            for (int i = 0; i < filesPaths.Length; i++)
            {
                byte[] file = File.ReadAllBytes(filesPaths[i]);
                if (file == null)
                {
                    Console.WriteLine("!!! Null file by path " + filesPaths[i]);
                }

                filesInBytes.Add(file);
            }

            Console.WriteLine("Readed bytes of all files by paths");

            // Поместим всё содержимое в контейнер
            FilesContainer container = new FilesContainer();

            for (int i = 0; i < filesPaths.Length; i++)
            {
                if (!container.Add(filesPaths[i], filesInBytes[i]))
                {
                    Console.WriteLine("!!! Cannot add to dictionary file by path " + filesPaths[i]);
                }
            }

            Console.WriteLine("Files and paths addead to Dictionaty");

            // Провекрим, не произошло ли изменение ключей при добавлении
            string[] containerKeys = container.GetKeys();
            if (containerKeys.Length != filesPaths.Length)
            {
                Console.WriteLine("Keys were modified in adding - Length is not the same");
                return;
            }

            for (int i = 0; i < containerKeys.Length; i++)
            {
                if (containerKeys[i].Equals(filesPaths[i]))
                {
                    continue;
                }
                Console.WriteLine($"Keys were modified in adding - [{i}] --> {filesPaths[i]} != {containerKeys[i]}");
                return;
            }

            Console.WriteLine("Keys were not modified in adding");

            // Проверим, не произошло ли изменение файлов при добавлении
            List <byte[]> containerValues = new List <byte[]>();

            foreach (string key in containerKeys)
            {
                containerValues.Add(container.GetValueByKey(key));
            }

            if (containerValues.Count != filesInBytes.Count)
            {
                Console.WriteLine("Values were modified in adding - Length is not the same");
                return;
            }

            for (int i = 0; i < containerValues.Count; i++)
            {
                byte[] value1 = containerValues[i];
                byte[] value2 = filesInBytes[i];
                if (value1.Length != value2.Length)
                {
                    Console.WriteLine("Values were modified in adding - Length of file is not the same " +
                                      $"--> {i} by path {containerKeys[i]}; Len in container = {value1.Length}, len original = {value2.Length}");
                    return;
                }
                else
                {
                    for (int j = 0; j < value1.Length; j++)
                    {
                        if (value1[j] == value2[j])
                        {
                            continue;
                        }
                        Console.WriteLine("Values were modified in adding - bytes are different");
                        return;
                    }
                }
            }

            Console.WriteLine($"Values were not modified in adding");

            // Проверим на добавление дубликатов
            if (!container.Add(filesPaths[0], filesInBytes[0]))
            {
                Console.WriteLine("Dublicate key test is success");
            }
            else
            {
                Console.WriteLine("Dublicate key test is failder");
            }

            // Удаление из контейнера
            if (!container.Remove(filesPaths[0]))
            {
                Console.WriteLine("Deletion broked - do not see key");
                return;
            }
            if (container.Remove(filesPaths[0]))
            {
                Console.WriteLine("Deletion broked - see deleted key");
                return;
            }

            Console.WriteLine("Deletion is OK");
        }
示例#25
0
        public CustomItem(LabelOnGround item, FilesContainer fs, float distance, Dictionary <string, int> weightsRules)
        {
            LabelOnGround = item;
            Distance      = distance;
            var itemItemOnGround = item.ItemOnGround;
            var worldItem        = itemItemOnGround?.GetComponent <WorldItem>();

            if (worldItem == null)
            {
                return;
            }
            var groundItem = worldItem.ItemEntity;

            GroundItem = groundItem;
            Path       = groundItem?.Path;
            if (GroundItem == null)
            {
                return;
            }

            if (Path != null && Path.Length < 1)
            {
                DebugWindow.LogMsg($"World: {worldItem.Address:X} P: {Path}", 2);
                DebugWindow.LogMsg($"Ground: {GroundItem.Address:X} P {Path}", 2);
                return;
            }

            IsTargeted = () => itemItemOnGround?.GetComponent <Targetable>()?.isTargeted == true;

            var baseItemType = fs.BaseItemTypes.Translate(Path);

            if (baseItemType != null)
            {
                ClassName = baseItemType.ClassName;
                BaseName  = baseItemType.BaseName;
                Width     = baseItemType.Width;
                Height    = baseItemType.Height;
                if (weightsRules.TryGetValue(BaseName, out var w))
                {
                    Weight = w;
                }
                if (ClassName.StartsWith("Heist"))
                {
                    IsHeist = true;
                }
            }

            var WeaponClass = new List <string>
            {
                "One Hand Mace",
                "Two Hand Mace",
                "One Hand Axe",
                "Two Hand Axe",
                "One Hand Sword",
                "Two Hand Sword",
                "Thrusting One Hand Sword",
                "Bow",
                "Claw",
                "Dagger",
                "Rune Dagger",
                "Sceptre",
                "Staff",
                "Wand"
            };

            if (GroundItem.HasComponent <Quality>())
            {
                var quality = GroundItem.GetComponent <Quality>();
                Quality = quality.ItemQuality;
            }

            if (GroundItem.HasComponent <Base>())
            {
                var @base = GroundItem.GetComponent <Base>();
                IsElder    = @base.isElder;
                IsShaper   = @base.isShaper;
                IsHunter   = @base.isHunter;
                IsRedeemer = @base.isRedeemer;
                IsCrusader = @base.isCrusader;
                IsWarlord  = @base.isWarlord;
            }

            if (GroundItem.HasComponent <Mods>())
            {
                var mods = GroundItem.GetComponent <Mods>();
                Rarity       = mods.ItemRarity;
                IsIdentified = mods.Identified;
                ItemLevel    = mods.ItemLevel;
                IsFractured  = mods.HaveFractured;
                IsVeiled     = mods.ItemMods.Any(m => m.DisplayName.Contains("Veil"));
            }

            if (GroundItem.HasComponent <Sockets>())
            {
                var sockets = GroundItem.GetComponent <Sockets>();
                IsRGB       = sockets.IsRGB;
                Sockets     = sockets.NumberOfSockets;
                LargestLink = sockets.LargestLinkSize;
            }

            if (GroundItem.HasComponent <Weapon>())
            {
                IsWeapon = true;
            }

            MapTier = GroundItem.HasComponent <Map>() ? GroundItem.GetComponent <Map>().Tier : 0;
            IsValid = true;
        }
示例#26
0
 public FileMock(FilesContainer filesContainer)
 {
     NameWithExtension = "test.dat";
     _filesContainer   = filesContainer;
 }
 public void NullLoggerThrowsException()
 {
     FilesContainer filesContainer = new FilesContainer(null);
 }
示例#28
0
 public void ReloadFiles()
 {
     Files = new FilesContainer(pM);
 }
示例#29
0
 public DirectoryMock(string dir, FilesContainer filesContainer)
 {
     Name            = dir;
     _filesContainer = filesContainer;
 }
示例#30
0
 public FileMock(string fileName, FilesContainer filesContainer)
 {
     NameWithExtension = fileName;
     _filesContainer   = filesContainer;
 }