コード例 #1
1
ファイル: MsiDiffEngine.cs プロジェクト: zooba/wix3
        protected bool GetStreamsDiff(Database db1, Database db2, string[] options, TextWriter diffOutput, string linePrefix, IDiffEngineFactory diffFactory)
        {
            bool difference = false;

            IList<string> streams1List = db1.ExecuteStringQuery("SELECT `Name` FROM `_Streams`");
            IList<string> streams2List = db2.ExecuteStringQuery("SELECT `Name` FROM `_Streams`");
            string[] streams1 = new string[streams1List.Count];
            string[] streams2 = new string[streams2List.Count];
            streams1List.CopyTo(streams1, 0);
            streams2List.CopyTo(streams2, 0);

            IComparer caseInsComp = CaseInsensitiveComparer.Default;
            Array.Sort(streams1, caseInsComp);
            Array.Sort(streams2, caseInsComp);

            for (int i1 = 0, i2 = 0; i1 < streams1.Length || i2 < streams2.Length; )
            {
                int comp;
                if (i1 == streams1.Length)
                {
                    comp = 1;
                }
                else if (i2 == streams2.Length)
                {
                    comp = -1;
                }
                else
                {
                    comp = caseInsComp.Compare(streams1[i1], streams2[i2]);
                }
                if(comp < 0)
                {
                    diffOutput.WriteLine("{0}< {1}", linePrefix, streams1[i1]);
                    i1++;
                    difference = true;
                }
                else if(comp > 0)
                {
                    diffOutput.WriteLine("{0}> {1}", linePrefix, streams2[i2]);
                    i2++;
                    difference = true;
                }
                else
                {
                    if(streams1[i1] != ("" + ((char)5) + "SummaryInformation"))
                    {
                        string tempFile1 = Path.GetTempFileName();
                        string tempFile2 = Path.GetTempFileName();

                        using (View view = db1.OpenView(String.Format("SELECT `Data` FROM `_Streams` WHERE `Name` = '{0}'", streams1[i1])))
                        {
                            view.Execute();

                            using (Record rec = view.Fetch())
                            {
                                rec.GetStream(1, tempFile1);
                            }
                        }

                        using (View view = db2.OpenView(String.Format("SELECT `Data` FROM `_Streams` WHERE `Name` = '{0}'", streams2[i2])))
                        {
                            view.Execute();

                            using (Record rec = view.Fetch())
                            {
                                rec.GetStream(1, tempFile2);
                            }
                        }

                        IDiffEngine diffEngine = diffFactory.GetDiffEngine(tempFile1, tempFile2, options);
                        StringWriter sw = new StringWriter();
                        if(diffEngine.GetDiff(tempFile1, tempFile2, options, sw, linePrefix + "    ", diffFactory))
                        {
                            diffOutput.WriteLine("{0}{1}", linePrefix, streams1[i1]);
                            diffOutput.Write(sw.ToString());
                            difference = true;
                        }

                        File.Delete(tempFile1);
                        File.Delete(tempFile2);
                    }
                    i1++;
                    i2++;
                }
            }

            return difference;
        }
