Initial import

This commit is contained in:
mlemanczyk committed 2012-09-24 20:55:07 +02:00
1 parent ea3f8549e4
commit fa6feafba7
133 files changed
+17503 -4

No files matched your search

@@ -0,0 +1,241 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{5C84FFF1-2B72-440F-A36D-7D411CF7AE61}</ProjectGuid>
<OutputType>WinExe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>DelphiProjectHandler</RootNamespace>
<AssemblyName>DelphiProjectHandler</AssemblyName>
<FileUpgradeFlags>
</FileUpgradeFlags>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<OldToolsVersion>3.5</OldToolsVersion>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data" />
<Reference Include="System.Data.DataSetExtensions">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Deployment" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="src\Controller\FixProjectSettingsController.cs" />
<Compile Include="src\Controller\FixUnitActionsController.cs" />
<Compile Include="src\Controller\FixUnitSettingsController.cs" />
<Compile Include="src\Controller\IFixProjectSettingsController.cs" />
<Compile Include="src\Controller\IFixProjectActionsController.cs" />
<Compile Include="src\Controller\FixProjectActionsController.cs" />
<Compile Include="src\Controller\IFixUnitActionsController.cs" />
<Compile Include="src\Controller\IFixUnitSettingsController.cs" />
<Compile Include="src\Controller\IProjectBulkOperationController.cs" />
<Compile Include="src\Controller\IUnitCleanupActionsController.cs" />
<Compile Include="src\Controller\ILibraryPathSettingsController.cs" />
<Compile Include="src\Controller\IUnitCleanupSettingsController.cs" />
<Compile Include="src\Controller\LibraryPathSettingsController.cs" />
<Compile Include="src\Controller\ProjectBulkOperationController.cs" />
<Compile Include="src\Controller\UnitCleanupActionsController.cs" />
<Compile Include="src\Controller\UnitCleanupSettingsController.cs" />
<Compile Include="src\Dialogs\FileSelectors\Specialized\DprFilesSelector.cs" />
<Compile Include="src\Dialogs\FileSelectors\Specialized\XmlFileSelector.cs" />
<Compile Include="src\IcarusAnalyzerReportParser.cs" />
<Compile Include="src\Model\ProjectBulkOperations.cs" />
<Compile Include="src\Model\FixProjectSettings.cs" />
<Compile Include="src\Model\FixUnitSettings.cs" />
<Compile Include="src\Model\IFixProjectSettings.cs" />
<Compile Include="src\Model\IFixUnitSettings.cs" />
<Compile Include="src\Model\ILibraryPathSettings.cs" />
<Compile Include="src\Model\IUnitCleanupSettings.cs" />
<Compile Include="src\Model\LibraryPathSettings.cs" />
<Compile Include="src\Model\UnitCleanupSettings.cs" />
<Compile Include="src\Operations\ProjectBulkOperationLoader.cs" />
<Compile Include="src\Operations\DelphiFileAgent.cs" />
<Compile Include="src\Operations\IDelphiFileAgent.cs" />
<Compile Include="src\Operations\IDelphiFileOperation.cs" />
<Compile Include="src\Operations\IOperationState.cs" />
<Compile Include="src\Operations\IUnitItemBuilder.cs" />
<Compile Include="src\Operations\Projects\AbstractDelphiProjectOperation.cs" />
<Compile Include="src\Operations\Projects\IProjectOperationSettings.cs" />
<Compile Include="src\Operations\Projects\IProjectOperationState.cs" />
<Compile Include="src\Operations\Projects\ProjectOperationSettings.cs" />
<Compile Include="src\Operations\Projects\ProjectOperationState.cs" />
<Compile Include="src\Operations\Projects\ProjectUnitItemBuilder.cs" />
<Compile Include="src\Operations\Units\AbstractDelphiUnitOperation.cs" />
<Compile Include="src\Operations\Units\DelphiUnitAddOperation.cs" />
<Compile Include="src\Operations\Units\DelphiUnitCleanerOperation.cs" />
<Compile Include="src\Operations\Units\DelphiUnitItemBuilder.cs" />
<Compile Include="src\Operations\Units\DelphiUnitOperationSettings.cs" />
<Compile Include="src\Operations\Units\DelphiUnitOperationState.cs" />
<Compile Include="src\Operations\Units\DelphiUnitUsesOperation.cs" />
<Compile Include="src\Operations\Units\IDelphiUnitOperation.cs" />
<Compile Include="src\Operations\DelphiUnitAgent.cs" />
<Compile Include="src\Operations\FileModifierAgent.cs" />
<Compile Include="src\Operations\Units\IDelphiUnitOperationSettings.cs" />
<Compile Include="src\Operations\Units\IDelphiUnitOperationState.cs" />
<Compile Include="src\Operations\Uses\AbstractUsesListOperation.cs" />
<Compile Include="src\Operations\Uses\IUsesListOperation.cs" />
<Compile Include="src\Operations\Uses\IUsesListOperationSettings.cs" />
<Compile Include="src\Operations\Uses\IUsesListOperationState.cs" />
<Compile Include="src\Operations\Uses\UsesListAddOperation.cs" />
<Compile Include="src\Operations\Uses\UsesListDeleteOperation.cs" />
<Compile Include="src\Operations\Uses\UsesListFixFormOperation.cs" />
<Compile Include="src\Operations\Uses\UsesListFixPathOperation.cs" />
<Compile Include="src\Operations\Uses\UsesListOperationSettings.cs" />
<Compile Include="src\Operations\Uses\UsesListOperationState.cs" />
<Compile Include="src\SuggestedUnitStructure.cs" />
<Compile Include="src\UnitStructure.cs" />
<Compile Include="src\SuggestedUnitStructureList.cs" />
<Compile Include="src\Dialogs\FileSelectors\FilesSelector.cs" />
<Compile Include="src\Dialogs\FileSelectors\FilesSelectorOptions.cs" />
<Compile Include="src\Dialogs\FileSelectors\FolderFilesImporter.cs" />
<Compile Include="src\Dialogs\FileSelectors\IFilesSelector.cs" />
<Compile Include="src\Dialogs\FileSelectors\IFolderFilesImporter.cs" />
<Compile Include="src\Utils\ICollectionUtils.cs" />
<Compile Include="src\Utils\ListUtils.cs" />
<Compile Include="src\Dialogs\FileSelectors\Specialized\PasFilesSelector.cs" />
<Compile Include="src\Utils\PathUtilsClass.cs" />
<Compile Include="src\Utils\StringListUtils.cs" />
<Compile Include="src\LibraryPaths\ClipboardLibraryPathsProvider.cs" />
<Compile Include="src\LibraryPaths\DelphiLibraryPathsProvider.cs" />
<Compile Include="src\LibraryPaths\DelphiLibraryPathsBuilder.cs" />
<Compile Include="src\LibraryPaths\DelphiRegistryKeys.cs" />
<Compile Include="src\LibraryPaths\LibraryPathsProviderFactory.cs" />
<Compile Include="src\LibraryPaths\LibraryPathsBuilderInterface.cs" />
<Compile Include="src\LibraryPaths\LibraryPathsProviderInterface.cs" />
<Compile Include="src\Operations\Projects\DelphiProjectFixFormsOperation.cs" />
<Compile Include="src\Operations\Projects\DelphiProjectFixPathsOperation.cs" />
<Compile Include="src\Operations\DelphiOperation.cs" />
<Compile Include="src\Operations\Projects\DelphiProjectRemoveUnitsOperation.cs" />
<Compile Include="src\Utils\TextBoxUtils.cs" />
<Compile Include="src\View\FormDelphiProjectManager.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="src\View\FormDelphiProjectManager.Designer.cs">
<DependentUpon>FormDelphiProjectManager.cs</DependentUpon>
</Compile>
<Compile Include="src\Operations\Projects\DelphiProjectAddUnitOperation.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="src\View\IFixProjectSettingsView.cs" />
<Compile Include="src\View\IFixUnitSettingsView.cs" />
<Compile Include="src\View\ILibraryPathSettingsView.cs" />
<Compile Include="src\View\IUnitCleanupSettingsView.cs" />
<EmbeddedResource Include="src\View\FormDelphiProjectManager.resx">
<SubType>Designer</SubType>
<DependentUpon>FormDelphiProjectManager.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</EmbeddedResource>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<Compile Include="src\Utils\RelativePathClass.cs" />
<Compile Include="src\SourceControl\SourceOffsiteClass.cs" />
<Compile Include="src\UnitFormReaderClass.cs" />
<Compile Include="src\UnitListClass.cs" />
<Compile Include="src\UsesClauseReaderClass.cs" />
<Compile Include="src\UnitItemClass.cs" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.2.0">
<Visible>False</Visible>
<ProductName>.NET Framework 2.0 %28x86%29</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.0">
<Visible>False</Visible>
<ProductName>.NET Framework 3.0 %28x86%29</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
<Visible>False</Visible>
<ProductName>Windows Installer 3.1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
+22
View File
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using DelphiProjectHandler.View;
namespace DelphiProjectHandler
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new FormDelphiProjectManager());
}
}
}
@@ -0,0 +1,33 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("DelphiProjectHandler")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("ProfiMile Lemańczyk sp. j.")]
[assembly: AssemblyProduct("DelphiProjectHandler")]
[assembly: AssemblyCopyright("Copyright © ProfiMile Lemańczyk sp. j. 2006")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("664d3bb0-413b-43a3-a175-26af528fb88b")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
+63
View File
@@ -0,0 +1,63 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.1
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace DelphiProjectHandler.Properties {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("DelphiProjectHandler.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
}
}
@@ -0,0 +1,117 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
+26
View File
@@ -0,0 +1,26 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.1
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace DelphiProjectHandler.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default {
get {
return defaultInstance;
}
}
}
}
@@ -0,0 +1,7 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
<Profiles>
<Profile Name="(Default)" />
</Profiles>
<Settings />
</SettingsFile>
@@ -0,0 +1,81 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DelphiProjectHandler.Model;
using DelphiProjectHandler.Operations;
using DelphiProjectHandler.Operations.Projects;
namespace DelphiProjectHandler.Controller
{
public class FixProjectActionsController: IFixProjectActionsController
{
#region Private
private IFixProjectSettings fModel;
private IDelphiFileAgent fDelphiFileAgent;
#endregion
#region Protected
protected void ExecuteOperation(IDelphiFileOperation aOperation)
{
foreach (string vProjectName in Model.Projects)
{
if (vProjectName == "")
continue;
fDelphiFileAgent.Execute(vProjectName, aOperation);
}
}
#endregion
#region Public
public FixProjectActionsController()
{
fDelphiFileAgent = new DelphiFileAgent();
}
#endregion
#region IProjectManipulator Implementation
public void AddUnits()
{
IDelphiFileOperation vOperation = new DelphiProjectAddUnitOperation(Model.UnitConstraints, Model.UnitsToManipulate, Model.AddUnitPathsToDPRs);
ExecuteOperation(vOperation);
}
public void RemoveUnits()
{
IDelphiFileOperation vOperation = new DelphiProjectRemoveUnitOperation(Model.UnitConstraints, Model.UnitsToManipulate, Model.AddUnitPathsToDPRs);
ExecuteOperation(vOperation);
}
public void FixPaths()
{
IDelphiFileOperation vOperation = new DelphiProjectFixPathsOperation(Model.UnitConstraints, Model.UnitsToManipulate, Model.AddUnitPathsToDPRs);
ExecuteOperation(vOperation);
}
public void FixForms()
{
IDelphiFileOperation vOperation = new DelphiProjectFixFormsOperation(Model.UnitConstraints, Model.UnitsToManipulate, Model.AddUnitPathsToDPRs);
ExecuteOperation(vOperation);
}
public IFixProjectSettings Model
{
get { return fModel; }
set
{
if (value == null)
throw new ArgumentNullException("Model");
fModel = value;
}
}
#endregion
}
}
@@ -0,0 +1,144 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DelphiProjectHandler.Model;
using DelphiProjectHandler.Dialogs.FileSelectors;
using DelphiProjectHandler.Dialogs.FileSelectors.Specialized;
using DelphiProjectHandler.Utils;
namespace DelphiProjectHandler.Controller
{
public class FixProjectSettingsController: IFixProjectSettingsController
{
#region Private
private IFixProjectSettings fModel;
private IFilesSelector fDprFilesSelector;
private IFilesSelector fPasFilesSelector;
#endregion
#region Protected
protected IFilesSelector CreatePasFilesSelector()
{
return new PasFilesSelector(new FilesSelector());
}
protected IFilesSelector CreateDprFilesSelector()
{
return new DprFilesSelector(new FilesSelector());
}
protected void ImportFiles(string aDescription, string aFileMask, ICollection<string> aList)
{
ValidateModel();
IFolderFilesImporter vImporter = new FolderFilesImporter();
aList.Add(vImporter.SelectFiles(aDescription, aFileMask));
Model.NotifyObservers();
}
protected void SelectFiles(IFilesSelector aFilesSelector, ICollection<string> aList)
{
ValidateModel();
aList.Add(aFilesSelector.SelectFiles());
Model.NotifyObservers();
}
protected void SetFiles(ICollection<string> aNewFiles, IList<string> aDestList)
{
ValidateModel();
aDestList.Clear();
aDestList.Add(aNewFiles);
Model.NotifyObservers();
}
protected void ValidateModel()
{
if (Model == null)
throw new ArgumentNullException("Model", "Model is not assigned to the controller");
}
protected IFilesSelector DprFilesSelector
{
get { return fDprFilesSelector; }
}
protected IFilesSelector PasFilesSelector
{
get { return fPasFilesSelector; }
}
#endregion
#region Public
public FixProjectSettingsController(): base()
{
fDprFilesSelector = CreateDprFilesSelector();
fPasFilesSelector = CreatePasFilesSelector();
}
#endregion
#region IFixProjectSettingsController Members
public void ImportProjects()
{
ImportFiles("Select any folder containing your projects. Subfolders are automatically included.", "*.dpr", Model.Projects);
}
public void ImportUnits()
{
ImportFiles("Select any folder containing your units. Subfolders are automatically included.", "*.pas", Model.UnitsToManipulate);
}
public void SelectProjects()
{
SelectFiles(DprFilesSelector, Model.Projects);
}
public void SelectUnits()
{
SelectFiles(PasFilesSelector, Model.UnitsToManipulate);
}
public void SwitchAddUnitPathsToDPRs()
{
ValidateModel();
Model.AddUnitPathsToDPRs = !Model.AddUnitPathsToDPRs;
Model.NotifyObservers();
}
public void SetProjects(ICollection<string> aProjects)
{
SetFiles(aProjects, Model.Projects);
}
public void SetUnitConstraints(ICollection<string> aConstraints)
{
SetFiles(aConstraints, Model.UnitConstraints);
}
public void SetUnitsToManipulate(ICollection<string> aUnits)
{
SetFiles(aUnits, Model.UnitsToManipulate);
}
public IFixProjectSettings Model
{
get
{
return fModel;
}
set
{
if (value == null)
throw new ArgumentNullException("Model");
fModel = value;
}
}
#endregion
}
}
@@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DelphiProjectHandler.Model;
using DelphiProjectHandler.Operations;
using DelphiProjectHandler.Operations.Units;
namespace DelphiProjectHandler.Controller
{
public class FixUnitActionsController: IFixUnitActionsController
{
#region Private
private IFixUnitSettings fModel;
#endregion
#region IFixUnitActionsController Members
public void AddUnits()
{
IDelphiFileOperation vOperation = new DelphiUnitAddOperation(Model.InterfaceUnits, Model.ImplementationUnits, Model.UnitConstraints);
IDelphiFileAgent vAgent = new DelphiFileAgent();
foreach (string vUnitFilename in Model.UnitsToModify)
vAgent.Execute(vUnitFilename, vOperation);
}
public void RemoveUnits()
{
throw new NotImplementedException();
}
public Model.IFixUnitSettings Model
{
get { return fModel; }
set {
if (value == null)
throw new ArgumentNullException("Model");
fModel = value;
}
}
#endregion
}
}
@@ -0,0 +1,140 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DelphiProjectHandler.Dialogs.FileSelectors;
using DelphiProjectHandler.Dialogs.FileSelectors.Specialized;
using DelphiProjectHandler.Model;
using DelphiProjectHandler.Utils;
namespace DelphiProjectHandler.Controller
{
public class FixUnitSettingsController: IFixUnitSettingsController
{
#region Private
private IFixUnitSettings fModel;
private IFilesSelector fPasFilesSelector;
#endregion
#region Protected
protected IFilesSelector PasFilesSelector
{
get { return fPasFilesSelector; }
}
private IFilesSelector CreatePasFilesSelector()
{
return new PasFilesSelector(new FilesSelector());
}
protected void ImportFiles(string aDescription, string aFileMask, ICollection<string> aDestinationList)
{
ValidateModel();
IFolderFilesImporter vImporter = new FolderFilesImporter();
aDestinationList.Add(vImporter.SelectFiles(aDescription, aFileMask));
Model.NotifyObservers();
}
protected void SelectFiles(IList<string> aDestList)
{
ValidateModel();
aDestList.Add(PasFilesSelector.SelectFiles());
Model.NotifyObservers();
}
protected void SetFiles(ICollection<string> aNewFiles, IList<string> aDestList)
{
ValidateModel();
aDestList.Clear();
aDestList.Add(aNewFiles);
Model.NotifyObservers();
}
protected void ValidateModel()
{
if (Model == null)
throw new ArgumentNullException("Model", "Model is not assigned to the controller");
}
#endregion
#region Public
public FixUnitSettingsController()
: base()
{
fPasFilesSelector = CreatePasFilesSelector();
}
#endregion
#region IFixUnitSettingsController Members
public void ImportUnitsToModify()
{
ImportFiles("Select a folder to import Delphi units from. Subfolders are automatically included.", "*.pas", Model.UnitsToModify);
}
public void SelectUnitsToModify()
{
SelectFiles(Model.UnitsToModify);
}
public void ImportInterfaceUnits()
{
ImportFiles("Select a folder to import Delphi units from. Subfolders are automatically included.", "*.pas", Model.InterfaceUnits);
}
public void SelectInterfaceUnits()
{
SelectFiles(Model.InterfaceUnits);
}
public void ImportImplementationUnits()
{
ImportFiles("Select a folder to import Delphi units from. Subfolders are automatically included.", "*.pas", Model.ImplementationUnits);
}
public void SelectImplementationUnits()
{
SelectFiles(Model.ImplementationUnits);
}
public void SetUnitsToModify(ICollection<string> aUnits)
{
SetFiles(aUnits, Model.UnitsToModify);
}
public void SetInterfaceUnits(ICollection<string> aUnits)
{
SetFiles(aUnits, Model.InterfaceUnits);
}
public void SetImplementationUnits(ICollection<string> aUnits)
{
SetFiles(aUnits, Model.ImplementationUnits);
}
public void SetUnitConstraints(ICollection<string> aConstraints)
{
SetFiles(aConstraints, Model.UnitConstraints);
}
public Model.IFixUnitSettings Model
{
get
{
return fModel;
}
set
{
if (value == null)
throw new ArgumentNullException("Model");
fModel = value;
}
}
#endregion
}
}
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DelphiProjectHandler.Model;
namespace DelphiProjectHandler.Controller
{
public interface IFixProjectActionsController
{
void AddUnits();
void RemoveUnits();
void FixPaths();
void FixForms();
IFixProjectSettings Model { get; set; }
}
}
@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DelphiProjectHandler.Model;
namespace DelphiProjectHandler.Controller
{
public interface IFixProjectSettingsController
{
void ImportProjects();
void SelectProjects();
void SelectUnits();
void ImportUnits();
void SwitchAddUnitPathsToDPRs();
void SetProjects(ICollection<string> aProjects);
void SetUnitsToManipulate(ICollection<string> aUnits);
void SetUnitConstraints(ICollection<string> aConstraints);
IFixProjectSettings Model { get; set; }
}
}
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DelphiProjectHandler.Model;
namespace DelphiProjectHandler.Controller
{
public interface IFixUnitActionsController
{
void AddUnits();
void RemoveUnits();
IFixUnitSettings Model { get; set; }
}
}
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DelphiProjectHandler.Model;
namespace DelphiProjectHandler.Controller
{
public interface IFixUnitSettingsController
{
void ImportUnitsToModify();
void SelectUnitsToModify();
void ImportInterfaceUnits();
void SelectInterfaceUnits();
void ImportImplementationUnits();
void SelectImplementationUnits();
void SetUnitsToModify(ICollection<string> aUnits);
void SetInterfaceUnits(ICollection<string> aUnits);
void SetImplementationUnits(ICollection<string> aUnits);
void SetUnitConstraints(ICollection<string> aConstraints);
IFixUnitSettings Model { get; set; }
}
}
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DelphiProjectHandler.LibraryPaths;
using DelphiProjectHandler.Model;
namespace DelphiProjectHandler.Controller
{
public interface ILibraryPathSettingsController
{
void LoadPreset(LibraryPathType aType);
void NormalizePaths();
void SetLibraryPaths(ICollection<string> aLibraryPaths);
ILibraryPathSettings Model { get; set; }
}
}
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DelphiProjectHandler.Controller
{
public interface IProjectBulkOperationController
{
bool ProcessFile();
bool SelectFile();
}
}
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DelphiProjectHandler.Model;
namespace DelphiProjectHandler.Controller
{
public interface IUnitCleanupActionsController
{
void RemoveUnusedUnits();
IUnitCleanupSettings Model { get; set; }
}
}
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DelphiProjectHandler.Model;
namespace DelphiProjectHandler.Controller
{
public interface IUnitCleanupSettingsController
{
void LoadFromLibraryPaths(ICollection<string> aLibraryPaths);
void PasteIcarusReport();
void SetIcarusReport(string aReport);
void SetIgnoredUnits(ICollection<string> aUnits);
void SetUnitsToClean(ICollection<string> aUnits);
IUnitCleanupSettings Model { get; set; }
}
}
@@ -0,0 +1,69 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DelphiProjectHandler.Model;
using DelphiProjectHandler.LibraryPaths;
using DelphiProjectHandler.Dialogs;
namespace DelphiProjectHandler.Controller
{
public class LibraryPathSettingsController: ILibraryPathSettingsController
{
#region (Private)
private ILibraryPathSettings fModel;
#endregion
#region (Protected)
protected void ValidateModel()
{
if (Model == null)
throw new ArgumentNullException("Model", "Model is not assigned to the controller");
}
#endregion
#region (ILibraryPathSettingsController Implementation)
public void LoadPreset(LibraryPathType aType)
{
ValidateModel();
ILibraryPathsProvider vProvider = LibraryPathsProviderFactory.CreateProvider(aType);
Model.LibraryPaths = vProvider.List();
Model.NotifyObservers();
}
public void NormalizePaths()
{
ValidateModel();
Model.LibraryPaths = PathUtils.Normalize(Model.LibraryPaths);
Model.NotifyObservers();
}
public void SetLibraryPaths(ICollection<string> aLibraryPaths)
{
ValidateModel();
Model.LibraryPaths = new List<string>(aLibraryPaths);
Model.NotifyObservers();
}
public ILibraryPathSettings Model
{
get
{
return fModel;
}
set
{
if (value == null)
throw new ArgumentNullException("Model");
fModel = value;
}
}
#endregion
}
}
@@ -0,0 +1,63 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DelphiProjectHandler.Operations;
using DelphiProjectHandler.Model;
using System.IO;
using DelphiProjectHandler.Dialogs.FileSelectors.Specialized;
using DelphiProjectHandler.Dialogs.FileSelectors;
namespace DelphiProjectHandler.Controller
{
public class ProjectBulkOperationController: IProjectBulkOperationController
{
protected XmlFileSelector Selector { get; private set; }
protected string FileName { get; private set; }
private static FixProjectActionsController CreateController(string aProjectName, IList<string> aUnits)
{
FixProjectActionsController vController = new FixProjectActionsController();
vController.Model = new FixProjectSettings();
vController.Model.Projects.Add(aProjectName);
vController.Model.UnitsToManipulate = aUnits;
return vController;
}
public bool ProcessFile()
{
ProjectBulkOperations vProjects = ProjectBulkOperationLoader.FromStream(new FileStream(FileName, FileMode.Open));
foreach (ProjectBulkOperation vProject in vProjects)
{
if (vProject.Remove.Count > 0)
{
FixProjectActionsController vController = CreateController(vProject.ProjectName, vProject.Remove);
vController.RemoveUnits();
}
if (vProject.Add.Count > 0)
{
FixProjectActionsController vController = CreateController(vProject.ProjectName, vProject.Add);
vController.AddUnits();
}
}
return true;
}
public ProjectBulkOperationController()
{
Selector = new XmlFileSelector(new FilesSelector());
FileName = "";
}
public bool SelectFile()
{
ICollection<string> vFiles = Selector.SelectFiles();
if (vFiles.Count == 0)
return false;
FileName = vFiles.ElementAt(0);
return true;
}
}
}
@@ -0,0 +1,69 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DelphiProjectHandler.Model;
using System.IO;
using DelphiProjectHandler.Operations;
namespace DelphiProjectHandler.Controller
{
public class UnitCleanupActionsController: IUnitCleanupActionsController
{
#region (Private)
private IUnitCleanupSettings fModel;
#endregion
#region (IUnitCleanupActionsController Implementation)
public void RemoveUnusedUnits()
{
SuggestedUnitStructureList vSuggestedStructures = IcarusAnalyzerReportParser.Parse(Model.IcarusReport);
StringBuilder vLog = new StringBuilder();
foreach (string vUnitFileName in Model.UnitsToClean)
{
if (vUnitFileName.Equals(""))
continue;
string vUnitName = Path.GetFileNameWithoutExtension(vUnitFileName).ToLower();
if (
!vSuggestedStructures.ContainsKey(vUnitName) ||
(vSuggestedStructures[vUnitName].MoveToInterface.Count == 0) &&
(vSuggestedStructures[vUnitName].ToDelete.Count == 0)
)
{
continue;
}
vLog.Append("Processing unit " + vUnitName + "\r\n");
DelphiUnitAgent vAgent = new DelphiUnitAgent(vUnitFileName);
vAgent.CleanupUnits(vSuggestedStructures[vUnitName], Model.IgnoredUnits);
if (vAgent.Modified)
{
vLog.Append("Saving changes in unit " + vUnitName + "\r\n");
vAgent.Save(vUnitFileName);
}
}
Model.IcarusReport = vLog.ToString();
Model.NotifyObservers();
}
public IUnitCleanupSettings Model
{
get
{
return fModel;
}
set
{
if (value == null)
throw new ArgumentNullException("Model");
fModel = value;
}
}
#endregion
}
}
@@ -0,0 +1,82 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DelphiProjectHandler.Model;
using System.IO;
using System.Windows.Forms;
namespace DelphiProjectHandler.Controller
{
public class UnitCleanupSettingsController: IUnitCleanupSettingsController
{
#region (Private)
private IUnitCleanupSettings fModel;
#endregion
#region (IUnitCleanupSettingsController Implementation)
public void LoadFromLibraryPaths(ICollection<string> aLibraryPaths)
{
List<string> vCompleteUnitList = new List<string>();
foreach (string vPath in aLibraryPaths)
{
if (vPath.Equals(""))
continue;
try
{
IList<string> vUnits = Directory.GetFiles(vPath, "*.pas", SearchOption.TopDirectoryOnly);
vCompleteUnitList.AddRange(vUnits);
}
catch (Exception iError)
{
throw new IOException("Error occurred when processing path: " + vPath + ". " + iError.Message);
}
}
Model.UnitsToClean = vCompleteUnitList;
Model.NotifyObservers();
}
public void PasteIcarusReport()
{
Model.IcarusReport = Clipboard.GetText();
Model.NotifyObservers();
}
public void SetIcarusReport(string aReport)
{
Model.IcarusReport = aReport;
Model.NotifyObservers();
}
public void SetIgnoredUnits(ICollection<string> aUnits)
{
Model.IgnoredUnits = new List<string>(aUnits);
Model.NotifyObservers();
}
public void SetUnitsToClean(ICollection<string> aUnits)
{
Model.UnitsToClean = new List<string>(aUnits);
Model.NotifyObservers();
}
public IUnitCleanupSettings Model
{
get
{
return fModel;
}
set
{
if (value == null)
throw new ArgumentNullException("Model");
fModel = value;
}
}
#endregion
}
}
@@ -0,0 +1,67 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace DelphiProjectHandler.Dialogs.FileSelectors
{
public class FilesSelector: IFilesSelector
{
#region Private
private IFilesSelectorOptions fDefaultOptions;
#endregion
#region Protected
protected IFilesSelectorOptions CreateDefaultOptions()
{
IFilesSelectorOptions vOptions = new FilesSelectorOptions();
vOptions.Filter = "Pas files|*.pas|All files|*.*";
vOptions.DefaultExt = "pas";
vOptions.MultiSelect = true;
vOptions.Title = "Select one or more units to add";
return vOptions;
}
#endregion
#region Public
public FilesSelector()
: base()
{
fDefaultOptions = CreateDefaultOptions();
}
#endregion
#region IFilesSelctor Implementation
public IFilesSelectorOptions DefaultOptions
{
get { return fDefaultOptions; }
}
public ICollection<string> SelectFiles(IFilesSelectorOptions aOptions)
{
OpenFileDialog vDialog = new OpenFileDialog();
vDialog.Filter = aOptions.Filter;
vDialog.DefaultExt = aOptions.DefaultExt;
vDialog.Multiselect = aOptions.MultiSelect;
vDialog.SupportMultiDottedExtensions = true;
vDialog.Title = aOptions.Title;
if (vDialog.ShowDialog() != DialogResult.OK)
return new List<string>();
return vDialog.FileNames;
}
public ICollection<string> SelectFiles()
{
return SelectFiles(DefaultOptions);
}
#endregion
}
}
@@ -0,0 +1,70 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DelphiProjectHandler.Dialogs.FileSelectors
{
public class FilesSelectorOptions: IFilesSelectorOptions
{
#region (Private)
private string fTitle;
private string fFilter;
private string fDefaultExt;
private bool fMultiSelect;
#endregion
#region (IFilesSelectorOptions Implementation)
public string Title
{
get
{
return fTitle;
}
set
{
fTitle = value;
}
}
public string Filter
{
get
{
return fFilter;
}
set
{
fFilter = value;
}
}
public string DefaultExt
{
get
{
return fDefaultExt;
}
set
{
fDefaultExt = value;
}
}
public bool MultiSelect
{
get
{
return fMultiSelect;
}
set
{
fMultiSelect = value;
}
}
#endregion
}
}
@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace DelphiProjectHandler.Dialogs.FileSelectors
{
public class FolderFilesImporter: IFolderFilesImporter
{
public ICollection<string> SelectFiles(string aDescription, string aFileMask)
{
FolderBrowserDialog vDialog = new FolderBrowserDialog();
vDialog.ShowNewFolderButton = false;
vDialog.Description = aDescription;
if (vDialog.ShowDialog() != DialogResult.OK)
return new List<string>();
return Directory.GetFiles(vDialog.SelectedPath, aFileMask, SearchOption.AllDirectories);
}
}
}
@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DelphiProjectHandler.Dialogs.FileSelectors
{
public interface IFilesSelectorOptions
{
string Title { get; set; }
string Filter { get; set; }
string DefaultExt { get; set; }
bool MultiSelect { get; set; }
}
public interface IFilesSelector
{
IFilesSelectorOptions DefaultOptions { get; }
ICollection<string> SelectFiles(IFilesSelectorOptions aOptions);
ICollection<string> SelectFiles();
}
}
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DelphiProjectHandler.Dialogs.FileSelectors
{
public interface IFolderFilesImporter
{
ICollection<string> SelectFiles(string aDescription, string aFileMask);
}
}
@@ -0,0 +1,63 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DelphiProjectHandler.Dialogs.FileSelectors;
namespace DelphiProjectHandler.Dialogs.FileSelectors.Specialized
{
public class DprFilesSelector: IFilesSelector
{
#region Private
private IFilesSelector fBaseSelector;
private IFilesSelectorOptions fDefaultOptions;
#endregion
#region Protected
protected IFilesSelector BaseSelector
{
get { return fBaseSelector; }
}
protected IFilesSelectorOptions CreateDefaultOptions()
{
IFilesSelectorOptions vOptions = new FilesSelectorOptions();
vOptions.Filter = "DPR files|*.dpr|All files|*.*";
vOptions.DefaultExt = "dpr";
vOptions.MultiSelect = true;
vOptions.Title = "Select one or more projects";
return vOptions;
}
#endregion
#region Public
public DprFilesSelector(IFilesSelector aBaseSelector): base()
{
fBaseSelector = aBaseSelector;
fDefaultOptions = CreateDefaultOptions();
}
#endregion
#region IFilesSelector Members
public IFilesSelectorOptions DefaultOptions
{
get { return fDefaultOptions; }
}
public ICollection<string> SelectFiles(IFilesSelectorOptions aOptions)
{
return BaseSelector.SelectFiles(aOptions);
}
public ICollection<string> SelectFiles()
{
return SelectFiles(DefaultOptions);
}
#endregion
}
}
@@ -0,0 +1,63 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DelphiProjectHandler.Dialogs.FileSelectors.Specialized
{
public class PasFilesSelector: IFilesSelector
{
#region Private
private IFilesSelector fBaseSelector;
private IFilesSelectorOptions fDefaultOptions;
#endregion
#region Protected
protected IFilesSelector BaseSelector
{
get { return fBaseSelector; }
}
protected IFilesSelectorOptions CreateDefaultOptions()
{
IFilesSelectorOptions vOptions = new FilesSelectorOptions();
vOptions.Filter = "Pas files|*.pas|All files|*.*";
vOptions.DefaultExt = "pas";
vOptions.MultiSelect = true;
vOptions.Title = "Select one or more units to add";
return vOptions;
}
#endregion
#region Public
public PasFilesSelector(IFilesSelector aBaseSelector)
: base()
{
fBaseSelector = aBaseSelector;
fDefaultOptions = CreateDefaultOptions();
}
#endregion
#region IFilesSelector Members
public IFilesSelectorOptions DefaultOptions
{
get { return fDefaultOptions; }
}
public ICollection<string> SelectFiles(IFilesSelectorOptions aOptions)
{
return BaseSelector.SelectFiles(aOptions);
}
public ICollection<string> SelectFiles()
{
return SelectFiles(DefaultOptions);
}
#endregion
}
}
@@ -0,0 +1,62 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DelphiProjectHandler.Dialogs.FileSelectors.Specialized
{
public class XmlFileSelector: IFilesSelector
{
#region Private
private IFilesSelector fBaseSelector;
private IFilesSelectorOptions fDefaultOptions;
#endregion
#region Protected
protected IFilesSelector BaseSelector
{
get { return fBaseSelector; }
}
protected IFilesSelectorOptions CreateDefaultOptions()
{
IFilesSelectorOptions vOptions = new FilesSelectorOptions();
vOptions.Filter = "XML files|*.xml|All files|*.*";
vOptions.DefaultExt = "xml";
vOptions.MultiSelect = false;
vOptions.Title = "Select existing XML file";
return vOptions;
}
#endregion
#region Public
public XmlFileSelector(IFilesSelector aBaseSelector): base()
{
fBaseSelector = aBaseSelector;
fDefaultOptions = CreateDefaultOptions();
}
#endregion
#region IFilesSelector Members
public IFilesSelectorOptions DefaultOptions
{
get { return fDefaultOptions; }
}
public ICollection<string> SelectFiles(IFilesSelectorOptions aOptions)
{
return BaseSelector.SelectFiles(aOptions);
}
public ICollection<string> SelectFiles()
{
return SelectFiles(DefaultOptions);
}
#endregion
}
}
@@ -0,0 +1,96 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
namespace DelphiProjectHandler
{
public class IcarusAnalyzerReportException: Exception
{
public IcarusAnalyzerReportException(string iMessage): base(iMessage) {}
}
/// <summary>
/// This class is used for parsing Icarus Analyzer results. For the given report it creates a
/// list containing all units listed in the report and list of used units, splitted into
/// interface & implementation categories.
/// </summary>
public class IcarusAnalyzerReportParser
{
protected enum UsesListType: int
{
Interface = 0,
Implementation = 1
}
protected static string ExtractUnitName(string iMatch)
{
Regex vRegExpr = new Regex(@"Module (\w+) uses:", RegexOptions.IgnoreCase | RegexOptions.Singleline);
Match vMatch = vRegExpr.Match(iMatch);
if (!vMatch.Success)
throw new IcarusAnalyzerReportException("Not recognized module name. " + iMatch);
return vMatch.Groups[1].Value;
}
protected static UsesListType ExtractUsesListType(string iMatch)
{
if (Regex.IsMatch(iMatch, "Units used in interface", RegexOptions.IgnoreCase | RegexOptions.Singleline))
return UsesListType.Interface;
else
if (Regex.IsMatch(iMatch, "Units used in implementation", RegexOptions.IgnoreCase | RegexOptions.Singleline))
return UsesListType.Implementation;
else
throw new IcarusAnalyzerReportException("Not recognized uses section type. " + iMatch);
}
protected static void ExtractUnitNames(string iMatch, UsesListType iUsesType, SuggestedUnitStructure iUnitUses)
{
Regex vRegExpr = new Regex(@"(-->|==>)?\s?(\w+)\s(in\simplementation|in\sinterface|unnecessary|source\snot\sfound)(?=\s\(|\r\n)", RegexOptions.IgnoreCase | RegexOptions.Singleline);
MatchCollection vMatches = vRegExpr.Matches(iMatch);
ExtractUnitsGroup(vMatches, "", (iUsesType == UsesListType.Interface ? iUnitUses.Uses.Interface : iUnitUses.Uses.Implementation));
ExtractUnitsGroup(vMatches, "==>", iUnitUses.ToDelete);
if (iUsesType == UsesListType.Interface)
ExtractUnitsGroup(vMatches, "-->", iUnitUses.MoveToInterface, iUnitUses.Uses.Implementation);
}
protected static void ExtractUnitsGroup(MatchCollection aUnitLineMatches, string aGroupCondition, params UnitList[] aListsToAddTo)
{
var vMatchedUnits = from Match vMatch in aUnitLineMatches
where vMatch.Groups[1].Value.Equals(aGroupCondition)
select new UnitItem(vMatch.Groups[2].Value);
foreach (var vUnit in vMatchedUnits)
foreach (var vListToAddTo in aListsToAddTo)
vListToAddTo.Add(vUnit);
}
protected static void ParseMatch(string aUnitName, UsesListType aUsesListType, string aModuleReport, SuggestedUnitStructureList aLists)
{
if (!aLists.ContainsKey(aUnitName))
aLists.Add(aUnitName, new SuggestedUnitStructure());
SuggestedUnitStructure vList = aLists[aUnitName];
ExtractUnitNames(aModuleReport, aUsesListType, vList);
}
protected static void DoParse(string iReport, SuggestedUnitStructureList iLists)
{
Regex vRegEx = new Regex(@"\bModule\s[\w\s.\:\(\),\-\>=]+?(?=\bModule|\bProgram|\bLibrary)|\bModule\s[\w\s.\:\(\),\-\>=]+", RegexOptions.IgnoreCase | RegexOptions.Singleline);
var vModuleReports = from Match vMatch in vRegEx.Matches(iReport)
let vModuleReport = vMatch.Value
select new { UnitName = ExtractUnitName(vModuleReport).ToLower(), UsesListType = ExtractUsesListType(vModuleReport), Report = vModuleReport };
foreach (var vModuleReport in vModuleReports)
ParseMatch(vModuleReport.UnitName, vModuleReport.UsesListType, vModuleReport.Report, iLists);
}
public static SuggestedUnitStructureList Parse(string iReport)
{
SuggestedUnitStructureList vResult = new SuggestedUnitStructureList();
DoParse(iReport, vResult);
return vResult;
}
}
}
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace DelphiProjectHandler.LibraryPaths
{
public class ClipboardLibraryPathsProvider: ILibraryPathsProvider
{
#region ILibraryPathsProvider Members
public IList<string> List()
{
string vPathsStr = Clipboard.GetText();
string[] vPaths = vPathsStr.Split(';');
return new List<string>(vPaths);
}
#endregion
}
}
@@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace DelphiProjectHandler.LibraryPaths
{
public class DelphiLibraryPathsBuilder: ILibraryPathsBuilder
{
#region (Protected Methods)
protected IList<string> CopyFromList(IList<string> iPaths)
{
IList<string> vResult = new List<string>();
foreach (string vPath in iPaths)
vResult.Add(vPath.ToLower());
return vResult;
}
protected bool SubstituteEnvironmentPaths(IList<string> iPaths, int iPathIdx, IDictionary<string, string> iEnvironmentPaths)
{
bool vReplaced = false;
string vNewPath = iPaths[iPathIdx];
vNewPath = SubstituteEnvironmentPaths(vNewPath, iEnvironmentPaths);
vReplaced = !vNewPath.Equals(iPaths[iPathIdx]);
if (vReplaced)
iPaths[iPathIdx] = vNewPath;
return vReplaced;
}
protected string SubstituteEnvironmentPaths(string iPath, IDictionary<string, string> iEnvironmentPaths)
{
foreach (string vKey in iEnvironmentPaths.Keys)
iPath = iPath.Replace("$(" + vKey.ToLower() + ")", iEnvironmentPaths[vKey].ToLower());
return iPath;
}
#endregion
#region ILibraryPathsBuilder Members
public IList<string> Build(IList<string> iPaths, IDictionary<string, string> iEnvironmentPaths)
{
bool vReplaced = false;
IList<string> vResult = CopyFromList(iPaths);
do
{
vReplaced = false;
for (int vPathIdx = 0; vPathIdx < vResult.Count; vPathIdx++)
vReplaced = SubstituteEnvironmentPaths(vResult, vPathIdx, iEnvironmentPaths) || vReplaced;
} while (vReplaced);
return vResult;
}
#endregion
}
}
@@ -0,0 +1,76 @@
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Win32;
namespace DelphiProjectHandler.LibraryPaths
{
public class DelphiLibraryPathsProvider: ILibraryPathsProvider
{
#region (Public Methods)
public DelphiLibraryPathsProvider(LibraryPathType iType)
{
fLibraryType = iType;
}
#endregion
#region ILibraryPathsProvider Members
IList<string> ILibraryPathsProvider.List()
{
List<string> vPaths = ListPaths(LibraryType);
IDictionary<string, string> vEnvironmentPaths = ListEnvironmentPaths(LibraryType);
return BuildPaths(vPaths, vEnvironmentPaths);
}
#endregion
#region (Protected Methods)
protected string ReadString(RegistryKey iKey, string iValueName)
{
return iKey.GetValue(iValueName).ToString();
}
protected List<string> ListPaths(LibraryPathType iType)
{
List<string> vResult = new List<string>();
vResult.AddRange(ReadString(DelphiRegistryKeys.LibraryKey(iType), "Search Path").ToString().Split(';'));
return vResult;
}
protected IDictionary<string, string> ListEnvironmentPaths(LibraryPathType iType)
{
Dictionary<string, string> vResult = new Dictionary<string, string>();
try
{
vResult.Add("delphi", ReadString(DelphiRegistryKeys.RootDirKey(iType), "RootDir"));
RegistryKey vKey = DelphiRegistryKeys.EnvironmentPathsKey(iType);
foreach (string vValueName in vKey.GetValueNames())
vResult.Add(vValueName, vKey.GetValue(vValueName).ToString());
}
catch (NotSupportedException)
{
// In this case return empty dictionary - no environment variables to return
}
return vResult;
}
protected IList<string> BuildPaths(List<string> vPaths, IDictionary<string, string> vEnvironmentPaths)
{
ILibraryPathsBuilder vBuilder = new DelphiLibraryPathsBuilder();
return vBuilder.Build(vPaths, vEnvironmentPaths);
}
#endregion
#region (Protected Properties)
protected LibraryPathType LibraryType
{
get { return fLibraryType; }
}
public LibraryPathType fLibraryType;
#endregion
}
}
@@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Win32;
namespace DelphiProjectHandler.LibraryPaths
{
public sealed class DelphiRegistryKeys
{
public static RegistryKey LibraryKey(LibraryPathType iType)
{
string vKey = "";
switch (iType)
{
case LibraryPathType.Delphi5:
vKey = @"Software\Borland\Delphi\5.0\Library";
break;
case LibraryPathType.Delphi6:
vKey = @"Software\Borland\Delphi\6.0\Library";
break;
default:
throw new NotSupportedException("The library type " + iType.ToString() + " is not supported");
}
return Registry.CurrentUser.OpenSubKey(vKey);
}
public static RegistryKey EnvironmentPathsKey(LibraryPathType iType)
{
string vKey = "";
switch (iType)
{
case LibraryPathType.Delphi6:
vKey = @"Software\Borland\Delphi\6.0\Environment Variables";
break;
default:
throw new NotSupportedException("The library type " + iType.ToString() + " is not supported");
}
return Registry.CurrentUser.OpenSubKey(vKey);
}
public static RegistryKey RootDirKey(LibraryPathType iType)
{
switch (iType)
{
case LibraryPathType.Delphi5:
return Registry.LocalMachine.OpenSubKey(@"Software\Borland\Delphi\5.0");
case LibraryPathType.Delphi6:
return Registry.CurrentUser.OpenSubKey(@"Software\Borland\Delphi\6.0");
default:
throw new NotSupportedException("The library type " + iType.ToString() + " is not supported");
}
}
}
}
@@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace DelphiProjectHandler.LibraryPaths
{
public interface ILibraryPathsBuilder
{
IList<string> Build(IList<string> iPaths, IDictionary<string, string> iEnvironmentPaths);
}
}
@@ -0,0 +1,59 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DelphiProjectHandler.LibraryPaths
{
public sealed class LibraryPathsProviderFactory
{
public static bool IsProviderSupported(LibraryPathType iLibraryType)
{
try
{
ILibraryPathsProvider vProvider = LibraryPathsProviderFactory.CreateProvider(iLibraryType);
return (vProvider != null);
}
catch (NotSupportedException)
{
return false;
}
}
public static LibraryPathType[] ListSupportedProviders()
{
Array vLibraryTypes = Enum.GetValues(typeof(LibraryPathType));
List<object> vSupported = new List<object>();
for (int vLibraryTypeIdx = 0; vLibraryTypeIdx < vLibraryTypes.Length; vLibraryTypeIdx++)
{
LibraryPathType vType = (LibraryPathType)vLibraryTypes.GetValue(vLibraryTypeIdx);
if (!IsProviderSupported(vType))
continue;
vSupported.Add(vType);
}
LibraryPathType[] vResult = new LibraryPathType[vSupported.Count];
for (int vSupportedIdx = 0; vSupportedIdx < vSupported.Count; vSupportedIdx++)
vResult[vSupportedIdx] = (LibraryPathType)vSupported[vSupportedIdx];
return vResult;
}
public static ILibraryPathsProvider CreateProvider(LibraryPathType iType)
{
switch (iType)
{
case LibraryPathType.Delphi5:
case LibraryPathType.Delphi6:
return new DelphiLibraryPathsProvider(iType);
case LibraryPathType.Clipboard:
return new ClipboardLibraryPathsProvider();
default:
throw new NotSupportedException("Provider " + iType.ToString() + " is not supported, yet.");
}
}
}
}
@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DelphiProjectHandler.LibraryPaths
{
public enum LibraryPathType : int
{
Delphi5 = 0,
Delphi6 = 1,
Delphi7 = 2,
Delphi2005 = 3,
Delphi2007 = 4,
Delphi2009 = 5,
Clipboard = 6
}
public interface ILibraryPathsProvider
{
IList<string> List();
}
}
@@ -0,0 +1,106 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DelphiProjectHandler.View;
namespace DelphiProjectHandler.Model
{
public class FixProjectSettings: IFixProjectSettings
{
#region (Private)
private bool fAddUnitPathsToDPRs = true;
private IList<string> fProjects = new List<string>();
private IList<string> fUnitsToManipulate = new List<string>();
private IList<string> fUnitConstraints = new List<string>();
private IList<IFixProjectSettingsView> fObservers = new List<IFixProjectSettingsView>();
#endregion
#region (Protected)
protected IList<IFixProjectSettingsView> Observers
{
get { return fObservers; }
}
#endregion
#region (IFixProjectSettingsModel implementation)
public bool AddUnitPathsToDPRs
{
get
{
return fAddUnitPathsToDPRs;
}
set
{
fAddUnitPathsToDPRs = value;
}
}
public IList<string> Projects
{
get
{
return fProjects;
}
set
{
if (value == null)
throw new ArgumentNullException("Projects");
fProjects = value;
}
}
public IList<string> UnitsToManipulate
{
get
{
return fUnitsToManipulate;
}
set
{
if (value == null)
throw new ArgumentNullException("UnitsToManipulate");
fUnitsToManipulate = value;
}
}
public IList<string> UnitConstraints
{
get
{
return fUnitConstraints;
}
set
{
if (value == null)
throw new ArgumentNullException("UnitConstraints");
}
}
public void AddObserver(View.IFixProjectSettingsView aView)
{
Observers.Add(aView);
}
public void RemoveObserver(View.IFixProjectSettingsView aView)
{
Observers.Remove(aView);
}
public void NotifyObservers()
{
foreach (IFixProjectSettingsView vObserver in Observers)
vObserver.UpdateView(this);
}
#endregion
}
}
@@ -0,0 +1,104 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DelphiProjectHandler.View;
namespace DelphiProjectHandler.Model
{
public class FixUnitSettings: IFixUnitSettings
{
#region (Private)
private IList<string> fUnitsToModify = new List<string>();
private IList<string> fInterfaceUnits = new List<string>();
private IList<string> fImplementationUnits = new List<string>();
private IList<string> fUnitConstraints = new List<string>();
private ICollection<IFixUnitSettingsView> fObservers = new List<IFixUnitSettingsView>();
#endregion
#region (Protected)
protected ICollection<IFixUnitSettingsView> Observers
{
get { return fObservers; }
}
#endregion
#region (IFixUnitSettings Implementation)
public IList<string> UnitsToModify
{
get
{
return fUnitsToModify;
}
set
{
if (value == null)
throw new ArgumentNullException("UnitsToModify");
fUnitsToModify = value;
}
}
public IList<string> InterfaceUnits
{
get
{
return fInterfaceUnits;
}
set
{
if (value == null)
throw new ArgumentNullException("InterfaceUnits");
fInterfaceUnits = value;
}
}
public IList<string> ImplementationUnits
{
get
{
return fImplementationUnits;
}
set
{
if (value == null)
throw new ArgumentNullException("ImplementationUnits");
fImplementationUnits = value;
}
}
public IList<string> UnitConstraints
{
get
{
return fUnitConstraints;
}
set
{
if (value == null)
throw new ArgumentNullException("UnitConstraints");
fUnitConstraints = value;
}
}
public void AddObserver(IFixUnitSettingsView aView)
{
Observers.Add(aView);
}
public void RemoveObserver(IFixUnitSettingsView aView)
{
Observers.Remove(aView);
}
public void NotifyObservers()
{
foreach (IFixUnitSettingsView vObserver in Observers)
vObserver.UpdateView(this);
}
}
#endregion
}
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DelphiProjectHandler.View;
namespace DelphiProjectHandler.Model
{
public interface IFixProjectSettings
{
IList<string> Projects { get; set; }
IList<string> UnitsToManipulate { get; set; }
IList<string> UnitConstraints { get; set; }
bool AddUnitPathsToDPRs { get; set; }
void AddObserver(IFixProjectSettingsView aView);
void RemoveObserver(IFixProjectSettingsView aView);
void NotifyObservers();
}
}
@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DelphiProjectHandler.View;
namespace DelphiProjectHandler.Model
{
public interface IFixUnitSettings
{
IList<string> UnitsToModify { get; set; }
IList<string> InterfaceUnits { get; set; }
IList<string> ImplementationUnits { get; set; }
IList<string> UnitConstraints { get; set; }
void AddObserver(IFixUnitSettingsView aView);
void RemoveObserver(IFixUnitSettingsView aView);
void NotifyObservers();
}
}
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DelphiProjectHandler.LibraryPaths;
using DelphiProjectHandler.View;
namespace DelphiProjectHandler.Model
{
public interface ILibraryPathSettings
{
IList<LibraryPathType> SupportedProviders { get; }
IList<string> LibraryPaths { get; set; }
void AddObserver(ILibraryPathSettingsView aView);
void RemoveObserver(ILibraryPathSettingsView aView);
void NotifyObservers();
}
}
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DelphiProjectHandler.View;
namespace DelphiProjectHandler.Model
{
public interface IUnitCleanupSettings
{
IList<string> UnitsToClean { get; set; }
IList<string> IgnoredUnits { get; set; }
String IcarusReport { get; set; }
void AddObserver(IUnitCleanupSettingsView aView);
void RemoveObserver(IUnitCleanupSettingsView aView);
void NotifyObservers();
}
}
@@ -0,0 +1,66 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DelphiProjectHandler.View;
using DelphiProjectHandler.LibraryPaths;
namespace DelphiProjectHandler.Model
{
public class LibraryPathSettings: ILibraryPathSettings
{
#region (Private)
private IList<string> fLibraryPaths = new List<string>();
private IList<ILibraryPathSettingsView> fObservers = new List<ILibraryPathSettingsView>();
private IList<LibraryPathType> fSupportedProviders = LibraryPathsProviderFactory.ListSupportedProviders();
#endregion
#region (Protected)
protected IList<ILibraryPathSettingsView> Observers
{
get { return fObservers; }
}
#endregion
#region (ILibraryPathSettings Implementation)
public IList<LibraryPathType> SupportedProviders
{
get { return fSupportedProviders; }
}
public IList<string> LibraryPaths
{
get
{
return fLibraryPaths;
}
set
{
if (value == null)
throw new ArgumentNullException("LibraryPaths");
fLibraryPaths = value;
}
}
public void AddObserver(ILibraryPathSettingsView aView)
{
Observers.Add(aView);
}
public void RemoveObserver(ILibraryPathSettingsView aView)
{
Observers.Remove(aView);
}
public void NotifyObservers()
{
foreach (ILibraryPathSettingsView vObserver in Observers)
vObserver.UpdateView(this);
}
#endregion
}
}
@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
namespace DelphiProjectHandler.Model
{
[Serializable]
[XmlType(TypeName="project")]
public class ProjectBulkOperation
{
[XmlAttribute("name")]
public string ProjectName { get; set; }
[XmlArray("add")]
[XmlArrayItem("file")]
public List<string> Add { get; set; }
[XmlArray("remove")]
[XmlArrayItem("file")]
public List<string> Remove { get; set; }
public ProjectBulkOperation()
{
Add = new List<string>();
Remove = new List<string>();
}
}
[Serializable]
[XmlType(TypeName="projects")]
public class ProjectBulkOperations: List<ProjectBulkOperation>
{
}
}
@@ -0,0 +1,89 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DelphiProjectHandler.View;
namespace DelphiProjectHandler.Model
{
public class UnitCleanupSettings: IUnitCleanupSettings
{
#region (Private)
private IList<IUnitCleanupSettingsView> fObservers = new List<IUnitCleanupSettingsView>();
private IList<string> fUnitsToClean = new List<string>();
private IList<string> fIgnoredUnits = new List<string>();
private string fIcarusReport = "";
#endregion
#region (Protected)
protected IList<IUnitCleanupSettingsView> Observers
{
get { return fObservers; }
}
#endregion
#region (IUnitCleanupSettings Implementation)
public IList<string> UnitsToClean
{
get
{
return fUnitsToClean;
}
set
{
if (value == null)
throw new ArgumentNullException("UnitsToClean");
fUnitsToClean = value;
}
}
public IList<string> IgnoredUnits
{
get
{
return fIgnoredUnits;
}
set
{
if (value == null)
throw new ArgumentNullException("IgnoredUnits");
fIgnoredUnits = value;
}
}
public string IcarusReport
{
get
{
return fIcarusReport;
}
set
{
if (value == null)
throw new ArgumentNullException("IcarusReport");
fIcarusReport = value;
}
}
public void AddObserver(View.IUnitCleanupSettingsView aView)
{
Observers.Add(aView);
}
public void RemoveObserver(View.IUnitCleanupSettingsView aView)
{
Observers.Remove(aView);
}
public void NotifyObservers()
{
foreach (IUnitCleanupSettingsView vObserver in Observers)
vObserver.UpdateView(this);
}
#endregion
}
}
@@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace DelphiProjectHandler.Operations
{
public class DelphiFileAgentError : Exception
{
public DelphiFileAgentError(string aMessage): base(aMessage)
{
}
}
public class DelphiFileAgent: IDelphiFileAgent
{
public void Execute(String aUnitFileName, IDelphiFileOperation aOperation)
{
Execute(aUnitFileName, new IDelphiFileOperation[] { aOperation });
}
public void Execute(String aUnitFileName, params IDelphiFileOperation[] aOperations)
{
FileModifierAgent vFileAgent = new FileModifierAgent(aUnitFileName);
foreach (IDelphiFileOperation vOperation in aOperations)
{
try
{
vOperation.Initialize(aUnitFileName, vFileAgent.Content);
if (!vOperation.CanProcess())
return;
vFileAgent.Content = vOperation.Execute();
}
catch (Exception e)
{
throw new DelphiFileAgentError(String.Format("Error processing file: {0}. {1}", aUnitFileName, e.Message));
}
}
if (vFileAgent.Modified)
vFileAgent.Save(aUnitFileName);
}
}
}
@@ -0,0 +1,12 @@
using System;
namespace DelphiProjectHandler.Operations
{
public abstract class DelphiOperation
{
protected virtual string ReplaceContent(string iContent, string iOldValue, string iNewValue)
{
return iContent.Replace(iOldValue, iNewValue);
}
}
}
@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using DelphiProjectHandler.Operations.Projects;
namespace DelphiProjectHandler.Operations
{
/// <summary>
/// Modifies Delphi projects, e.g. by adding units, changing unit paths etc.
/// </summary>
public class DelphiProjectAgent
{
protected FileModifierAgent FileAgent
{
get { return fFileAgent; }
}
private FileModifierAgent fFileAgent;
public DelphiProjectAgent(string iProjectName)
{
fFileAgent = new FileModifierAgent(iProjectName);
}
public bool Modified
{
get { return FileAgent.Modified; }
}
public void Save(string iProjectName)
{
FileAgent.Save(iProjectName);
}
}
}
@@ -0,0 +1,52 @@
/*
* Created by SharpDevelop.
* User: SG0894652
* Date: 8/12/2009
* Time: 10:58 PM
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Collections.Generic;
using DelphiProjectHandler.Operations.Units;
namespace DelphiProjectHandler.Operations
{
/// <summary>
/// Description of DelphiUnitAgent.
/// </summary>
public class DelphiUnitAgent
{
#region (Protected Properties)
protected FileModifierAgent FileAgent
{
get { return fFileAgent; }
}
private FileModifierAgent fFileAgent;
#endregion
public DelphiUnitAgent(string aUnitFilename)
{
fFileAgent = new FileModifierAgent(aUnitFilename);
}
public void CleanupUnits(SuggestedUnitStructure aSuggestedStructure, IList<string> aIgnoredUnits)
{
DelphiUnitCleanerOperation vOperation = new DelphiUnitCleanerOperation();
FileAgent.Content = vOperation.Execute(FileAgent.Content, aSuggestedStructure, aIgnoredUnits);
}
public bool Modified
{
get { return FileAgent.Modified; }
}
public void Save(string aUnitFilename)
{
FileAgent.Save(aUnitFilename);
}
}
}
@@ -0,0 +1,67 @@
/*
* Created by SharpDevelop.
* User: SG0894652
* Date: 8/12/2009
* Time: 10:49 PM
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.IO;
namespace DelphiProjectHandler.Operations
{
/// <summary>
/// Description of FileModifierAgent.
/// </summary>
public class FileModifierAgent
{
public FileModifierAgent(string iFileName)
{
Load(iFileName);
}
public virtual void Save(string iFileName)
{
string vTempFileName = iFileName + ".tmp";
string vBackupFileName = iFileName + ".backup";
File.SetAttributes(iFileName, FileAttributes.Normal);
File.WriteAllText(vTempFileName, Content);
File.Replace(vTempFileName, iFileName, vBackupFileName, false);
fFileName = iFileName;
fOriginalContent = Content;
}
public virtual void Load(string iFileName)
{
fFileName = iFileName;
fOriginalContent = File.ReadAllText(iFileName);
Content = OriginalContent;
}
public string FileName
{
get { return fFileName; }
}
protected string fFileName;
public string Content
{
get { return fContent; }
set { fContent = value; }
}
protected string fContent;
public string OriginalContent
{
get { return fOriginalContent; }
}
protected string fOriginalContent;
public bool Modified
{
get { return OriginalContent != Content; }
}
}
}
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DelphiProjectHandler.Operations
{
public interface IDelphiFileAgent
{
void Execute(String aUnitFileName, IDelphiFileOperation aOperation);
void Execute(String aUnitFileName, params IDelphiFileOperation[] aOperations);
}
}
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DelphiProjectHandler.Operations
{
public interface IDelphiFileOperation
{
void Initialize(string aFileName, string aFileContent);
bool CanProcess();
string Execute();
}
}
@@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DelphiProjectHandler.Operations
{
public interface IOperationState
{
}
}
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DelphiProjectHandler.Operations
{
public interface IUnitItemBuilder
{
UnitItem Create(string aUnitFileName);
}
}
@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DelphiProjectHandler.Model;
using System.IO;
using System.Xml.Serialization;
using System.Xml;
namespace DelphiProjectHandler.Operations
{
public class ProjectBulkOperationLoader
{
public static ProjectBulkOperations FromStream(Stream aStream)
{
XmlSerializer vSerializer = new XmlSerializer(typeof(ProjectBulkOperations));
//if (!vSerializer.CanDeserialize(XmlReader.Create(aStream)))
// throw new InvalidDataException("Unsupported stream format");
return vSerializer.Deserialize(aStream) as ProjectBulkOperations;
}
}
}
@@ -0,0 +1,83 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DelphiProjectHandler.Operations.Uses;
namespace DelphiProjectHandler.Operations.Projects
{
public abstract class AbstractDelphiProjectOperation : IDelphiFileOperation
{
private IUsesListOperation fOperation;
private IProjectOperationSettings fSettings;
private IProjectOperationState fState;
protected IUsesListOperation Operation
{
get { return fOperation; }
set { fOperation = value; }
}
protected IProjectOperationSettings Settings
{
get { return fSettings; }
set { fSettings = value; }
}
protected IProjectOperationState State
{
get { return fState; }
set { fState = value; }
}
protected virtual string ReplaceContent(string iContent, string iOldValue, string iNewValue)
{
return iContent.Replace(iOldValue, iNewValue);
}
protected IProjectOperationSettings CreateProjectSettings(ICollection<string> aRequiredUnits, ICollection<string> aUnitsToManipulate, bool aUsePaths)
{
IProjectOperationSettings vSettings = new ProjectOperationSettings();
vSettings.RequiredUnits = aRequiredUnits;
vSettings.UnitsToManipulate = aUnitsToManipulate;
vSettings.UsePaths = aUsePaths;
return vSettings;
}
protected IUnitItemBuilder CreateUnitItemBuilder(string aFileName, bool aUsePaths)
{
return new ProjectUnitItemBuilder(aFileName, aUsePaths);
}
protected abstract IUsesListOperation CreateUsesOperation(string aFileName, IProjectOperationSettings aSettings, IUnitItemBuilder aBuilder);
public AbstractDelphiProjectOperation(ICollection<string> aRequiredUnits, ICollection<string> aUnitsToManipulate, bool aUsePaths)
{
fState = new ProjectOperationState();
fSettings = CreateProjectSettings(aRequiredUnits, aUnitsToManipulate, aUsePaths);
}
public virtual void Initialize(string aFileName, string aFileContent)
{
State.FileContent = aFileContent;
State.OriginalUsesClause = UsesClauseReader.ExtractUses(aFileContent);
State.Units = UsesClauseReader.GetUnits(State.FileContent);
IUnitItemBuilder vBuilder = CreateUnitItemBuilder(aFileName, Settings.UsePaths);
fOperation = CreateUsesOperation(aFileName, Settings, vBuilder);
Operation.Initialize(State.Units);
}
public bool CanProcess()
{
return Operation.CanProcess();
}
public string Execute()
{
if (!Operation.Execute())
return State.FileContent;
return ReplaceContent(State.FileContent, State.OriginalUsesClause, State.Units.ToString());
}
}
}
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Text;
using DelphiProjectHandler.Operations.Uses;
namespace DelphiProjectHandler.Operations.Projects
{
public class DelphiProjectAddUnitOperation: AbstractDelphiProjectOperation
{
protected override IUsesListOperation CreateUsesOperation(string aFileName, IProjectOperationSettings aSettings, IUnitItemBuilder aBuilder)
{
IUsesListOperationSettings vUsesSettings = new UsesListOperationSettings();
vUsesSettings.RequiredUnits = aSettings.RequiredUnits;
vUsesSettings.UnitItemBuilder = aBuilder;
vUsesSettings.UnitsToManipulate = aSettings.UnitsToManipulate;
return new UsesListAddOperation(vUsesSettings);
}
public DelphiProjectAddUnitOperation(ICollection<string> aRequiredUnits, ICollection<string> aUnitsToManipulate, bool aUsePaths)
: base(aRequiredUnits, aUnitsToManipulate, aUsePaths)
{
}
}
}
@@ -0,0 +1,23 @@
using System;
using DelphiProjectHandler.Operations.Uses;
using System.Collections.Generic;
namespace DelphiProjectHandler.Operations.Projects
{
public class DelphiProjectFixFormsOperation: AbstractDelphiProjectOperation
{
protected override IUsesListOperation CreateUsesOperation(string aFileName, IProjectOperationSettings aSettings, IUnitItemBuilder aBuilder)
{
IUsesListOperationSettings vUsesSettings = new UsesListOperationSettings();
vUsesSettings.RequiredUnits = aSettings.RequiredUnits;
vUsesSettings.UnitItemBuilder = aBuilder;
vUsesSettings.UnitsToManipulate = aSettings.UnitsToManipulate;
return new UsesListFixFormOperation(vUsesSettings);
}
public DelphiProjectFixFormsOperation(ICollection<string> aRequiredUnits, ICollection<string> aUnitsToManipulate, bool aUsePaths): base(aRequiredUnits, aUnitsToManipulate, aUsePaths)
{
}
}
}
@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Text;
using DelphiProjectHandler.Operations.Uses;
namespace DelphiProjectHandler.Operations.Projects
{
public class DelphiProjectFixPathsOperation: AbstractDelphiProjectOperation
{
protected override IUsesListOperation CreateUsesOperation(string aFileName, IProjectOperationSettings aSettings, IUnitItemBuilder aBuilder)
{
IUsesListOperationSettings vUsesSettings = new UsesListOperationSettings();
vUsesSettings.RequiredUnits = aSettings.RequiredUnits;
vUsesSettings.UnitItemBuilder = aBuilder;
vUsesSettings.UnitsToManipulate = aSettings.UnitsToManipulate;
return new UsesListFixPathOperation(vUsesSettings);
}
public DelphiProjectFixPathsOperation(ICollection<string> aRequiredUnits, ICollection<string> aUnitsToManipulate, bool aUsePaths): base(aRequiredUnits, aUnitsToManipulate, aUsePaths)
{
}
}
}
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Text;
using DelphiProjectHandler.Operations.Uses;
namespace DelphiProjectHandler.Operations.Projects
{
public class DelphiProjectRemoveUnitOperation: AbstractDelphiProjectOperation
{
public DelphiProjectRemoveUnitOperation(ICollection<string> aRequiredUnits, ICollection<string> aUnitsToManipulate, bool aUsePaths)
: base(aRequiredUnits, aUnitsToManipulate, aUsePaths)
{
}
protected override IUsesListOperation CreateUsesOperation(string aFileName, IProjectOperationSettings aSettings, IUnitItemBuilder aBuilder)
{
IUsesListOperationSettings vUsesSettings = new UsesListOperationSettings();
vUsesSettings.RequiredUnits = aSettings.RequiredUnits;
vUsesSettings.UnitItemBuilder = aBuilder;
vUsesSettings.UnitsToManipulate = aSettings.UnitsToManipulate;
return new UsesListDeleteOperation(vUsesSettings);
}
}
}
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DelphiProjectHandler.Operations.Projects
{
public interface IProjectOperationSettings
{
ICollection<string> RequiredUnits { get; set; }
ICollection<string> UnitsToManipulate { get; set; }
bool UsePaths { get; set; }
}
}
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DelphiProjectHandler.Operations.Projects
{
public interface IProjectOperationState : IOperationState
{
string FileContent { get; set; }
string OriginalUsesClause { get; set; }
UnitList Units { get; set; }
}
}
@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DelphiProjectHandler.Operations.Projects
{
public class ProjectOperationSettings: IProjectOperationSettings
{
private ICollection<string> fRequiredUnits;
public ICollection<string> RequiredUnits
{
get { return fRequiredUnits; }
set { fRequiredUnits = value; }
}
private ICollection<string> fUnitsToManipulate;
public ICollection<string> UnitsToManipulate
{
get { return fUnitsToManipulate; }
set { fUnitsToManipulate = value; }
}
private bool fUsePaths;
public bool UsePaths
{
get { return fUsePaths; }
set { fUsePaths = value; }
}
}
}
@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DelphiProjectHandler.Operations.Projects
{
public class ProjectOperationState : IProjectOperationState
{
private string fFileContent;
public string FileContent
{
get { return fFileContent; }
set { fFileContent = value; }
}
private string fOriginalUsesState;
public string OriginalUsesClause
{
get { return fOriginalUsesState; }
set { fOriginalUsesState = value; }
}
private UnitList fUnits;
public UnitList Units
{
get { return fUnits; }
set { fUnits = value; }
}
}
}
@@ -0,0 +1,63 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using DelphiProjectHandler.Dialogs;
namespace DelphiProjectHandler.Operations.Projects
{
/// <summary>
/// UnitItem builder for creating complete project file unit item. New UnitItem will have all properties set that are normally used in a project Delphi file. It will also
/// search for corresponding dfm file.
/// </summary>
class ProjectUnitItemBuilder: IUnitItemBuilder
{
/// <summary>
/// Complete fileName or path of the project file. It is used to calculate new unit item path relative to project file location.
/// </summary>
public string BasePath
{
get { return fBasePath; }
}
private string fBasePath;
/// <summary>
/// Indicates, if unit paths should be added in a project file style, when converting the unit list to uses clause.
/// </summary>
public bool UsePaths
{
get { return fUsePaths; }
}
private bool fUsePaths;
/// <summary>
/// Creates new instance of the ProjectItemBuilder.
/// </summary>
/// <param name="aBasePath">Complete fileName or path of the project file. It is used to calculate new unit item path relative to project file location.</param>
public ProjectUnitItemBuilder(string aBasePath, bool aUsePaths)
{
fBasePath = aBasePath;
fUsePaths = aUsePaths;
}
/// <summary>
/// Creates new UnitItem object and fills it will all required information that can be used in a project file. Requires valid RelativePath builder and UnitFormFinder.
/// It finds corresponding form for the unit automatically. Path is always set relatively to the BasePath.
/// </summary>
/// <param name="aUnitFileName"></param>
/// <returns></returns>
public UnitItem Create(string aUnitFileName)
{
UnitItem vResult = new UnitItem();
vResult.Name = Path.GetFileNameWithoutExtension(aUnitFileName);
vResult.UsePath = UsePaths;
if (!aUnitFileName.Equals(""))
vResult.Path = Path.GetDirectoryName(aUnitFileName);
vResult.Path = RelativePath.GetRelativeFileName(BasePath, vResult.Path);
vResult.Form = UnitFormReader.GetUnitForm(aUnitFileName);
return vResult;
}
}
}
@@ -0,0 +1,87 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DelphiProjectHandler.Operations.Uses;
namespace DelphiProjectHandler.Operations.Units
{
public abstract class AbstractDelphiUnitOperation: IDelphiFileOperation
{
private IUsesListOperation fIntfOperation;
private IUsesListOperation fImplOperation;
private IDelphiUnitOperationState fState;
protected IDelphiUnitOperationState State
{
get { return fState; }
set { fState = value; }
}
private IDelphiUnitOperationSettings fSettings;
protected IDelphiUnitOperationSettings Settings
{
get { return fSettings; }
set { fSettings = value; }
}
protected IUnitItemBuilder CreateUnitItemBuilder()
{
return new DelphiUnitItemBuilder();
}
protected IDelphiUnitOperationSettings CreateSettings(ICollection<string> aRequiredUnits, ICollection<string> aInterfaceUnits, ICollection<string> aImplementationUnits)
{
IDelphiUnitOperationSettings vSettings = new DelphiUnitOperationSettings();
vSettings.RequiredUnits = aRequiredUnits;
vSettings.IntfUnitsToManipulate = aInterfaceUnits;
vSettings.ImplUnitsToManipulate = aImplementationUnits;
return vSettings;
}
protected abstract IUsesListOperation CreateUsesOperation(ICollection<string> aUnitsToManipulate, ICollection<string> aRequiredUnits, IUnitItemBuilder aBuilder);
protected virtual string ReplaceContent(string iContent, string iOldValue, string iNewValue)
{
return iContent.Replace(iOldValue, iNewValue);
}
public AbstractDelphiUnitOperation(ICollection<string> aInterfaceUnits, ICollection<string> aImplementationUnits, ICollection<string> aRequiredUnits)
{
fState = new DelphiUnitOperationState();
fSettings = CreateSettings(aRequiredUnits, aInterfaceUnits, aImplementationUnits);
}
public void Initialize(string aFileName, string aFileContent)
{
State.FileContent = aFileContent;
string vIntfUsesClause = "", vImplUsesClause = "";
UsesClauseReader.ExtractUses(aFileContent, out vIntfUsesClause, out vImplUsesClause);
State.OriginalIntfUsesClause = vIntfUsesClause;
State.OriginalImplUsesClause = vImplUsesClause;
State.IntfUnits = UsesClauseReader.GetUnits(vIntfUsesClause);
State.ImplUnits = UsesClauseReader.GetUnits(vImplUsesClause);
IUnitItemBuilder vBuilder = CreateUnitItemBuilder();
fIntfOperation = CreateUsesOperation(Settings.IntfUnitsToManipulate, Settings.RequiredUnits, vBuilder);
fImplOperation = CreateUsesOperation(Settings.ImplUnitsToManipulate, Settings.RequiredUnits, vBuilder);
fIntfOperation.Initialize(State.IntfUnits);
fImplOperation.Initialize(State.ImplUnits);
}
public bool CanProcess()
{
return (fIntfOperation.CanProcess() || fImplOperation.CanProcess());
}
public string Execute()
{
string vContent = State.FileContent;
if (fIntfOperation.Execute())
vContent = ReplaceContent(vContent, State.OriginalIntfUsesClause, State.IntfUnits.ToString());
if (fImplOperation.Execute())
vContent = ReplaceContent(vContent, State.OriginalImplUsesClause, State.ImplUnits.ToString());
return vContent;
}
}
}
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using DelphiProjectHandler.Operations.Uses;
namespace DelphiProjectHandler.Operations.Units
{
public class DelphiUnitAddOperation: AbstractDelphiUnitOperation
{
protected override IUsesListOperation CreateUsesOperation(ICollection<string> aUnitsToManipulate, ICollection<string> aRequiredUnits, IUnitItemBuilder aBuilder)
{
IUsesListOperationSettings vUsesSettings = new UsesListOperationSettings();
vUsesSettings.RequiredUnits = aRequiredUnits;
vUsesSettings.UnitItemBuilder = aBuilder;
vUsesSettings.UnitsToManipulate = aUnitsToManipulate;
return new UsesListAddOperation(vUsesSettings);
}
public DelphiUnitAddOperation(ICollection<string> aInterfaceUnits, ICollection<string> aImplementationUnits, ICollection<string> aRequiredUnits)
: base(aInterfaceUnits, aImplementationUnits, aRequiredUnits)
{
}
}
}
@@ -0,0 +1,101 @@
/*
* Created by SharpDevelop.
* User: SG0894652
* Date: 8/12/2009
* Time: 11:06 PM
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Collections.Generic;
using DelphiProjectHandler.Operations;
namespace DelphiProjectHandler.Operations.Units
{
/// <summary>
/// Description of DelphiUnitCleanerOperation.
/// </summary>
public class DelphiUnitCleanerOperation: DelphiOperation
{
public DelphiUnitCleanerOperation(): base()
{
}
protected SuggestedUnitStructure RemoveIgnoredUnits(SuggestedUnitStructure iSuggestedUnitStructure, IList<string> iIgnoredUnits)
{
List<string> vList = new List<string>(iIgnoredUnits);
for (int vUnitIdx = 0; vUnitIdx < vList.Count; vUnitIdx++)
vList[vUnitIdx] = vList[vUnitIdx].ToLower();
SuggestedUnitStructure vResult = iSuggestedUnitStructure.Clone();
RemoveUnits(vResult.MoveToInterface, vList);
RemoveUnits(vResult.ToDelete, vList);
return vResult;
}
protected void RemoveUnits(UnitList iList, IList<string> iToRemove)
{
for (int vUnitIdx = iList.Count - 1; vUnitIdx >= 0; vUnitIdx--)
if (iToRemove.IndexOf(iList[vUnitIdx].Name.ToLower()) >= 0)
iList.RemoveAt(vUnitIdx);
}
protected void AddUnits(UnitList iList, UnitList iToAdd)
{
for (int vUnitIdx = iToAdd.Count - 1; vUnitIdx >= 0; vUnitIdx--)
{
UnitItem vUnit = iToAdd[vUnitIdx];
if (iList.IndexOf(vUnit.Name) < 0)
iList.Insert(0, vUnit);
}
}
protected UnitList GetUsesList(string iUsesContent)
{
if (!iUsesContent.Trim().Equals(""))
return UsesClauseReader.GetUnits(iUsesContent);
else
return new UnitList();
}
protected string CleanUpInterface(string iUnitContent, string iUsesContent, SuggestedUnitStructure iSuggestedStructure)
{
if (iUsesContent.Trim().Equals(""))
return iUnitContent;
UnitList vUnits = GetUsesList(iUsesContent);
RemoveUnits(vUnits, iSuggestedStructure.ToDelete);
RemoveUnits(vUnits, iSuggestedStructure.MoveToInterface);
return ReplaceContent(iUnitContent, iUsesContent, vUnits.ToString());
}
protected string CleanUpImplementation(string iUnitContent, string iUsesContent, SuggestedUnitStructure iSuggestedStructure)
{
UnitList vUnits = GetUsesList(iUsesContent);
RemoveUnits(vUnits, iSuggestedStructure.ToDelete);
AddUnits(vUnits, iSuggestedStructure.MoveToInterface);
if (vUnits.Count == 0 && iUsesContent.Trim().Equals(""))
return iUnitContent;
string vNewValue = vUnits.ToString();
if (iUsesContent.Trim().Equals(""))
{
iUsesContent = "implementation";
vNewValue = "implementation\r\n\r\n" + vNewValue;
}
return ReplaceContent(iUnitContent, iUsesContent, vNewValue);
}
public string Execute(string iUnitContent, SuggestedUnitStructure iSuggestedStructure, IList<string> iIgnoredUnits)
{
string vInterface, vImplementation;
SuggestedUnitStructure vSuggestedStructure = RemoveIgnoredUnits(iSuggestedStructure.Clone(), iIgnoredUnits);
UsesClauseReader.ExtractUses(iUnitContent, out vInterface, out vImplementation);
string vResult = iUnitContent;
vResult = CleanUpInterface(vResult, vInterface, vSuggestedStructure);
vResult = CleanUpImplementation(vResult, vImplementation, vSuggestedStructure);
return vResult;
}
}
}
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace DelphiProjectHandler.Operations.Units
{
public class DelphiUnitItemBuilder: IUnitItemBuilder
{
public UnitItem Create(string aUnitFileName)
{
UnitItem vResult = new UnitItem();
vResult.Name = Path.GetFileNameWithoutExtension(aUnitFileName);
return vResult;
}
}
}
@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DelphiProjectHandler.Operations.Units
{
public class DelphiUnitOperationSettings: IDelphiUnitOperationSettings
{
private ICollection<string> fRequiredUnits;
public ICollection<string> RequiredUnits
{
get { return fRequiredUnits; }
set { fRequiredUnits = value; }
}
private ICollection<string> fIntfUnitsToManipulate;
public ICollection<string> IntfUnitsToManipulate
{
get { return fIntfUnitsToManipulate; }
set { fIntfUnitsToManipulate = value; }
}
private ICollection<string> fImplUnitsToManipulate;
public ICollection<string> ImplUnitsToManipulate
{
get { return fImplUnitsToManipulate; }
set { fImplUnitsToManipulate = value; }
}
}
}
@@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DelphiProjectHandler.Operations.Units
{
public class DelphiUnitOperationState: IDelphiUnitOperationState
{
private string fFileContent;
public string FileContent
{
get { return fFileContent; }
set { fFileContent = value; }
}
private string fOriginalIntfUsesClause;
public string OriginalIntfUsesClause
{
get { return fOriginalIntfUsesClause; }
set { fOriginalIntfUsesClause = value; }
}
private string fOriginalImplUsesClause;
public string OriginalImplUsesClause
{
get { return fOriginalImplUsesClause; }
set { fOriginalImplUsesClause = value; }
}
private UnitList fIntfUnits;
public UnitList IntfUnits
{
get { return fIntfUnits; }
set { fIntfUnits = value; }
}
private UnitList fImplUnits;
public UnitList ImplUnits
{
get { return fImplUnits; }
set { fImplUnits = value; }
}
}
}
@@ -0,0 +1,55 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DelphiProjectHandler.Operations;
namespace DelphiProjectHandler.Operations.Units
{
public abstract class DelphiUnitUsesOperation: DelphiOperation, IDelphiUnitOperation
{
protected virtual bool CanProcessUnit(UnitList aCurrentIntfUnits, UnitList aCurrentImplUnits, ICollection<string> aRequiredUnits)
{
return aCurrentIntfUnits.Concat<string>(aCurrentImplUnits).Intersect<string>(aRequiredUnits).Count() == aRequiredUnits.Count;
}
public string Execute(string aUnitContent, ICollection<string> aInterfaceUnits, ICollection<string> aImplementationUnits, ICollection<string> aRequiredUnits)
{
string vCurrentIntfUses = "";
string vCurrentImplUses = "";
UsesClauseReader.ExtractUses(aUnitContent, out vCurrentIntfUses, out vCurrentImplUses);
UnitList vCurrentIntfUnits = UsesClauseReader.GetUnits(vCurrentIntfUses);
UnitList vCurrentImplUnits = UsesClauseReader.GetUnits(vCurrentImplUses);
if (!CanProcessUnit(vCurrentIntfUnits, vCurrentImplUnits, aRequiredUnits))
return aUnitContent;
string vNewUnitContent = ProcessUsesSection(aUnitContent, vCurrentIntfUses, vCurrentIntfUnits, aInterfaceUnits, "interface");
return ProcessUsesSection(vNewUnitContent, vCurrentImplUses, vCurrentImplUnits, aImplementationUnits, "implementation");
}
protected string ProcessUsesSection(string aUnitContent, string aCurrentUsesClause, UnitList aCurrentUnitList, ICollection<string> aUnits, string aMissingUsesReplacement)
{
bool vListModified = ProcessUsesList(aCurrentUnitList, aUnits);
if (!vListModified)
return aUnitContent;
return BuildNewUsesClause(aUnitContent, aCurrentUsesClause, aCurrentUnitList, aMissingUsesReplacement);
}
protected string BuildNewUsesClause(string aUnitContent, string aCurrentUsesClause, UnitList aCurrentUnitList, string aMissingUsesReplacement)
{
string vLineStarting = "";
string vLineEnding = "";
if (aCurrentUsesClause == "")
{
aCurrentUsesClause = aMissingUsesReplacement + Environment.NewLine;
vLineStarting = aCurrentUsesClause + Environment.NewLine;
}
return ReplaceContent(aUnitContent, aCurrentUsesClause, vLineStarting + aCurrentUnitList.ToString() + vLineEnding);
}
protected abstract bool ProcessUsesList(UnitList aCurrentUnitList, ICollection<string> aUnits);
}
}
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DelphiProjectHandler.Operations.Units
{
public interface IDelphiUnitOperation
{
string Execute(string aUnitContent, ICollection<string> aInterfaceUnits, ICollection<string> aImplementationUnits, ICollection<string> aRequiredUnits);
}
}
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DelphiProjectHandler.Operations.Units
{
public interface IDelphiUnitOperationSettings
{
ICollection<string> RequiredUnits { get; set; }
ICollection<string> IntfUnitsToManipulate { get; set; }
ICollection<string> ImplUnitsToManipulate { get; set; }
}
}
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DelphiProjectHandler.Operations.Units
{
public interface IDelphiUnitOperationState: IOperationState
{
string FileContent { get; set; }
string OriginalIntfUsesClause { get; set; }
string OriginalImplUsesClause { get; set; }
UnitList IntfUnits { get; set; }
UnitList ImplUnits { get; set; }
}
}
@@ -0,0 +1,67 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DelphiProjectHandler.Operations.Uses
{
public abstract class AbstractUsesListOperation: IUsesListOperation
{
private IUsesListOperationSettings fSettings;
protected IUsesListOperationSettings Settings
{
get { return fSettings; }
set { fSettings = value; }
}
private IUsesListOperationState fState;
protected IUsesListOperationState State
{
get { return fState; }
}
protected virtual bool CanProcessUnit(UnitItem aUnit)
{
return (aUnit.Name != "" && State.Units.Contains(aUnit.Name));
}
protected virtual IUsesListOperationState CreateState(UnitList aUnitList)
{
UsesListOperationState vState = new UsesListOperationState();
vState.Units = aUnitList;
return vState;
}
protected abstract bool ProcessUnit(UnitList aUnits, UnitItem aUnit);
public AbstractUsesListOperation(IUsesListOperationSettings aSettings)
{
Settings = aSettings;
}
public void Initialize(UnitList aUnitList)
{
fState = CreateState(aUnitList);
}
public bool CanProcess()
{
return (State.Units.Intersect(Settings.RequiredUnits).Count() == Settings.RequiredUnits.Count);
}
public bool Execute()
{
bool vListModified = false;
foreach (string vUnitFileName in Settings.UnitsToManipulate)
{
UnitItem vUnit = Settings.UnitItemBuilder.Create(vUnitFileName);
if (!CanProcessUnit(vUnit))
continue;
vListModified = ProcessUnit(State.Units, vUnit) || vListModified;
}
return vListModified;
}
}
}
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DelphiProjectHandler.Operations.Uses
{
public interface IUsesListOperation
{
void Initialize(UnitList aUnitList);
bool CanProcess();
bool Execute();
}
}
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DelphiProjectHandler.Operations.Uses
{
public interface IUsesListOperationSettings
{
ICollection<string> RequiredUnits { get; set; }
ICollection<string> UnitsToManipulate { get; set; }
IUnitItemBuilder UnitItemBuilder { get; set; }
}
}
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DelphiProjectHandler.Operations.Uses
{
public interface IUsesListOperationState: IOperationState
{
UnitList Units { get; }
}
}
@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using DelphiProjectHandler.Dialogs;
namespace DelphiProjectHandler.Operations.Uses
{
public class UsesListAddOperation: AbstractUsesListOperation
{
protected override bool ProcessUnit(UnitList aUnits, UnitItem aUnit)
{
aUnits.Add(aUnit);
return true;
}
protected override bool CanProcessUnit(UnitItem aUnit)
{
return (aUnit.Name != "") && !State.Units.Contains(aUnit.Name);
}
public UsesListAddOperation(IUsesListOperationSettings aSettings)
: base(aSettings)
{
}
}
}
@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DelphiProjectHandler.Operations.Uses
{
public class UsesListDeleteOperation : AbstractUsesListOperation
{
protected override bool ProcessUnit(UnitList aUnits, UnitItem aUnit)
{
int vUnitIdx = aUnits.IndexOf(aUnit.Name);
UnitItem vToDelete = aUnits[vUnitIdx];
if (vToDelete.HasStartingConditions && !vToDelete.HasEndingConditions && vUnitIdx < aUnits.Count - 1)
aUnits[vUnitIdx + 1].StartingConditions = vToDelete.StartingConditions;
else
if (vToDelete.HasEndingConditions && !vToDelete.HasStartingConditions && vUnitIdx > 0)
aUnits[vUnitIdx - 1].EndingConditions = vToDelete.EndingConditions;
aUnits.RemoveAt(vUnitIdx);
return true;
}
public UsesListDeleteOperation(IUsesListOperationSettings aSettings)
: base(aSettings)
{
}
}
}
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DelphiProjectHandler.Operations.Uses
{
public class UsesListFixFormOperation: AbstractUsesListOperation
{
protected override bool ProcessUnit(UnitList aUnits, UnitItem aUnit)
{
int vUnitIdx = aUnits.IndexOf(aUnit.Name);
if (aUnits[vUnitIdx].Form == aUnit.Form)
return false;
UnitItem vToFix = aUnits[vUnitIdx];
vToFix.Form = aUnit.Form;
return true;
}
public UsesListFixFormOperation(IUsesListOperationSettings aSettings): base(aSettings)
{
}
}
}
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DelphiProjectHandler.Operations.Uses
{
public class UsesListFixPathOperation: AbstractUsesListOperation
{
protected override bool ProcessUnit(UnitList aUnits, UnitItem aUnit)
{
int vUnitIdx = aUnits.IndexOf(aUnit.Name);
UnitItem iToFix = aUnits[vUnitIdx];
iToFix.UsePath = aUnit.UsePath;
iToFix.Path = aUnit.Path;
return true;
}
public UsesListFixPathOperation(IUsesListOperationSettings aSettings): base(aSettings)
{
}
}
}
@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DelphiProjectHandler.Operations.Uses
{
public class UsesListOperationSettings: IUsesListOperationSettings
{
private ICollection<string> fRequiredUnits;
public ICollection<string> RequiredUnits
{
get { return fRequiredUnits; }
set { fRequiredUnits = value; }
}
private ICollection<string> fUnitsToManipulate;
public ICollection<string> UnitsToManipulate
{
get { return fUnitsToManipulate; }
set { fUnitsToManipulate = value; }
}
private IUnitItemBuilder fUnitItemBuilder;
public IUnitItemBuilder UnitItemBuilder
{
get { return fUnitItemBuilder; }
set { fUnitItemBuilder = value; }
}
}
}
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DelphiProjectHandler.Operations.Uses
{
public class UsesListOperationState: IUsesListOperationState
{
private UnitList fUnits;
public UnitList Units
{
get { return fUnits; }
set { fUnits = value; }
}
}
}
@@ -0,0 +1,137 @@
using System;
using System.Diagnostics;
using System.IO;
using DelphiProjectHandler.Dialogs;
namespace DelphiProjectHandler.SourceControl
{
public class SourceOffsite
{
protected bool WasFileCheckedOut(string iResult)
{
return iResult.StartsWith("Checked out file:");
}
protected void Initialize(
string iServerName,
int iServerPort,
string iAlias,
string iUserName,
string iPassword,
string iBaseFolder)
{
ServerName = iServerName;
ServerPort = iServerPort;
Alias = iAlias;
UserName = iUserName;
Password = iPassword;
BaseFolder = iBaseFolder;
}
protected virtual string GetApplicationFileName()
{
return @"c:\program files\SourceOffsite\soscmd.exe";
}
protected string GetCommandParameters(string iFileName)
{
string vFileName = Path.GetFileName(iFileName);
string vProjectPath = Path.GetDirectoryName(iFileName);
if (vProjectPath.StartsWith(BaseFolder))
{
vProjectPath = vProjectPath.Substring(BaseFolder.Length);
vProjectPath = vProjectPath.TrimStart(Path.DirectorySeparatorChar);
vProjectPath = PathUtils.RemoveEndingDirectorySeparator(vProjectPath);
}
vProjectPath = vProjectPath.Replace(Path.DirectorySeparatorChar, '/');
return string.Format(
@"-command CheckoutFile -server {0}:{1} " +
@"-alias {2} -name {3} -password {4} " +
@"-project $/{5} -file {6}",
ServerName, ServerPort, Alias, UserName, Password, vProjectPath, vFileName);
}
protected virtual string RunCommand(string iFileName)
{
iFileName = iFileName.Trim();
if (iFileName == "")
throw new ArgumentException("File name to checkout can not be empty", "iFileName");
Process vProcess = new Process();
vProcess.StartInfo.FileName = GetApplicationFileName();
vProcess.StartInfo.Arguments = GetCommandParameters(iFileName);
vProcess.StartInfo.CreateNoWindow = true;
vProcess.StartInfo.ErrorDialog = false;
vProcess.StartInfo.RedirectStandardError = true;
vProcess.StartInfo.RedirectStandardInput = true;
vProcess.StartInfo.RedirectStandardOutput = true;
vProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
vProcess.StartInfo.UseShellExecute = false;
vProcess.Start();
vProcess.WaitForExit();
return vProcess.StandardOutput.ReadToEnd();
}
public SourceOffsite(
string iServerName,
int iServerPort,
string iAlias,
string iUserName,
string iPassword,
string iBaseFolder)
{
Initialize(iServerName, iServerPort, iAlias, iUserName, iPassword, iBaseFolder);
}
public bool CheckoutFile(string iFileName)
{
string vResult = RunCommand(iFileName);
return WasFileCheckedOut(vResult);
}
public string ServerName
{
get { return fServerName; }
set { fServerName = value; }
}
protected string fServerName;
public int ServerPort
{
get { return fServerPort; }
set { fServerPort = value; }
}
private int fServerPort;
public string UserName
{
get { return fUserName; }
set { fUserName = value; }
}
protected string fUserName;
public string Password
{
get { return fPassword; }
set { fPassword = value; }
}
protected string fPassword;
public string Alias
{
get { return fAlias; }
set { fAlias = value; }
}
protected string fAlias;
public string BaseFolder
{
get { return fBaseFolder; }
set { fBaseFolder = value; }
}
private string fBaseFolder;
}
}
@@ -0,0 +1,60 @@
/*
* Created by SharpDevelop.
* User: SG0894652
* Date: 8/12/2009
* Time: 10:17 PM
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
namespace DelphiProjectHandler
{
/// <summary>
/// Description of IcarusSuggestedUnitUses.
/// </summary>
public class SuggestedUnitStructure: IDisposable
{
public SuggestedUnitStructure()
{
fUses = new UnitStructure();
fToDelete = new UnitList();
fMoveToInterface = new UnitList();
}
public void Dispose()
{
fUses = null;
fToDelete = null;
fMoveToInterface = null;
}
public UnitStructure Uses
{
get { return fUses; }
}
protected UnitStructure fUses;
public UnitList ToDelete
{
get { return fToDelete; }
}
protected UnitList fToDelete;
public UnitList MoveToInterface
{
get { return fMoveToInterface; }
}
protected UnitList fMoveToInterface;
public SuggestedUnitStructure Clone()
{
SuggestedUnitStructure vResult = new SuggestedUnitStructure();
vResult.MoveToInterface.AddRange(MoveToInterface);
vResult.ToDelete.AddRange(ToDelete);
vResult.Uses.Interface.AddRange(Uses.Interface);
vResult.Uses.Implementation.AddRange(Uses.Implementation);
return vResult;
}
}
}
@@ -0,0 +1,23 @@
/*
* Created by SharpDevelop.
* User: SG0894652
* Date: 8/11/2009
* Time: 6:50 AM
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Collections.Generic;
namespace DelphiProjectHandler
{
/// <summary>
/// Description of UnitUsesLists.
/// </summary>
public class SuggestedUnitStructureList: Dictionary<string, SuggestedUnitStructure>
{
public SuggestedUnitStructureList()
{
}
}
}
@@ -0,0 +1,92 @@
using System;
using System.IO;
using System.Text.RegularExpressions;
namespace DelphiProjectHandler
{
public class UnitFormReader
{
protected static string cFormName = @"(inherited|object)\s+([^:]*):";
protected static string FindAndLoadFormFile(string iUnitFileName)
{
string vFormFileName = Path.ChangeExtension(iUnitFileName, ".dfm");
if (!File.Exists(vFormFileName))
throw new FileNotFoundException("File was not found.", vFormFileName);
return File.ReadAllText(vFormFileName);
}
public static string GetUnitForm(string iUnitFileName)
{
string vResult = "";
string vFileContent = "";
try
{
vFileContent = FindAndLoadFormFile(iUnitFileName);
}
catch (FileNotFoundException)
{
return vResult;
}
Regex vRegExpr = new Regex(cFormName);
if (vRegExpr.IsMatch(vFileContent))
vResult = vRegExpr.Match(vFileContent).Groups[2].Value;
else
vResult = GetBinaryFormName(vFileContent);
return vResult;
}
public static string GetBinaryFormName(string iFileContent)
{
int vPos = iFileContent.IndexOf("TPF0");
if (vPos < 0)
throw new Exception("Can't read form name from DFM file.");
vPos += 5;
// Find 1st character of the name
while (vPos < iFileContent.Length)
{
byte vByte = Convert.ToByte(iFileContent[vPos]);
if (
(vByte >= 65 && vByte <= 90) ||
(vByte >= 97 && vByte <= 122)
)
break;
vPos++;
}
if (vPos == iFileContent.Length)
throw new Exception("Can't read form name from binary DFM file.");
int vStart = vPos;
// Start reading name
while (vPos < iFileContent.Length)
{
byte vByte = Convert.ToByte(iFileContent[vPos]);
if (
(vByte < 48 || vByte > 57) &&
(vByte < 65 || vByte > 90) &&
(vByte < 97 || vByte > 122) &&
(iFileContent[vPos] != '_')
)
break;
vPos++;
}
if (vPos == iFileContent.Length)
throw new Exception("Can't read form name from binary DFM file.");
string vFormTypeName = iFileContent.Substring(vStart, vPos - vStart);
if (vFormTypeName.StartsWith("T"))
vFormTypeName = vFormTypeName.Substring(1);
return vFormTypeName;
}
}
}
+157
View File
@@ -0,0 +1,157 @@
using System;
using System.IO;
namespace DelphiProjectHandler
{
public class UnitItem
{
/// <summary>
/// Name of the unit in uses clause.
/// </summary>
public string Name
{
get { return fName; }
set { fName = value; }
}
protected string fName;
/// <summary>
/// Path, where the unit is placed - if it's given with the unit name.
/// </summary>
public string Path
{
get { return fPath; }
set { fPath = value; }
}
protected string fPath = "";
/// <summary>
/// Indicates, if the path is included together with the unit name
/// </summary>
public bool UsePath
{
get { return fUsePath; }
set { fUsePath = value; }
}
protected bool fUsePath;
public bool HasForm
{
get { return Form != ""; }
}
public string Form
{
get { return fForm; }
set { fForm = value; }
}
protected string fForm = "";
public string StartingConditions
{
get { return fStartingConditions; }
set { fStartingConditions = value.TrimEnd(' ', '\n').TrimStart('\n'); }
}
protected string fStartingConditions = "";
public string EndingConditions
{
get { return fEndingConditions; }
set
{
fEndingConditions = value.TrimEnd(' ', '\n');
fEndingConditions = EndingConditions.TrimStart(' ', '\n');
}
}
protected string fEndingConditions = "";
public bool HasStartingConditions
{
get { return (StartingConditions != ""); }
}
public bool HasEndingConditions
{
get { return (EndingConditions != ""); }
}
/// <summary>
/// Initializes the object with given unit name and path.
/// </summary>
/// <param name="iName">Name of the unit in the uses clause.</param>
/// <param name="iPath">Path to the unit in the uses clause.</param>
protected void Initialize(string iName, string iPath, bool iUsePath, string iForm)
{
fName = iName;
UsePath = iUsePath;
if (UsePath)
Path = iPath;
Form = iForm;
}
/// <summary>
/// Creates new instance of the unit information object.
/// </summary>
/// <param name="iName">Name of the unit in the uses clause.</param>
/// <param name="iPath">Path to the unit in the uses clause.</param>
/// <param name="iUsePath">Indicates, if the path is included together
/// with the unit name.</param>
public UnitItem(string iName, string iPath, bool iUsePath, string iForm)
{
Initialize(iName, iPath, iUsePath, iForm);
}
/// <summary>
/// Creates new instance of the unit information object.
/// </summary>
/// <param name="iName">Name of the unit in the uses clause.</param>
public UnitItem(string iName)
{
Initialize(iName, "", false, "");
}
public UnitItem()
{
Initialize("", "", false, "");
}
/// <summary>
/// Returns the unit name and path (if given) as a string, which can be used
/// to construct "uses" clause in Delphi.
/// </summary>
/// <param name="iIndent">Indention of the output value.</param>
/// <param name="iUnitSeparator">Unit separator that must be added after unit
/// name and/or path. Usually it is collon, but the last unit is separated
/// with semicolon</param>
/// <param name="iSeparatorLast">Specifies, if unit separator must be added
/// as the last character in the output value, after any conditionals. If not,
/// it will be added before EndingConditionals.</param>
/// <returns>Unit name with unit path (if given)</returns>
public string ToString(string iIndent, string iUnitSeparator, bool iSeparatorLast)
{
string vResult = "";
if (StartingConditions != "")
vResult += iIndent + StartingConditions + "\n";
if (StartingConditions != "" || EndingConditions != "")
vResult += iIndent;
vResult += iIndent + Name;
if (UsePath)
vResult += " in '" + System.IO.Path.Combine(Path, Name) + ".pas'";
if (HasForm)
vResult += " {" + Form + "}";
if (!iSeparatorLast)
vResult += iUnitSeparator;
if (EndingConditions != "")
vResult += "\n" + iIndent + EndingConditions;
if (iSeparatorLast)
vResult += iUnitSeparator;
return vResult;
}
}
}
+261
View File
@@ -0,0 +1,261 @@
using System;
using System.Collections;
using System.Collections.Generic;
namespace DelphiProjectHandler
{
public class UnitList: ArrayList, IList<string>
{
protected int IndexOf(string iUnitName, int iStartIndex, int iCount, bool iDescending)
{
iUnitName = iUnitName.ToLower();
int vOffset;
if (!iDescending)
vOffset = 1;
else
vOffset = -1;
for (int vUnitIdx = 0, vCurrIdx = iStartIndex; vUnitIdx < iCount; vUnitIdx++, vCurrIdx += vOffset)
{
if (vCurrIdx < 0 || vCurrIdx >= Count)
break;
UnitItem vUnitItem = this[vCurrIdx];
if (vUnitItem.Name.ToLower().Equals(iUnitName))
return vCurrIdx;
}
return -1;
}
protected void ValidateArgument(object iUnitItem, string iArgumentName)
{
if (!(iUnitItem is UnitItem))
throw new ArgumentOutOfRangeException(iArgumentName, "Argument must be UnitItem");
string vUnitName = ((UnitItem) iUnitItem).Name;
if (Contains(vUnitName))
throw new ArgumentException("Unit \"" + vUnitName + "\" is already on the list", iArgumentName);
}
public new UnitItem this[int iIndex]
{
get { return (UnitItem) base[iIndex]; }
set
{
ValidateArgument(value, "value");
base[iIndex] = value;
}
}
public override int Add(object iUnitItem)
{
ValidateArgument(iUnitItem, "iUnitItem");
return base.Add(iUnitItem);
}
public bool Contains(string iUnitName)
{
return IndexOf(iUnitName) >= 0;
}
public int IndexOf(string iUnitName, int iStartIndex, int iCount)
{
return IndexOf(iUnitName, iStartIndex, iCount, false);
}
public int IndexOf(string iUnitName, int iStartIndex)
{
return IndexOf(iUnitName, iStartIndex, Count - iStartIndex);
}
public int IndexOf(string iUnitName)
{
return IndexOf(iUnitName, 0, Count);
}
public override void Insert(int iIndex, object iUnitItem)
{
ValidateArgument(iUnitItem, "iValue");
base.Insert(iIndex, iUnitItem);
}
public int LastIndexOf(string iUnitName)
{
return LastIndexOf(iUnitName, Count - 1, Count);
}
public int LastIndexOf(string iUnitName, int iStartIndex)
{
return LastIndexOf(iUnitName, iStartIndex, Count - iStartIndex);
}
public int LastIndexOf(string iUnitName, int iStartIndex, int iCount)
{
return IndexOf(iUnitName, iStartIndex, iCount, true);
}
public bool Remove(string iUnitName)
{
int vUnitIdx = IndexOf(iUnitName);
if (vUnitIdx < 0)
return false;
RemoveAt(vUnitIdx);
return true;
}
public override string ToString()
{
string vResult = "";
if (Count == 0)
return vResult;
string vSeparator = ",";
bool vSeparatorLast = false;
vResult = "uses\n";
for (int vUnitIdx = 0; vUnitIdx < Count; vUnitIdx++)
{
UnitItem vUnit = this[vUnitIdx];
if (vUnitIdx == Count - 1)
{
vSeparator = ";";
vSeparatorLast = true;
}
vResult += this[vUnitIdx].ToString(" ", vSeparator, vSeparatorLast) + "\n";
}
return vResult.TrimEnd('\n');
}
#region ICollection<string> Members
void ICollection<string>.Add(string item)
{
Add(new UnitItem(item));
}
void ICollection<string>.CopyTo(string[] array, int arrayIndex)
{
string[] vResult = new string[Count];
for (int vItemIdx = 0; vItemIdx < Count; vItemIdx++)
vResult[vItemIdx] = this[vItemIdx].Name;
vResult.CopyTo(array, arrayIndex);
}
#endregion
protected class UnitListEnumerator : IEnumerator<string>
{
protected UnitList List;
protected int CurrentIdx = -1;
public UnitListEnumerator(UnitList iList)
{
List = new UnitList();
List.AddRange(iList);
}
#region IEnumerator<string> Members
public string Current
{
get
{
if (CurrentIdx >= 0 && CurrentIdx < List.Count)
return List[CurrentIdx].Name;
else
return null;
}
}
#endregion
#region IDisposable Members
public void Dispose()
{
List = null;
}
#endregion
#region IEnumerator Members
object IEnumerator.Current
{
get
{
if (CurrentIdx >= 0 && CurrentIdx < List.Count)
return List[CurrentIdx].Name;
else
return null;
}
}
public bool MoveNext()
{
if (CurrentIdx >= List.Count - 1)
return false;
CurrentIdx++;
return true;
}
public void Reset()
{
if (List.Count > 0)
CurrentIdx = 0;
else
CurrentIdx = -1;
}
#endregion
}
#region IList<string> Members
void IList<string>.Insert(int index, string item)
{
Insert(index, new UnitItem(item));
}
string IList<string>.this[int index]
{
get
{
return this[index].Name;
}
set
{
this[index].Name = value;
}
}
#endregion
#region IEnumerable<string> Members
IEnumerator<string> IEnumerable<string>.GetEnumerator()
{
return new UnitListEnumerator(this);
}
#endregion
#region IEnumerable Members
IEnumerator IEnumerable.GetEnumerator()
{
return new UnitListEnumerator(this);
}
#endregion
}
}
+42
View File
@@ -0,0 +1,42 @@
/*
* Created by SharpDevelop.
* User: SG0894652
* Date: 8/11/2009
* Time: 6:02 AM
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
namespace DelphiProjectHandler
{
/// <summary>
/// Container that stored uses list of a unit. Both, interface and implementation.
/// </summary>
public class UnitStructure: IDisposable
{
public UnitStructure()
{
fImplementation = new UnitList();
fInterface = new UnitList();
}
public UnitList Implementation
{
get { return fImplementation; }
}
private UnitList fImplementation;
public UnitList Interface
{
get { return fInterface; }
}
private UnitList fInterface;
public void Dispose()
{
fImplementation = null;
fInterface = null;
}
}
}
@@ -0,0 +1,179 @@
using System;
using System.Text.RegularExpressions;
namespace DelphiProjectHandler
{
public class UsesClauseReader
{
protected static string cLineComments = @"//[^\r\n]*[\r\n]+";
protected static string cDelphiComments = @"{(?!\$)(?:[/\w\s.]*?[,;]|[\s.]*\w+[\s.]+\w+\s*[/\w\s.]*?)}\r?\n?";
protected static string cIfDefCondExpr = @"\{[\s\n]*\$IFDEF[\s\n]+[^}]+\}[\s\n]*";
protected static string cElseCondExpr = @"\{[\s\n]*\$ELSE[\s\n]+[^}]+\}[\s\n]*";
protected static string cEndifCondExpr = @"[\s\n]*\{[\s\n]*\$ENDIF[\s\n]*[^}]*\}";
protected static string cUnitExpr = @"\w[\d\w_.]*";
protected static string cUnitPathExpr = @"[\s\n]+in[\s\n]+'([^']+)'";
protected static string cUnitCommentExpr = @"\{([^$]*)\}";
protected static string cUnitWithPathExpr = "(" + cUnitExpr + ")(" + cUnitPathExpr + "){0,1}";
protected static string cUnitsPathsAndCommentsExpr = cUnitWithPathExpr + @"[\s\n]*(" + cUnitCommentExpr + "){0,1}[,;]{0,1}";
protected static string cUnitsAndConditions = "((" + cIfDefCondExpr + @")*)[\s\n]*(" + cUnitsPathsAndCommentsExpr + ")((" + cEndifCondExpr + @")*)[,;]{0,1}";
protected static string cUnitLine = @"(([^,;]+)[,;])";
protected static string cUnitLines = "((" + cIfDefCondExpr + ")*(" + cUnitLine + ")(" + cEndifCondExpr + ")*)";
protected static string cAllConditionals = @"\{(\$\w+)([\s\n]+[^}]*)*\}";
protected static string cAllUnits = @"\buses[\s\n]+([^;]*;)";
// 1 unit name
protected static string c1 = @"[\s\n\r]*/*[\s\n\r]*[\w_]+[\s\n\r]*[,;]";
// 2 unit name with form name
protected static string c2 = @"[\s\n\r]*/*[\s\n\r]*[\w_]+[\s\n\r]*{[^}]+}[\s\n\r]*[,;]";
// 3 unit name with in & form name
protected static string c3 = @"[\s\n\r]*/*[\s\n\r]*[\w_]+[\s\n\r]+in[\s\n\r]+'[^']+'[\s\n\r]*{[^}]+}[\s\n\r]*[,;]";
// 4 unit name with in
protected static string c4 = @"[\s\n\r]*/*[\s\n\r]*[\w_]+[\s\n\r]+in[\s\n\r]+'[^']+'[\s\n\r]*[,;]";
// 5 conditional define start
protected static string c5 = @"[\s\n\r]*/*[\s\n\r]*{[\s\n\r]*\$IFDEF[\s\n\r]+[^}]+}";
// 6 conditional define end
protected static string c6 = @"[\s\n\r]*/*[\s\n\r]*{[\s\n\r]*\$ENDIF[\s\n\r]*}";
// 7 C++ like comment
protected static string c7 = @"[\s\n\r]*/*[\s\n\r]*" + cLineComments;
// 8 Delphi like comment
protected static string c8 = @"[\s\n\r]*/*[\s\n\r]*" + cDelphiComments;
// 9 unit name with following C++ comment
protected static string c9 = @"[\s\n\r]*/*[\s\n\r]*[\w_]+\s*(?:" + cLineComments + @")[\s\n\r]*[,;]";
// 10 unit name with following Delphi comment
protected static string c10 = @"[\s\n\r]*/*[\s\n\r]*[\w_]+\s*(?:([\s\n\r]*" + cDelphiComments + @")+)[\s\n\r]*[,;]";
protected static string cUsesClausesExpr = @"(\buses\b(" + c1 + "|" + c2 + "|" + c3 + "|" + c4 + "|" + c5 + "|" + c6 + "|" + c7 + "|" + c8 + "|" + c9 + "|" + c10 + ")+)";
protected static string cInterfaceSectionExpr = @"interface\b((.|\n)*)";
protected static string cImplementationSectionExpr = @"\nimplementation((.|\n)*)";
protected static string cBothSectionsExpr = cInterfaceSectionExpr + cImplementationSectionExpr;
// @"uses[\s\n\r]+[\w\s,\{\}\\'.$:]+?(?=;);"
protected static string GetMatchResult(int iMatchID, Match iMatch)
{
if (iMatch.Groups.Count <= iMatchID)
return "";
else
return iMatch.Groups[iMatchID].Value;
}
protected static string GetMatchResult(int iMatchIdx, string iText, string iExpression)
{
MatchCollection vMatches = ExecuteExpression(iText, iExpression);
if (vMatches.Count <= iMatchIdx)
return "";
else
return GetMatchResult(1, vMatches[iMatchIdx]);
}
protected static MatchCollection ExecuteExpression(string iText, string iExpression)
{
return Regex.Matches(iText, iExpression, RegexOptions.IgnoreCase);
}
protected static string GetAllUnits(string iText)
{
return GetMatchResult(0, iText, cAllUnits);
}
protected static UnitItem SplitUnitInfo(string iText)
{
MatchCollection vMatches = ExecuteExpression(iText, cUnitsAndConditions);
foreach (Match vMatch in vMatches)
{
string vUnitName = GetMatchResult(4, vMatch).Trim();
if (vUnitName == "")
continue;
string vUnitPath = GetMatchResult(6, vMatch).Trim();
bool vHasPath = (vUnitPath != "");
if (vHasPath)
vUnitPath = System.IO.Path.GetDirectoryName(vUnitPath);
string vForm = GetMatchResult(8, vMatch).Trim();
UnitItem vUnit = new UnitItem(vUnitName, vUnitPath, vHasPath, vForm);
vUnit.StartingConditions = GetMatchResult(1, vMatch);
vUnit.EndingConditions = GetMatchResult(9, vMatch);
return vUnit;
}
return null;
}
protected static string RemoveCommentLines(string iText)
{
string vResult = Regex.Replace(iText, cLineComments, "");
return Regex.Replace(vResult, cDelphiComments, "");
}
protected static UnitList SplitUnits(string iText)
{
UnitList vList = new UnitList();
MatchCollection vMatches = ExecuteExpression(iText, cUnitLines);
foreach (Match vMatch in vMatches)
{
string vUnitLine = GetMatchResult(1, vMatch);
if (vUnitLine == "")
continue;
UnitItem vUnit = SplitUnitInfo(vUnitLine);
if (vUnit != null)
vList.Add(vUnit);
}
return vList;
}
public static UnitList GetUnits(string iText)
{
string vAllUnits = GetAllUnits(RemoveCommentLines(iText));
return SplitUnits(vAllUnits);
}
public static void ExtractUses(string iText, out string ivInterface, out string ivImplementation)
{
ivInterface = "";
ivImplementation = "";
string vInterfaceSection = "";
string vImplementationSection = "";
MatchCollection vMatches = ExecuteExpression(iText, cBothSectionsExpr);
if (vMatches.Count == 0)
{
vMatches = ExecuteExpression(iText, cInterfaceSectionExpr);
if (vMatches.Count == 0)
{
vMatches = ExecuteExpression(iText, cImplementationSectionExpr);
if (vMatches.Count > 0)
vImplementationSection = GetMatchResult(1, vMatches[0]);
else
vImplementationSection = "";
}
else
if (vMatches.Count > 0)
vInterfaceSection = GetMatchResult(1, vMatches[0]);
else
vInterfaceSection = "";
}
else
{
vInterfaceSection = GetMatchResult(1, vMatches[0]);
vImplementationSection = GetMatchResult(3, vMatches[0]);
}
ivInterface = ExtractUses(vInterfaceSection);
ivImplementation = ExtractUses(vImplementationSection);
}
public static string ExtractUses(string iContent)
{
return GetMatchResult(0, iContent, cUsesClausesExpr);
}
}
}
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DelphiProjectHandler.Utils
{
public static class CollectionUtils
{
public static void Add<T>(this ICollection<T> aList, ICollection<T> aListToAppend)
{
foreach (T vObject in aListToAppend)
aList.Add(vObject);
}
}
}
@@ -0,0 +1,43 @@
/*
* Created by SharpDevelop.
* User: SG0894652
* Date: 8/10/2009
* Time: 8:34 PM
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Collections.Generic;
namespace DelphiProjectHandler.Dialogs
{
/// <summary>
/// Contains basic methods for manipulating list. E.g. removing duplicates, removing empty strings etc.
/// </summary>
public class ListUtils
{
public static IList<T> Normalize<T>(IList<T> iList)
{
return RemoveDuplicates(iList);
}
public static IList<T> RemoveDuplicates<T>(IList<T> iList)
{
List<T> vResult = new List<T>(iList.Count);
vResult.AddRange(iList);
for (int vItemIdx = vResult.Count - 1; vItemIdx >= 0; vItemIdx--)
{
T vItem = vResult[vItemIdx];
for (int vCompareIdx = vItemIdx - 1; vCompareIdx >= 0; vCompareIdx--)
{
if ((vItem == null && vResult[vCompareIdx] == null) || (vItem != null && vItem.Equals(vResult[vCompareIdx])))
{
vResult.RemoveAt(vItemIdx);
break;
}
}
}
return vResult;
}
}
}
@@ -0,0 +1,263 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace DelphiProjectHandler.Dialogs
{
public class PathUtils
{
/// <summary>
/// Contatets folders from the list, starting on specific index.
/// The returned path always contains ending directory separator character.
/// </summary>
/// <param name="iStartingIdx">Index of the folder in the array. Concatanation
/// will start on the given folder. Empty path will be returned, if index is
/// greater than the number of folders in the array.</param>
/// <param name="iDirectories">Array of folders which should be concatanated.
/// </param>
/// <returns>Empty path if iStartingIdx is outside the bounds of the folders
/// array. Concatanated folders path ended with directory separator
/// character.</returns>
public static string ConcatFolders(int iStartingIdx, string[] iDirectories)
{
string vPath = "";
if (iStartingIdx < 0)
return vPath;
for (; iStartingIdx < iDirectories.Length; iStartingIdx++)
vPath = Path.Combine(vPath, iDirectories[iStartingIdx]);
return AddEndingDirectorySeparator(vPath);
}
/// <summary>
/// Builds a list of "go-up" folders (..) which can be used in relative
/// paths. The path is always ended with directory separator character.
/// </summary>
/// <param name="iCount">Number of "go-up" folders to return.</param>
/// <returns>Path containing "go-up" folders.</returns>
public static string BuildGoUpPath(int iCount)
{
StringBuilder vPath = new StringBuilder();
for (int vPathIdx = 0; vPathIdx < iCount; vPathIdx++)
vPath.Append(@"..\");
return AddEndingDirectorySeparator(vPath.ToString());
}
/// <summary>
/// Splits list of folders into array of folder names.
///
/// This function doesn't recognize if the path ends with file name, or not.
/// If it does, the file name will be included on the list. It also doesn't
/// verify, if the path is valid.
///
/// If the path starts and/or ends with directory separator character, the
/// first and/or last array's element will be empty string.
/// </summary>
/// <param name="iPath">Path to split.</param>
/// <returns>Array of folder names.</returns>
public static string[] SplitPath(string iPath)
{
if (iPath == "")
return new string[] { };
return iPath.Split(Path.DirectorySeparatorChar);
}
/// <summary>
/// Adds a root path to the given path.
///
/// Before adding the root path, the function verifies if iCorrectPath
/// contains a root path itself.
///
/// It also verifies, if iPathToFix parameter starts with directory separator.
/// If not, iPathToFix is treated as relative path and no root path is added.
/// </summary>
/// <param name="iCorrectPath">Correct path, containing root path.</param>
/// <param name="iPathToFix">Path, which doesn't contain complete root path
/// and should be fixed.</param>
/// <returns>Fixed path containing root path.
///
/// If iPathToFix is relative path or iCorrectPath doesn't contain root path, not modified iPathToFix string
/// is returned.</returns>
public static string FixRootPath(string iCorrectPath, string iPathToFix)
{
if (
Path.IsPathRooted(iCorrectPath) &&
!iCorrectPath.StartsWith(Path.DirectorySeparatorChar.ToString()) &&
iPathToFix.StartsWith(Path.DirectorySeparatorChar.ToString())
)
return Combine(Path.GetPathRoot(iCorrectPath), iPathToFix);
else
return iPathToFix;
}
/// <summary>
/// Add one path to another. The paths are combined, even if the right path
/// starts with directory separator.
///
/// If the appended path starts with drive and path to which you append is not
/// empty - exception will be raised. If it's empty, the appended path will
/// be returned.
///
/// If the path to which you append is empty, the appended path will be
/// returned, too.
/// </summary>
/// <exception cref="ArgumentException"
/// <param name="iLeftPath">Left path to add to.</param>
/// <param name="iRightPath">Right path which will be added</param>
/// <returns>Appended path, if the path to which you append is empty.
///
/// Appended path if it's contains root path and the path to which you
/// append is empty.
///
/// If appended path doesn't contain root path, concatated path will be
/// returned.
/// </returns>
public static string Combine(string iLeftPath, string iRightPath)
{
iRightPath = iRightPath.TrimStart(Path.DirectorySeparatorChar);
if (Path.IsPathRooted(iRightPath) && iLeftPath != "")
throw new ArgumentException("Path containing root path can not be appended to another path");
else
if (Path.IsPathRooted(iRightPath))
return iRightPath;
iLeftPath = AddEndingDirectorySeparator(iLeftPath);
return iLeftPath + iRightPath;
}
/// <summary>
/// Removes ending directory separator character from the given path. It
/// doesn't remove the ending path, if the is root path - "c:\" or "\"
/// </summary>
/// <param name="iPath">Path from which ending directory separator
/// character should be removed.</param>
/// <returns>Path without ending directory separator character.</returns>
public static string RemoveEndingDirectorySeparator(string iPath)
{
if ((iPath.Length != 3 && iPath != @"\") || (iPath.Length == 3 && iPath[1] != ':'))
iPath = iPath.TrimEnd(Path.DirectorySeparatorChar);
return iPath;
}
/// <summary>
/// Adds ending directory separator character, if iPath doesn't contain it
/// already. Empty strings are ignored and returned without modification.
/// </summary>
/// <param name="iPath">Path to which ending separator character must be
/// added.</param>
/// <returns>Path containing ending directory separator character.</returns>
public static string AddEndingDirectorySeparator(string iPath)
{
if (iPath != "" && !iPath.EndsWith(Path.DirectorySeparatorChar.ToString()))
iPath += Path.DirectorySeparatorChar;
return iPath;
}
/// <summary>
/// Adds ending directory separator character to all paths on the given list, if the
/// given path doesn't contain it already. Empty strings are ignored and returned without
/// modification.
/// </summary>
/// <param name="iPaths">List of path to which directory separator must be added.</param>
/// <returns>New list containing paths with directory separator.</returns>
public static IList<string> AddEndingDirectorySeparator(IList<string> iPaths)
{
IList<string> vResult = new List<string>(iPaths.Count);
foreach (string vPath in iPaths)
vResult.Add(AddEndingDirectorySeparator(vPath));
return vResult;
}
/// <summary>
/// Checks, if two path have same root paths.
///
/// If one of the path doesn't contain root path, they are considered the
/// same, because one of them is considered to be relative path.
///
/// If both don't contain root paths, they are considered the same, because
/// both are relative and are assumed to be in the same root folder.
/// </summary>
/// <param name="iLeftPath">First path to compare.</param>
/// <param name="iRightPath">Second path to compare.</param>
/// <returns>True if root paths and they are the same. False otherwise.</returns>
public static bool HaveSameRoots(string iLeftPath, string iRightPath)
{
return !((Path.IsPathRooted(iLeftPath)) &&
(Path.IsPathRooted(iRightPath)) &&
(Path.GetPathRoot(iLeftPath).ToLower() != Path.GetPathRoot(iRightPath).ToLower()));
}
/// <summary>
/// Compares two arrays of folder names and returns the index of the first
/// folder, which is different. iLeftCompare is treated as primary.
///
/// If arrays contain different number of elements, the last index in
/// iLeftCompare or iRightCompare will be returned, depending which one is
/// lower.
///
/// This function is case insensitive.
/// </summary>
/// <param name="iLeftCompare">Main array for the comparision.</param>
/// <param name="iRightCompare">Compared array of folders.</param>
/// <returns>Index of first different folder in given arrays.</returns>
public static int GetFirstDifferentFolderIdx(string[] iLeftCompare, string[] iRightCompare)
{
int vFolderIdx = 0;
while (
vFolderIdx < iLeftCompare.Length &&
vFolderIdx < iRightCompare.Length &&
iLeftCompare[vFolderIdx].ToLower() == iRightCompare[vFolderIdx].ToLower()
)
vFolderIdx++;
return vFolderIdx;
}
/// <summary>
/// Validates, if the given path is a valid path.
/// </summary>
/// <param name="iPath">Path to validate.</param>
/// <returns>true, if path is valid. false, if path is invalid.</returns>
public static bool IsValidPath(string iPath)
{
return Directory.Exists(iPath);
}
/// <summary>
/// Removes all invalid paths from the given list of paths.
/// </summary>
/// <param name="iPaths">List of paths to validate.</param>
/// <returns>New list, containing only valid paths.</returns>
public static IList<string> RemoveInvalidPaths(IList<string> iPaths)
{
List<string> vResult = new List<string>();
foreach (string vPath in iPaths)
if (IsValidPath(vPath))
vResult.Add(vPath);
return vResult;
}
/// <summary>
/// Normalizes given path list, by:
/// - making all paths lower case
/// - removing invalid and empty paths
/// - removing duplicates
/// - adding directory separator to each path
/// </summary>
/// <param name="iPaths"></param>
/// <returns></returns>
public static IList<string> Normalize(IList<string> iPaths)
{
IList<string> vResult = RemoveInvalidPaths(iPaths);
vResult = AddEndingDirectorySeparator(vResult);
vResult = StringListUtils.Normalize(vResult);
return vResult;
}
}
}
@@ -0,0 +1,146 @@
using System;
using System.IO;
using DelphiProjectHandler.Dialogs;
namespace DelphiProjectHandler.Dialogs
{
public class RelativePath
{
/// <summary>
/// Changes the given path to relative path according to given base folder.
/// It doesn't validates, if the calculation may be made.
/// </summary>
/// <param name="iBasePath">Base folder for the path.</param>
/// <param name="iPath">Folder which must be changed to relative.</param>
/// <returns>Relative path according to base folder.</returns>
private static string BuildRelativePath(string iBasePath, string iPath)
{
string[] vBaseDirs = PathUtils.SplitPath(iBasePath);
string[] vRelativeDirs = PathUtils.SplitPath(iPath);
int vFolderIdx = PathUtils.GetFirstDifferentFolderIdx(vBaseDirs, vRelativeDirs);
string vBasePath = PathUtils.BuildGoUpPath(vBaseDirs.Length - vFolderIdx);
string vRelativePathSuffix = PathUtils.ConcatFolders(vFolderIdx, vRelativeDirs);
return Path.Combine(vBasePath, vRelativePathSuffix);
}
/// <summary>
/// Checks, if the given path is can be made relative. Path may not be changed
/// to relative if:
///
/// - Base path is rooted path and validated path is not. Validated path
/// may not be changed, because it doesn't contain root information and
/// the starting point for relative path calculation can not be taken.
/// Validated path is considered to be relative path already.
///
/// - Base path is not rooted path and validated path is rooted path.
/// It's similar to previous case. The starting point for relative path
/// calculations may not be taken.
/// </summary>
/// <param name="iBasePath">Based path used for validation.</param>
/// <param name="iPath">Validated path.</param>
/// <returns>True, if validated path can be made relative to the base
/// folder. False otherwise.</returns>
private static bool CanBeRelative(string iBasePath, string iPath)
{
return
!(
(Path.IsPathRooted(iBasePath) && !Path.IsPathRooted(iPath)) ||
(!Path.IsPathRooted(iBasePath) && Path.IsPathRooted(iPath))
);
}
/// <summary>
/// Calculates path relative to the base folder. As addition it
/// normalizes given paths, so the relative path can be calculated. It also
/// checks, if relative path can be calculated. If not, it returns iPath.
///
/// The relative path may not be calculated, if:
/// - root path of base and converted paths are different
/// - base path is rooted while converted path is not
/// - converted path is rooted while base path is not.
/// </summary>
/// <param name="iBasePath">Base path for the calculation.</param>
/// <param name="iPath">Path that should be changed to relative.</param>
/// <returns>Relative path, if possible. If not, iPath is returned.</returns>
protected static string DoGetRelativePath(string iBasePath, string iPath)
{
if (iPath == "")
return iBasePath;
iBasePath = PathUtils.RemoveEndingDirectorySeparator(iBasePath);
iPath = PathUtils.RemoveEndingDirectorySeparator(iPath);
iBasePath = PathUtils.FixRootPath(iPath, iBasePath);
iPath = PathUtils.FixRootPath(iBasePath, iPath);
if (!PathUtils.HaveSameRoots(iBasePath, iPath) || !CanBeRelative(iBasePath, iPath))
return iPath;
return BuildRelativePath(iBasePath, iPath);
}
/// <summary>
/// Changes path to be relative to the base folder. It checks, if relative
/// path can be calculated. If not, it returns iPath.
///
/// The relative path may not be calculated, if:
/// - root path of base and converted paths are different
/// - base path is rooted while converted path is not
/// - converted path is rooted while base path is not.
/// </summary>
/// <param name="iBasePath">Base path for the calculation.</param>
/// <param name="iPath">Path that should be changed to relative.</param>
/// <returns>Relative path, if possible. If not, iPath is returned.
///
/// The path is always ended with directory separator character.</returns>
public static string GetRelativePath(string iBasePath, string iPath)
{
return PathUtils.AddEndingDirectorySeparator(DoGetRelativePath(iBasePath, iPath));
}
/// <summary>
/// Changes filename to be relative to the base filename. It checks, if
/// relative path can be calculated. If not, it returns iFilename.
///
/// The relative filename may not be calculated, if:
/// - root path of base and converted filenames are different
/// - base filename is rooted while converted filename is not
/// - converted filename is rooted while base filename is not.
/// </summary>
/// <param name="iBaseFileName">Base filename for the calculation.</param>
/// <param name="iFileName">Filename that should be changed to relative.</param>
/// <returns>Relative filename, if possible. If not, iFileName is returned.</returns>
public static string GetRelativeFileName(string iBaseFileName, string iFileName)
{
if (iFileName.Equals(""))
return "";
string vBasePath = Path.GetDirectoryName(iBaseFileName);
return GetRelativeFilenameByFolder(vBasePath, iFileName);
}
/// <summary>
/// Changes filename to be relative to the base path. It checks, if
/// relative path can be calculated. If not, it returns iPath.
///
/// The relative filename may not be calculated, if:
/// - root path of base and converted paths are different
/// - base path is rooted while converted filename is not
/// - converted filename is rooted while base path is not.
/// </summary>
/// <param name="iBaseFileName">Base filename for the calculation.</param>
/// <param name="iFileName">Filename that should be changed to relative.</param>
/// <returns>Relative filename, if possible. If not, iFileName is returned.</returns>
public static string GetRelativeFilenameByFolder(string iBasePath, string iFileName)
{
string vPath = Path.GetDirectoryName(iFileName);
string vFileName = Path.GetFileName(iFileName);
return Path.Combine(DoGetRelativePath(iBasePath, vPath), vFileName);
}
}
}
Loaded 100 of 133 files, more files were not shown because too many files have changed in this diff. Show more