Пример #1
0
        public void FixCaseWasDuplicatingLines()
        {
            const string oldFile = @"Attribute VB_Name = ""Module1""
Option Explicit


Sub StubbedOuttes()
    MsgBox ""Hello, world!""
End Sub

Sub StubbedOuttes2()

    MsgBox ""Hello, world!""
End Sub
";

            const string newFile = @"Attribute VB_Name = ""Module1""
Option Explicit

Sub tes()
    MsgBox ""Hello, world!""
End Sub

Sub tes2()
    MsgBox ""Hello, world!""
End Sub
";

            Assert.AreEqual(newFile, ModuleProcessing.FixCase(oldFile, newFile));
        }
Пример #2
0
        public void StubOutBasic()
        {
            var sb = new StringBuilder();

            sb.Append("VERSION 1.0 CLASS\r\n");
            sb.Append("BEGIN\r\n");
            sb.Append("  MultiUse = -1  'True\r\n");
            sb.Append("END\r\n");
            sb.Append("Attribute VB_Name = \"ThisWorkbook\"\r\n");
            sb.Append("Attribute VB_Base = \"0{00020819-0000-0000-C000-000000000046}\"\r\n");
            sb.Append("Attribute VB_GlobalNameSpace = False\r\n");
            sb.Append("Attribute VB_Creatable = False\r\n");
            sb.Append("Attribute VB_PredeclaredId = True\r\n");
            sb.Append("Attribute VB_Exposed = True\r\n");
            sb.Append("Attribute VB_TemplateDerived = False\r\n");
            sb.Append("Attribute VB_Customizable = True\r\n");
            var expected = sb.ToString();

            sb.Append("Option Explicit\r\n\r\n");
            sb.Append("Private Sub Workbook_Open()\r\n");
            sb.Append("    MsgBox \"Hello World!\"\r\n");
            sb.Append("End Sub\r\n");
            Assert.That(ModuleProcessing.StubOut(sb.ToString()), Is.EqualTo(expected));
        }
Пример #3
0
        public void FixCaseBasic()
        {
            const string oldFile    = @"VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = ""ThisWorkbook""
Attribute VB_Base = ""0{00020819-0000-0000-C000-000000000046}""
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = True
Attribute VB_TemplateDerived = False
Attribute VB_Customizable = True
Option Explicit

' hello world!
Sub tes()
    Dim HelloWorld$
    HelloWorld = ""Hello, world!""
    MsgBox HelloWorld
End Sub
Sub tes2()
    MsgBox 2 + 2
End Sub
Sub tes3()
    MsgBox ""Hello, world!""
End Sub
";
            const string newFileRaw = @"VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = ""ThisWorkbook""
Attribute VB_Base = ""0{00020819-0000-0000-C000-000000000046}""
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = True
Attribute VB_TemplateDerived = False
Attribute VB_Customizable = True
Option Explicit

' Hello world!
Sub Tes()
    Dim helloworld$
    helloworld = ""Hello, World!""
    MsgBox helloworld
End Sub

Sub Tes2()
    MsgBox 2 + 3
End Sub

Sub Tes3()
    MsgBox ""Hello, world!""
End Sub
";
            const string newFileFix = @"VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = ""ThisWorkbook""
Attribute VB_Base = ""0{00020819-0000-0000-C000-000000000046}""
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = True
Attribute VB_TemplateDerived = False
Attribute VB_Customizable = True
Option Explicit

' Hello world!
Sub tes()
    Dim HelloWorld$
    helloworld = ""Hello, World!""
    MsgBox HelloWorld
End Sub

Sub tes2()
    MsgBox 2 + 3
End Sub

Sub tes3()
    MsgBox ""Hello, world!""
End Sub
";

            Assert.AreEqual(newFileFix, ModuleProcessing.FixCase(oldFile, newFileRaw));
        }