コード例 #2
0
ファイル: DirectoryDiffEngine.cs プロジェクト: Jeremiahf/wix3
		public bool GetDiff(string diffInput1, string diffInput2, string[] options, TextWriter diffOutput, string linePrefix, IDiffEngineFactory diffFactory)
		{
			bool difference = false;
			IComparer caseInsComp = CaseInsensitiveComparer.Default;

			string[] files1 = Directory.GetFiles(diffInput1);
			string[] files2 = Directory.GetFiles(diffInput2);
			for(int i1 = 0; i1 < files1.Length; i1++)
			{
				files1[i1] = Path.GetFileName(files1[i1]);
			}
			for(int i2 = 0; i2 < files2.Length; i2++)
			{
				files2[i2] = Path.GetFileName(files2[i2]);
			}
			Array.Sort(files1, caseInsComp);
			Array.Sort(files2, caseInsComp);

			for(int i1 = 0, i2 = 0; i1 < files1.Length || i2 < files2.Length; )
			{
				int comp;
				if(i1 == files1.Length)
				{
					comp = 1;
				}
				else if(i2 == files2.Length)
				{
					comp = -1;
				}
				else
				{
					comp = caseInsComp.Compare(files1[i1], files2[i2]);
				}
				if(comp < 0)
				{
					diffOutput.WriteLine("{0}< {1}", linePrefix, files1[i1]);
					i1++;
					difference = true;
				}
				else if(comp > 0)
				{
					diffOutput.WriteLine("{0}> {1}", linePrefix, files2[i2]);
					i2++;
					difference = true;
				}
				else
				{
					string file1 = Path.Combine(diffInput1, files1[i1]);
					string file2 = Path.Combine(diffInput2, files2[i2]);
					IDiffEngine diffEngine = diffFactory.GetDiffEngine(file1, file2, options);
					StringWriter sw = new StringWriter();
					if(diffEngine.GetDiff(file1, file2, options, sw, linePrefix + "    ", diffFactory))
					{
						diffOutput.WriteLine("{0}{1}", linePrefix, files1[i1]);
						diffOutput.Write(sw.ToString());
						difference = true;
					}
					i1++;
					i2++;
				}
			}

			string[] dirs1 = Directory.GetDirectories(diffInput1);
			string[] dirs2 = Directory.GetDirectories(diffInput2);
			for(int i1 = 0; i1 < dirs1.Length; i1++)
			{
				dirs1[i1] = Path.GetFileName(dirs1[i1]);
			}
			for(int i2 = 0; i2 < dirs2.Length; i2++)
			{
				dirs2[i2] = Path.GetFileName(dirs2[i2]);
			}
			Array.Sort(dirs1, caseInsComp);
			Array.Sort(dirs2, caseInsComp);

			for(int i1 = 0, i2 = 0; i1 < dirs1.Length || i2 < dirs2.Length; )
			{
				int comp;
				if(i1 == dirs1.Length)
				{
					comp = 1;
				}
				else if(i2 == dirs2.Length)
				{
					comp = -1;
				}
				else
				{
					comp = caseInsComp.Compare(dirs1[i1], dirs2[i2]);
				}
				if(comp < 0)
				{
					diffOutput.WriteLine("{0}< {1}", linePrefix, dirs1[i1]);
					i1++;
					difference = true;
				}
				else if(comp > 0)
				{
					diffOutput.WriteLine("{0}> {1}", linePrefix, dirs2[i2]);
					i2++;
					difference = true;
				}
				else
				{
					string dir1 = Path.Combine(diffInput1, dirs1[i1]);
					string dir2 = Path.Combine(diffInput2, dirs2[i2]);
					IDiffEngine diffEngine = diffFactory.GetDiffEngine(dir1, dir2, options);
					StringWriter sw = new StringWriter();
					if(diffEngine.GetDiff(dir1, dir2, options, sw, linePrefix + "    ", diffFactory))
					{
						diffOutput.WriteLine("{0}{1}\\", linePrefix, dirs1[i1]);
						diffOutput.Write(sw.ToString());
						difference = true;
					}
					i1++;
					i2++;
				}
			}
			return difference;
		}
