Initial project's source code check-in.

This commit is contained in:
ptsurbeleu 2011-07-13 16:07:32 -07:00
commit b03b0b373f
4573 changed files with 981205 additions and 0 deletions

View file

@ -0,0 +1,75 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace WebsitePanel.FilesComparer
{
public class CRC32
{
private UInt32[] crc32Table;
private const int BUFFER_SIZE = 1024;
/// <summary>
/// Returns the CRC32 for the specified stream.
/// </summary>
/// <param name="stream">The stream to calculate the CRC32 for</param>
/// <returns>An unsigned integer containing the CRC32 calculation</returns>
public UInt32 GetCrc32(System.IO.Stream stream)
{
unchecked
{
UInt32 crc32Result;
crc32Result = 0xFFFFFFFF;
byte[] buffer = new byte[BUFFER_SIZE];
int readSize = BUFFER_SIZE;
int count = stream.Read(buffer, 0, readSize);
while (count > 0)
{
for (int i = 0; i < count; i++)
{
crc32Result = ((crc32Result) >> 8) ^ crc32Table[(buffer[i]) ^ ((crc32Result) & 0x000000FF)];
}
count = stream.Read(buffer, 0, readSize);
}
return ~crc32Result;
}
}
/// <summary>
/// Construct an instance of the CRC32 class, pre-initialising the table
/// for speed of lookup.
/// </summary>
public CRC32()
{
unchecked
{
// This is the official polynomial used by CRC32 in PKZip.
// Often the polynomial is shown reversed as 0x04C11DB7.
UInt32 dwPolynomial = 0xEDB88320;
UInt32 i, j;
crc32Table = new UInt32[256];
UInt32 dwCrc;
for (i = 0; i < 256; i++)
{
dwCrc = i;
for (j = 8; j > 0; j--)
{
if ((dwCrc & 1) == 1)
{
dwCrc = (dwCrc >> 1) ^ dwPolynomial;
}
else
{
dwCrc >>= 1;
}
}
crc32Table[i] = dwCrc;
}
}
}
}
}

View file