Пример #4
0
        private void ApplyButton_Click(object sender, RoutedEventArgs e)
        {
            var vm = ChangesGrid.DataContext as ChangesViewModel;

            if (vm == null)
            {
                return;
            }
            if (Session.Action == ActionType.Extract)
            {
                foreach (var p in vm.Where(p => p.Commit).ToArray())
                {
                    var fileName = p.ModuleName + ModuleProcessing.ExtensionFromType(p.ModuleType);
                    switch (p.ChangeType)
                    {
                    case ChangeType.DeleteFile:
                        File.Delete(Path.Combine(Session.FolderPath, fileName));
                        if (p.ModuleType == ModuleType.Form)
                        {
                            File.Delete(Path.Combine(Session.FolderPath, p.ModuleName + ".frx"));
                        }
                        break;

                    case ChangeType.ChangeFormControls:
                        File.Copy(Path.Combine(_evf.FolderPath, p.ModuleName + ".frx"), Path.Combine(Session.FolderPath, p.ModuleName + ".frx"), true);
                        break;

                    default:
                        File.Copy(Path.Combine(_evf.FolderPath, fileName), Path.Combine(Session.FolderPath, fileName), true);
                        if (p.ChangeType == ChangeType.AddFile && p.ModuleType == ModuleType.Form)
                        {
                            File.Copy(Path.Combine(_evf.FolderPath, p.ModuleName + ".frx"), Path.Combine(Session.FolderPath, p.ModuleName + ".frx"), true);
                        }
                        break;
                    }
                    vm.Remove(p);
                }
            }
            else
            {
                foreach (var p in vm.Where(p => p.Commit).ToArray())
                {
                    var fileName = p.ModuleName + ModuleProcessing.ExtensionFromType(p.ModuleType);
                    switch (p.ChangeType)
                    {
                    case ChangeType.DeleteFile:
                        File.Delete(Path.Combine(_evf.FolderPath, fileName));
                        if (p.ModuleType == ModuleType.Form)
                        {
                            File.Delete(Path.Combine(_evf.FolderPath, p.ModuleName + ".frx"));
                        }
                        break;

                    case ChangeType.ChangeFormControls:
                        File.Copy(Path.Combine(Session.FolderPath, p.ModuleName + ".frx"), Path.Combine(_evf.FolderPath, p.ModuleName + ".frx"), true);
                        break;

                    default:
                        File.Copy(Path.Combine(Session.FolderPath, fileName), Path.Combine(_evf.FolderPath, fileName), true);
                        if (p.ChangeType == ChangeType.AddFile && p.ModuleType == ModuleType.Form)
                        {
                            File.Copy(Path.Combine(Session.FolderPath, p.ModuleName + ".frx"), Path.Combine(_evf.FolderPath, p.ModuleName + ".frx"), true);
                        }
                        break;
                    }
                    vm.Remove(p);
                }
                _evf.Write(Session.FilePath);
            }
            UpdateIncludeAllBox();
        }
Пример #5
0
        private void ChangesGrid_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            var    sel      = (Patch)ChangesGrid.SelectedItem;
            var    fileName = sel.ModuleName + (sel.ChangeType != ChangeType.ChangeFormControls ? ModuleProcessing.ExtensionFromType(sel.ModuleType) : ".frx");
            string oldPath;
            string newPath;

            if (Session.Action == ActionType.Extract)
            {
                oldPath = Path.Combine(Session.FolderPath, fileName);
                newPath = Path.Combine(_evf.FolderPath, fileName);
            }
            else
            {
                oldPath = Path.Combine(_evf.FolderPath, fileName);
                newPath = Path.Combine(Session.FolderPath, fileName);
            }
            if (sel.ChangeType == ChangeType.ChangeFormControls)
            {
                Lib.FrxFilesAreDifferent(oldPath, newPath, out var explain);
                MessageBox.Show(explain, "FRX file difference", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            else
            {
                var diffExePath = Environment.ExpandEnvironmentVariables(Session.DiffTool);
                if (!File.Exists(oldPath) || !File.Exists(newPath) || !File.Exists(diffExePath))
                {
                    return;
                }
                var p = new Process {
                    StartInfo = new ProcessStartInfo(diffExePath, Session.DiffToolParameters.Replace("{OldFile}", oldPath).Replace("{NewFile}", newPath))
                    {
                        UseShellExecute = false
                    }
                };
                p.Start();
            }
        }