コード例 #3
0
        public bool GetDiff(string diffInput1, string diffInput2, string[] options, TextWriter diffOutput, string linePrefix, IDiffEngineFactory diffFactory)
        {
            bool      difference  = false;
            IComparer caseInsComp = CaseInsensitiveComparer.Default;

            string[] files1 = Directory.GetFiles(diffInput1);
            string[] files2 = Directory.GetFiles(diffInput2);
            for (int i1 = 0; i1 < files1.Length; i1++)
            {
                files1[i1] = Path.GetFileName(files1[i1]);
            }
            for (int i2 = 0; i2 < files2.Length; i2++)
            {
                files2[i2] = Path.GetFileName(files2[i2]);
            }
            Array.Sort(files1, caseInsComp);
            Array.Sort(files2, caseInsComp);

            for (int i1 = 0, i2 = 0; i1 < files1.Length || i2 < files2.Length;)
            {
                int comp;
                if (i1 == files1.Length)
                {
                    comp = 1;
                }
                else if (i2 == files2.Length)
                {
                    comp = -1;
                }
                else
                {
                    comp = caseInsComp.Compare(files1[i1], files2[i2]);
                }
                if (comp < 0)
                {
                    diffOutput.WriteLine("{0}< {1}", linePrefix, files1[i1]);
                    i1++;
                    difference = true;
                }
                else if (comp > 0)
                {
                    diffOutput.WriteLine("{0}> {1}", linePrefix, files2[i2]);
                    i2++;
                    difference = true;
                }
                else
                {
                    string       file1      = Path.Combine(diffInput1, files1[i1]);
                    string       file2      = Path.Combine(diffInput2, files2[i2]);
                    IDiffEngine  diffEngine = diffFactory.GetDiffEngine(file1, file2, options);
                    StringWriter sw         = new StringWriter();
                    if (diffEngine.GetDiff(file1, file2, options, sw, linePrefix + "    ", diffFactory))
                    {
                        diffOutput.WriteLine("{0}{1}", linePrefix, files1[i1]);
                        diffOutput.Write(sw.ToString());
                        difference = true;
                    }
                    i1++;
                    i2++;
                }
            }

            string[] dirs1 = Directory.GetDirectories(diffInput1);
            string[] dirs2 = Directory.GetDirectories(diffInput2);
            for (int i1 = 0; i1 < dirs1.Length; i1++)
            {
                dirs1[i1] = Path.GetFileName(dirs1[i1]);
            }
            for (int i2 = 0; i2 < dirs2.Length; i2++)
            {
                dirs2[i2] = Path.GetFileName(dirs2[i2]);
            }
            Array.Sort(dirs1, caseInsComp);
            Array.Sort(dirs2, caseInsComp);

            for (int i1 = 0, i2 = 0; i1 < dirs1.Length || i2 < dirs2.Length;)
            {
                int comp;
                if (i1 == dirs1.Length)
                {
                    comp = 1;
                }
                else if (i2 == dirs2.Length)
                {
                    comp = -1;
                }
                else
                {
                    comp = caseInsComp.Compare(dirs1[i1], dirs2[i2]);
                }
                if (comp < 0)
                {
                    diffOutput.WriteLine("{0}< {1}", linePrefix, dirs1[i1]);
                    i1++;
                    difference = true;
                }
                else if (comp > 0)
                {
                    diffOutput.WriteLine("{0}> {1}", linePrefix, dirs2[i2]);
                    i2++;
                    difference = true;
                }
                else
                {
                    string       dir1       = Path.Combine(diffInput1, dirs1[i1]);
                    string       dir2       = Path.Combine(diffInput2, dirs2[i2]);
                    IDiffEngine  diffEngine = diffFactory.GetDiffEngine(dir1, dir2, options);
                    StringWriter sw         = new StringWriter();
                    if (diffEngine.GetDiff(dir1, dir2, options, sw, linePrefix + "    ", diffFactory))
                    {
                        diffOutput.WriteLine("{0}{1}\\", linePrefix, dirs1[i1]);
                        diffOutput.Write(sw.ToString());
                        difference = true;
                    }
                    i1++;
                    i2++;
                }
            }
            return(difference);
        }