@ -0,0 +1,241 @@
using System;
using System.Xml;
using System.IO;
using System.Collections.Generic;
using System.Text;
namespace WebsitePanel.FilesComparer
{
class Program
{
static string FilesToExclude;
static void Main(string[] args)
{
if (args.Length < 3 && args.Length > 4)
{
Console.WriteLine("Usage: Diff.exe [sourceDir] [targetDir] [resultDir] [/ex:fileToExclude.ext,fileToExclude.ext]");
Console.WriteLine("Example: Diff.exe c:\\WSP1 c:\\WSP2 c:\\result /ex:Default.aspx,Error.htm");
Console.WriteLine("NOTE: Please make sure all parameters containg spaces are enclosed in quotes.");
return;
}
try
{
//
if (args.Length == 4)
FilesToExclude = args[3];
//
CreateComparison(args[0], args[1], args[2]);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
static void CreateComparison(string sourcePath, string targetPath, string pathToSave)
{
DeleteDir(pathToSave, false);
string[] sourceFiles = GetFiles(sourcePath);
string[] targetFiles = GetFiles(targetPath);
if (sourcePath.EndsWith(@"\"))
sourcePath = sourcePath.Substring(0, sourcePath.Length - 1);
if (targetPath.EndsWith(@"\"))
targetPath = targetPath.Substring(0, targetPath.Length - 1);
int sIndexOf = sourcePath.Length;
int tIndexOf = targetPath.Length;
List<string> filesA = new List<string>();
List<string> filesAlower = new List<string>();
List<string> filesB = new List<string>();
List<string> filesBlower = new List<string>();
List<string> excludes = new List<string>();
excludes.Add("bin");
excludes.Add("setup");
string file;
foreach (string sourceFile in sourceFiles)
{
file = sourceFile.Substring(sIndexOf);
if (file.StartsWith("\\"))
file = file.TrimStart('\\');
filesA.Add(file);
filesAlower.Add(file.ToLower());
}
foreach (string targetFile in targetFiles)
{
file = targetFile.Substring(tIndexOf);
if (file.StartsWith("\\"))
file = file.TrimStart('\\');
filesB.Add(file);
filesBlower.Add(file.ToLower());
}
//files to delete
foreach (string fileA in filesA)
{
file = fileA.ToLower();
if (file.StartsWith("bin\\") || file.StartsWith("setup\\") || file.EndsWith("sitesettings.config"))
{
continue;
}
if (filesBlower.IndexOf(file) == -1)
excludes.Add(fileA);
}
//files to copy
foreach (string fileB in filesB)
{
file = fileB.ToLower();
if (file.EndsWith("sitesettings.config"))
continue;
if (file.StartsWith("bin\\") || file.StartsWith("setup\\"))
{
//copy all new files from bin and setup folders
CopyFile(targetPath, fileB, pathToSave);
continue;
}
//try to find a new file in the list of old files
int index = filesAlower.IndexOf(file);
if (index == -1)
{
//old files do not contain new file - we need to copy a new file
CopyFile(targetPath, fileB, pathToSave);
}
else
{
//old files contain the same file - we need to compare files
string oldFile = Path.Combine(sourcePath, filesA[index]);
string newFile = Path.Combine(targetPath, fileB);
if (Diff(oldFile, newFile))
{
//files are not equal - we need to delete old file and copy a new file
excludes.Add(filesA[index]);
CopyFile(targetPath, fileB, pathToSave);
}
}
}
string deleteFile = Path.Combine(pathToSave, "setup\\delete.txt");
WriteFilesToDelete(deleteFile, excludes);
}
private static void DeleteDir(string path, bool delRoot)
{
if (Directory.Exists(path))
{
string[] files = Directory.GetFiles(path);
foreach (string file in files)
{
File.Delete(file);
}
string[] dirs = Directory.GetDirectories(path);
foreach (string dir in dirs)
{
DeleteDir(dir, true);
}
if (delRoot)
{
Directory.Delete(path);
}
}
}
private static bool Diff(string oldFile, string newFile)
{
FileInfo fi1 = new FileInfo(oldFile);
FileInfo fi2 = new FileInfo(newFile);
if (fi1.Length != fi2.Length)
return true;
UInt32 hash1 = GetCRC32(oldFile);
UInt32 hash2 = GetCRC32(newFile);
return (hash1 != hash2);
}
private static UInt32 GetCRC32(string oldFile)
{
CRC32 c = new CRC32();
UInt32 crc = 0;
using (FileStream f = new FileStream(oldFile, FileMode.Open, FileAccess.Read, FileShare.Read, 8192))
{
crc = c.GetCrc32(f);
}
return crc;
}
private static void CopyFile(string sourceDir, string fileName, string targetDir)
{
string destFile = Path.Combine(targetDir, fileName);
string dir = Path.GetDirectoryName(destFile);
if (!Directory.Exists(dir))
{
Directory.CreateDirectory(dir);
}
string sourceFile = Path.Combine(sourceDir, fileName);
File.Copy(sourceFile, destFile);
}
private static void WriteFilesToDelete(string fileName, List<string> list)
{
string dir = Path.GetDirectoryName(fileName);
if (!Directory.Exists(dir))
{
Directory.CreateDirectory(dir);
}
using (StreamWriter sw = new StreamWriter(fileName))
{
// Write all files received
foreach (string file in list)
{
sw.WriteLine(file);
}
}
}
static string[] GetFiles(string path)
{
var filesListRaw = Directory.GetFiles(path, "*.*", SearchOption.AllDirectories);
// See if the switch is specified
bool useAllFiles = String.IsNullOrEmpty(FilesToExclude);
// Switch is not empty so do the check
if (!useAllFiles)
{
var resultList = new List<string>();
//
foreach (string file in filesListRaw)
{
// Verify to include the file
if (FilesToExclude.IndexOf(Path.GetFileName(file), StringComparison.OrdinalIgnoreCase) >= 0)
continue;
//
resultList.Add(file);
}
//
return resultList.ToArray();
}
//
return filesListRaw;
}
}
}

View file

@ -0,0 +1,29 @@
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("WebsitePanel.FilesComparer")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyProduct("WebsitePanel.FilesComparer")]
[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("235a18ac-7560-49ac-96fc-a01d5f9a862d")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//

View file

@ -0,0 +1,99 @@
<?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>8.0.50727</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{85315088-B2F0-439B-9360-4D5BECE630DB}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>WebsitePanel.FilesComparer</RootNamespace>
<AssemblyName>diff</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileUpgradeFlags>
</FileUpgradeFlags>
<OldToolsVersion>2.0</OldToolsVersion>
<UpgradeBackupLocation />
<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>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\..\..\Tools\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\..\..\Tools\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
<UseVSHostingProcess>false</UseVSHostingProcess>
</PropertyGroup>
<PropertyGroup>
<StartupObject>WebsitePanel.FilesComparer.Program</StartupObject>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\VersionInfo.cs">
<Link>VersionInfo.cs</Link>
</Compile>
<Compile Include="CRC32.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.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.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>
<None Include="app.config" />
</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>

View file

@ -0,0 +1,3 @@
<?xml version="1.0"?>
<configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>