Exemple #1
0
        public void GetExistingDriveFreeSpaceTest()
        {
            var space = FreeSpaceHelper.GetDriveFreeSpace("C");

            Assert.NotNull(space);
            Assert.NotEqual(0, space.Value);
        }
Exemple #2
0
        private void Find(bool findNext)
        {
            FreeSpaceHelper.FreeSpaceByte = (byte)tbxFreeSpaceByte.Value;
            int startOffset = 0;

            if (!findNext)
            {
                startOffset = rbtnSearchFromBeginning.Checked ? 0 : (int)tbxOffset.Value;
            }
            else
            {
                startOffset = Convert.ToInt32(lbxResults.SelectedItem.ToString(), 16) +
                              (int)nudSkipInterval.Value;
            }

            int result = -1;

            try
            {
                result = FreeSpaceHelper.Search(GameManager.FileName, startOffset, (int)nudNeededBytes.Value);

                if (!findNext)
                {
                    Clear();
                }
            }
            catch (Exception ex)
            {
                ExceptionHandler.LogException(ex);
                ExceptionHandler.ShowMessage(ex);
                return;
            }

            if (result != -1)
            {
                if (!findNext)
                {
                    // enable find next, copy and clear
                    miFindNext.Enabled = true;
                    miCopy.Enabled     = true;
                    miClear.Enabled    = true;

                    btnFindNext.Enabled = true;
                    btnFindNext.Update();

                    btnCopy.Enabled = true;
                    btnCopy.Update();
                }

                // convert the result to hex
                string offset = result.ToString("X6");

                // check if the offset exists already
                if (!lbxResults.Items.Contains(offset))
                {
                    // add new item
                    lbxResults.Items.Add(offset);
                    lbxResults.SelectedIndex = lbxResults.Items.Count - 1;
                }
                else
                {
                    // select the existing item
                    lbxResults.SelectedItem = offset;
                }
            }
            else
            {
                // not enough free space found
                MessageBoxHelper.Show(this, Localization.GetString(this.Name + ".Find.CantFindEnoughSpace") +
                                      "\n\n" + Localization.GetString(this.Name + ".Find.TryDifferentOffset"),
                                      MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemple #3
0
        public void GetNonExistingDriveFreeSpaceTest()
        {
            var space = FreeSpaceHelper.GetDriveFreeSpace("-");

            Assert.Null(space);
        }