コード例 #4
0
ファイル: CabDiffEngine.cs プロジェクト: Jeremiahf/wix3
		public bool GetDiff(string diffInput1, string diffInput2, string[] options, TextWriter diffOutput, string linePrefix, IDiffEngineFactory diffFactory)
		{
			bool difference = false;
			IComparer caseInsComp = CaseInsensitiveComparer.Default;

			// TODO: Make this faster by extracting the whole cab at once.
			// TODO: Optimize for the match case by first comparing the whole cab files.

            CabInfo cab1 = new CabInfo(diffInput1);
            CabInfo cab2 = new CabInfo(diffInput2);
			IList<CabFileInfo> cabFilesList1 = cab1.GetFiles();
            IList<CabFileInfo> cabFilesList2 = cab2.GetFiles();
            CabFileInfo[] cabFiles1 = new CabFileInfo[cabFilesList1.Count];
            CabFileInfo[] cabFiles2 = new CabFileInfo[cabFilesList2.Count];
            cabFilesList1.CopyTo(cabFiles1, 0);
            cabFilesList2.CopyTo(cabFiles2, 0);
			string[] files1 = new string[cabFiles1.Length];
			string[] files2 = new string[cabFiles2.Length];
			for(int i1 = 0; i1 < cabFiles1.Length; i1++) files1[i1] = cabFiles1[i1].Name;
			for(int i2 = 0; i2 < cabFiles2.Length; i2++) files2[i2] = cabFiles2[i2].Name;
			Array.Sort(files1, cabFiles1, caseInsComp);
			Array.Sort(files2, cabFiles2, caseInsComp);


			for(int i1 = 0, i2 = 0; i1 < files1.Length || i2 < files2.Length; )
			{
				int comp;
				if(i1 == files1.Length)
				{
					comp = 1;
				}
				else if(i2 == files2.Length)
				{
					comp = -1;
				}
				else
				{
					comp = caseInsComp.Compare(files1[i1], files2[i2]);
				}
				if(comp < 0)
				{
					diffOutput.WriteLine("{0}< {1}", linePrefix, files1[i1]);
					i1++;
					difference = true;
				}
				else if(comp > 0)
				{
					diffOutput.WriteLine("{0}> {1}", linePrefix, files2[i2]);
					i2++;
					difference = true;
				}
				else
				{
					string tempFile1 = Path.GetTempFileName();
					string tempFile2 = Path.GetTempFileName();
					cabFiles1[i1].CopyTo(tempFile1, true);
					cabFiles2[i2].CopyTo(tempFile2, true);
					IDiffEngine diffEngine = diffFactory.GetDiffEngine(tempFile1, tempFile2, options);
					StringWriter sw = new StringWriter();
					if(diffEngine.GetDiff(tempFile1, tempFile2, options, sw, linePrefix + "    ", diffFactory))
					{
						diffOutput.WriteLine("{0}{1}", linePrefix, files1[i1]);
						diffOutput.Write(sw.ToString());
						difference = true;
					}

					File.SetAttributes(tempFile1, File.GetAttributes(tempFile1) & ~FileAttributes.ReadOnly);
					File.SetAttributes(tempFile2, File.GetAttributes(tempFile2) & ~FileAttributes.ReadOnly);
					try
					{
						File.Delete(tempFile1);
						File.Delete(tempFile2);
					}
					catch(IOException)
					{
#if DEBUG
						Console.WriteLine("Could not delete temporary files {0} and {1}", tempFile1, tempFile2);
#endif
					}
					i1++;
					i2++;
				}
			}

			return difference;
		}
コード例 #5
0
        public bool GetDiff(string diffInput1, string diffInput2, string[] options, TextWriter diffOutput, string linePrefix, IDiffEngineFactory diffFactory)
        {
            bool      difference  = false;
            IComparer caseInsComp = CaseInsensitiveComparer.Default;

            // TODO: Make this faster by extracting the whole cab at once.
            // TODO: Optimize for the match case by first comparing the whole cab files.

            CabInfo             cab1          = new CabInfo(diffInput1);
            CabInfo             cab2          = new CabInfo(diffInput2);
            IList <CabFileInfo> cabFilesList1 = cab1.GetFiles();
            IList <CabFileInfo> cabFilesList2 = cab2.GetFiles();

            CabFileInfo[] cabFiles1 = new CabFileInfo[cabFilesList1.Count];
            CabFileInfo[] cabFiles2 = new CabFileInfo[cabFilesList2.Count];
            cabFilesList1.CopyTo(cabFiles1, 0);
            cabFilesList2.CopyTo(cabFiles2, 0);
            string[] files1 = new string[cabFiles1.Length];
            string[] files2 = new string[cabFiles2.Length];
            for (int i1 = 0; i1 < cabFiles1.Length; i1++)
            {
                files1[i1] = cabFiles1[i1].Name;
            }
            for (int i2 = 0; i2 < cabFiles2.Length; i2++)
            {
                files2[i2] = cabFiles2[i2].Name;
            }
            Array.Sort(files1, cabFiles1, caseInsComp);
            Array.Sort(files2, cabFiles2, caseInsComp);


            for (int i1 = 0, i2 = 0; i1 < files1.Length || i2 < files2.Length;)
            {
                int comp;
                if (i1 == files1.Length)
                {
                    comp = 1;
                }
                else if (i2 == files2.Length)
                {
                    comp = -1;
                }
                else
                {
                    comp = caseInsComp.Compare(files1[i1], files2[i2]);
                }
                if (comp < 0)
                {
                    diffOutput.WriteLine("{0}< {1}", linePrefix, files1[i1]);
                    i1++;
                    difference = true;
                }
                else if (comp > 0)
                {
                    diffOutput.WriteLine("{0}> {1}", linePrefix, files2[i2]);
                    i2++;
                    difference = true;
                }
                else
                {
                    string tempFile1 = Path.GetTempFileName();
                    string tempFile2 = Path.GetTempFileName();
                    cabFiles1[i1].CopyTo(tempFile1, true);
                    cabFiles2[i2].CopyTo(tempFile2, true);
                    IDiffEngine  diffEngine = diffFactory.GetDiffEngine(tempFile1, tempFile2, options);
                    StringWriter sw         = new StringWriter();
                    if (diffEngine.GetDiff(tempFile1, tempFile2, options, sw, linePrefix + "    ", diffFactory))
                    {
                        diffOutput.WriteLine("{0}{1}", linePrefix, files1[i1]);
                        diffOutput.Write(sw.ToString());
                        difference = true;
                    }

                    File.SetAttributes(tempFile1, File.GetAttributes(tempFile1) & ~FileAttributes.ReadOnly);
                    File.SetAttributes(tempFile2, File.GetAttributes(tempFile2) & ~FileAttributes.ReadOnly);
                    try
                    {
                        File.Delete(tempFile1);
                        File.Delete(tempFile2);
                    }
                    catch (IOException)
                    {
#if DEBUG
                        Console.WriteLine("Could not delete temporary files {0} and {1}", tempFile1, tempFile2);
#endif
                    }
                    i1++;
                    i2++;
                }
            }

            return(difference);
        }
