From 3625a8a2362883b97da5b31ff6a590a3cc42ebf8 Mon Sep 17 00:00:00 2001 From: "Joel W. Reed" Date: Sat, 1 Dec 2007 21:01:42 -0500 Subject: [PATCH] add.OpenTF.Common --- class/OpenTF.Common/FileType.cs | 109 ++++++++++++++++++++++++++ class/OpenTF.Common/Gtk.TeamFoundation.csproj | 88 +++++++++++++++++++++ class/OpenTF.Common/Makefile | 24 ++++++ class/OpenTF.Common/NoFileType.cs | 38 +++++++++ 4 files changed, 259 insertions(+) create mode 100644 class/OpenTF.Common/FileType.cs create mode 100644 class/OpenTF.Common/Gtk.TeamFoundation.csproj create mode 100644 class/OpenTF.Common/Makefile create mode 100644 class/OpenTF.Common/NoFileType.cs diff --git a/class/OpenTF.Common/FileType.cs b/class/OpenTF.Common/FileType.cs new file mode 100644 index 0000000..984643e --- /dev/null +++ b/class/OpenTF.Common/FileType.cs @@ -0,0 +1,109 @@ +// +// filetype.cs +// +// Authors: +// Joel Reed (joelwreed@gmail.com) +// + +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +using System; +using System.Collections.Generic; +using System.IO; +using System.Runtime.InteropServices; +using Mono.Unix; + +class FileTypeDatabase +{ + [DllImport("magic")] + private extern static IntPtr magic_open(int flags); + + [DllImport("magic")] + private extern static void magic_close(IntPtr magic_cookie); + + [DllImport("magic")] + private extern static IntPtr magic_file(IntPtr magic_cookie, string filename); + + [DllImport("magic")] + private extern static int magic_load(IntPtr magic_cookie, IntPtr x); + + private static IntPtr _magic = IntPtr.Zero; + + static FileTypeDatabase() + { + _magic = magic_open(0); + if (_magic == IntPtr.Zero) + { + Console.WriteLine("Warning: failed to open libmagic database"); + return; + } + + magic_load(_magic, IntPtr.Zero); + } + + ~FileTypeDatabase() + { + if (_magic != IntPtr.Zero) + magic_close(_magic); + } + + public static bool ShouldBeExecutable(string filename) + { + if (_magic == IntPtr.Zero) return false; + string desc = Marshal.PtrToStringAuto(magic_file(_magic, filename)); + if (String.IsNullOrEmpty(desc)) + { + Console.WriteLine("Error querying file type for " + filename); + return false; + } + + return desc.Contains("executable"); + } + + public static void MakeExecutable(string filename) + { + Mono.Unix.Native.Stat stat; + if (0 == Mono.Unix.Native.Syscall.stat(filename, out stat)) + { + Mono.Unix.Native.FilePermissions fp = stat.st_mode | Mono.Unix.Native.FilePermissions.S_IXUSR; + Mono.Unix.Native.Syscall.chmod(filename, fp); + } + } + + public static void SetPermissions(List fileList) + { + Console.Write("Setting permissions..."); + + int i = 0; + foreach (string file in fileList) + { + if (0 == (i % 100)) Console.Write("."); + i++; + + if (! ShouldBeExecutable(file)) continue; + MakeExecutable(file); + } + + Console.WriteLine(" done!"); + } +} + diff --git a/class/OpenTF.Common/Gtk.TeamFoundation.csproj b/class/OpenTF.Common/Gtk.TeamFoundation.csproj new file mode 100644 index 0000000..a87fe17 --- /dev/null +++ b/class/OpenTF.Common/Gtk.TeamFoundation.csproj @@ -0,0 +1,88 @@ + + + Debug + AnyCPU + {B0953653-A461-4338-BDAE-91DA9C3583AA} + Library + false + Gtk.TeamFoundation + Gtk.TeamFoundation + + + true + full + false + ..\lib\net_2_0\ + DEBUG;TRACE + + + pdbonly + true + ..\lib\net_2_0\ + TRACE + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {E0953653-D640-4338-BDAE-91DA9C3583F8} + Microsoft.TeamFoundation.Common + + + {B0953653-D640-4338-BDAE-91DA9C3583F8} + Microsoft.TeamFoundation.Client + + + {B0953653-D640-4338-BDAE-91DA9C3583F8} + Microsoft.TeamFoundation + + + {A0953653-D640-4338-BDAE-91DA9C3583F8} + Microsoft.TeamFoundation.VersionControl.Common + + + {F0953653-D640-4338-BDAE-91DA9C3583F8} + Microsoft.TeamFoundation.VersionControl.Client + + + + + + + diff --git a/class/OpenTF.Common/Makefile b/class/OpenTF.Common/Makefile new file mode 100644 index 0000000..e6945db --- /dev/null +++ b/class/OpenTF.Common/Makefile @@ -0,0 +1,24 @@ +thisdir = tools/Gtk.TeamFoundation +include ../../build/rules.make + +LIBRARY = Gtk.TeamFoundation.dll +RESOURCES = $(wildcard icons/*.png) + +LIB_MCS_FLAGS = /unsafe /pkg:gtk-sharp-2.0 /r:Microsoft.TeamFoundation.dll /r:Microsoft.TeamFoundation.Common.dll /r:Microsoft.TeamFoundation.Client.dll /r:Microsoft.TeamFoundation.VersionControl.Client.dll /r:Microsoft.TeamFoundation.VersionControl.Common.dll + +ifeq ($(HAVE_SYNTAX_HIGHLIGHTING),no) +EXTRA_SOURCES += NoSourceView.cs +else +EXTRA_SOURCES += SourceView.cs +LOCAL_MCS_FLAGS += -pkg:gtksourceview-sharp-2.0 -pkg:gnome-vfs-sharp-2.0 -d:HAVE_SYNTAX_HIGHLIGHTING +endif + +res: + echo $(RESOURCES) + +LOCAL_MCS_FLAGS += $(RESOURCES:%=/resource:%) + +TEST_MCS_FLAGS = $(LIB_MCS_FLAGS) + +include ../../build/library.make + diff --git a/class/OpenTF.Common/NoFileType.cs b/class/OpenTF.Common/NoFileType.cs new file mode 100644 index 0000000..063e065 --- /dev/null +++ b/class/OpenTF.Common/NoFileType.cs @@ -0,0 +1,38 @@ +// +// nofiletype.cs +// +// Authors: +// Joel Reed (joelwreed@gmail.com) +// + +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +using System; +using System.Collections.Generic; + +class FileTypeDatabase +{ + public static void SetPermissions(List x) + { + } +} + -- 2.11.4.GIT