コード例 #6
0
        protected bool GetStreamsDiff(Database db1, Database db2, string[] options, TextWriter diffOutput, string linePrefix, IDiffEngineFactory diffFactory)
        {
            bool difference = false;

            IList <string> streams1List = db1.ExecuteStringQuery("SELECT `Name` FROM `_Streams`");
            IList <string> streams2List = db2.ExecuteStringQuery("SELECT `Name` FROM `_Streams`");

            string[] streams1 = new string[streams1List.Count];
            string[] streams2 = new string[streams2List.Count];
            streams1List.CopyTo(streams1, 0);
            streams2List.CopyTo(streams2, 0);

            IComparer caseInsComp = CaseInsensitiveComparer.Default;

            Array.Sort(streams1, caseInsComp);
            Array.Sort(streams2, caseInsComp);

            for (int i1 = 0, i2 = 0; i1 < streams1.Length || i2 < streams2.Length;)
            {
                int comp;
                if (i1 == streams1.Length)
                {
                    comp = 1;
                }
                else if (i2 == streams2.Length)
                {
                    comp = -1;
                }
                else
                {
                    comp = caseInsComp.Compare(streams1[i1], streams2[i2]);
                }
                if (comp < 0)
                {
                    diffOutput.WriteLine("{0}< {1}", linePrefix, streams1[i1]);
                    i1++;
                    difference = true;
                }
                else if (comp > 0)
                {
                    diffOutput.WriteLine("{0}> {1}", linePrefix, streams2[i2]);
                    i2++;
                    difference = true;
                }
                else
                {
                    if (streams1[i1] != ("" + ((char)5) + "SummaryInformation"))
                    {
                        string tempFile1 = Path.GetTempFileName();
                        string tempFile2 = Path.GetTempFileName();

                        using (View view = db1.OpenView(String.Format("SELECT `Data` FROM `_Streams` WHERE `Name` = '{0}'", streams1[i1])))
                        {
                            view.Execute();

                            using (Record rec = view.Fetch())
                            {
                                rec.GetStream(1, tempFile1);
                            }
                        }

                        using (View view = db2.OpenView(String.Format("SELECT `Data` FROM `_Streams` WHERE `Name` = '{0}'", streams2[i2])))
                        {
                            view.Execute();

                            using (Record rec = view.Fetch())
                            {
                                rec.GetStream(1, tempFile2);
                            }
                        }

                        IDiffEngine  diffEngine = diffFactory.GetDiffEngine(tempFile1, tempFile2, options);
                        StringWriter sw         = new StringWriter();
                        if (diffEngine.GetDiff(tempFile1, tempFile2, options, sw, linePrefix + "    ", diffFactory))
                        {
                            diffOutput.WriteLine("{0}{1}", linePrefix, streams1[i1]);
                            diffOutput.Write(sw.ToString());
                            difference = true;
                        }

                        File.Delete(tempFile1);
                        File.Delete(tempFile2);
                    }
                    i1++;
                    i2++;
                }
            }

            return(difference);
        }