Browse Source

added functions to set read only flag or reset it

git-svn-id: svn://svn.code.sf.net/p/ditto-cp/code/trunk@485 595ec19a-5cb4-439b-94a8-42fb3063c22c
sabrogden 15 years ago
parent
commit
f2a3554fad

+ 6 - 2
Addins/DittoUtil/DittoUtil.vcxproj

@@ -116,17 +116,19 @@
     </ResourceCompile>
   </ItemDefinitionGroup>
   <ItemGroup>
+    <ClCompile Include="..\..\Shared\TextConvert.cpp" />
+    <ClCompile Include="..\..\Shared\Tokenizer.cpp" />
     <ClCompile Include="DialogResizer.cpp" />
     <ClCompile Include="DittoUtil.cpp" />
     <ClCompile Include="Exports.cpp" />
     <ClCompile Include="PasteAnyAsText.cpp" />
     <ClCompile Include="PasteImageAsHtmlImage.cpp" />
+    <ClCompile Include="ReadOnlyFlag.cpp" />
     <ClCompile Include="SelectPasteFormat.cpp" />
     <ClCompile Include="stdafx.cpp">
       <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
       <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
     </ClCompile>
-    <ClCompile Include="TextConvert.cpp" />
   </ItemGroup>
   <ItemGroup>
     <None Include="DittoUtil.def" />
@@ -134,15 +136,17 @@
     <None Include="ReadMe.txt" />
   </ItemGroup>
   <ItemGroup>
+    <ClInclude Include="..\..\Shared\TextConvert.h" />
+    <ClInclude Include="..\..\Shared\Tokenizer.h" />
     <ClInclude Include="DialogResizer.h" />
     <ClInclude Include="DittoUtil.h" />
     <ClInclude Include="Exports.h" />
     <ClInclude Include="PasteAnyAsText.h" />
     <ClInclude Include="PasteImageAsHtmlImage.h" />
+    <ClInclude Include="ReadOnlyFlag.h" />
     <ClInclude Include="Resource.h" />
     <ClInclude Include="SelectPasteFormat.h" />
     <ClInclude Include="stdafx.h" />
-    <ClInclude Include="TextConvert.h" />
   </ItemGroup>
   <ItemGroup>
     <ResourceCompile Include="DittoUtil.rc" />

+ 34 - 1
Addins/DittoUtil/Exports.cpp

@@ -2,6 +2,7 @@
 #include ".\exports.h"
 #include "PasteAnyAsText.h"
 #include ".\pasteimageashtmlimage.h"
+#include "ReadOnlyFlag.h"
 
 
 bool DittoAddin(const CDittoInfo &DittoInfo, CDittoAddinInfo &info)
@@ -39,6 +40,20 @@ bool SupportedFunctions(const CDittoInfo &DittoInfo, FunctionType type, std::vec
 			func2.m_csDetailDescription = _T("Converts a CF_DIB or CF_HDROP to a html format for pasting into outlook express");
 
 			Functions.push_back(func2);
+
+			CFunction func3;
+			func3.m_csFunction = _T("ClearReadOnlyFlag");
+			func3.m_csDisplayName = _T("Clear read only flag");
+			func3.m_csDetailDescription = _T("Clears read only flag on the types CF_HDROP, or files paths in text");
+
+			Functions.push_back(func3);
+
+			CFunction func4;
+			func4.m_csFunction = _T("SetReadOnlyFlag");
+			func4.m_csDisplayName = _T("Set read only flag");
+			func4.m_csDetailDescription = _T("Sets the read only flag on the types CF_HDROP, or files paths in text");
+
+			Functions.push_back(func4);
 		}
 		break;
 	}
@@ -55,4 +70,22 @@ bool ConvertPathToHtmlImageTag(const CDittoInfo &DittoInfo, IClip *pClip)
 {
 	CPasteImageAsHtmlImage convert;
 	return convert.ConvertPathToHtmlImageTag(DittoInfo, pClip);
-}
+}
+
+bool ClearReadOnlyFlag(const CDittoInfo &DittoInfo, IClip *pClip)
+{
+	CReadOnlyFlag readOnly;
+	readOnly.ResetReadOnlyFlag(DittoInfo, pClip, true);
+
+	//return false so the clip is not pasted
+	return false;
+}
+
+bool SetReadOnlyFlag(const CDittoInfo &DittoInfo, IClip *pClip)
+{
+	CReadOnlyFlag readOnly;
+	readOnly.ResetReadOnlyFlag(DittoInfo, pClip, false);
+
+	//return false so the clip is not pasted
+	return false;
+}

+ 2 - 0
Addins/DittoUtil/Exports.h

@@ -10,4 +10,6 @@ extern "C"
 	bool __declspec(dllexport) SupportedFunctions(const CDittoInfo &DittoInfo, FunctionType type, std::vector<CFunction> &Functions);
 	bool __declspec(dllexport) PasteAnyAsText(const CDittoInfo &DittoInfo, IClip *pClip);	
 	bool __declspec(dllexport) ConvertPathToHtmlImageTag(const CDittoInfo &DittoInfo, IClip *pClip);
+	bool __declspec(dllexport) ClearReadOnlyFlag(const CDittoInfo &DittoInfo, IClip *pClip);
+	bool __declspec(dllexport) SetReadOnlyFlag(const CDittoInfo &DittoInfo, IClip *pClip);
 }

+ 1 - 1
Addins/DittoUtil/PasteImageAsHtmlImage.cpp

@@ -1,6 +1,6 @@
 #include "StdAfx.h"
 #include ".\pasteimageashtmlimage.h"
-#include "TextConvert.h"
+#include "../../shared/TextConvert.h"
 
 CString g_csDIBImagePath = _T("");
 int g_nDIBImageName = 1;

+ 159 - 0
Addins/DittoUtil/ReadOnlyFlag.cpp

@@ -0,0 +1,159 @@
+#include "StdAfx.h"
+#include "ReadOnlyFlag.h"
+#include "../../Shared/Tokenizer.h"
+#include "../../Shared/TextConvert.h"
+
+
+CReadOnlyFlag::CReadOnlyFlag(void)
+{
+}
+
+
+CReadOnlyFlag::~CReadOnlyFlag(void)
+{
+}
+
+
+bool CReadOnlyFlag::ResetReadOnlyFlag(const CDittoInfo &DittoInfo, IClip *pClip, bool resetFlag)
+{
+	IClipFormats *pFormats = pClip->Clips();
+	if(pFormats)
+	{
+		CStringArray lines;
+
+		LoadHDropFiles(lines, pFormats);
+
+		if(lines.GetSize() <= 0)
+		{
+			LoadUnicodeFiles(lines, pFormats);
+		}
+
+		if(lines.GetSize() <= 0)
+		{
+			LoadTextFiles(lines, pFormats);
+		}
+
+		for(int i = 0; i < lines.GetSize(); i++)
+		{
+			CString file = lines[i].TrimLeft(' ').TrimRight(' ').MakeLower();
+
+			//Find the first occurance of a file // or \\ for a network file or a->z:\\ for a local files
+			int pos = file.Find(_T("//"));
+			if(pos >= 0)
+			{
+				file = file.Mid(pos);
+			}
+			else
+			{
+				pos = file.Find(_T("\\\\"));
+				if(pos >= 0)
+				{
+					file = file.Mid(pos);
+				}
+				else
+				{
+					for(wchar_t drive = 'a'; drive <= 'z'; drive++)
+					{
+						CString csDrive(drive);
+						csDrive += _T(":\\");
+
+						pos = file.Find(csDrive);
+						if(pos >= 0)
+						{
+							file = file.Mid(pos);
+							break;
+						}
+					}
+				}
+			}
+
+			if(resetFlag)
+			{
+				::SetFileAttributes(file, FILE_ATTRIBUTE_NORMAL);
+			}
+			else
+			{
+				::SetFileAttributes(file, FILE_ATTRIBUTE_READONLY);
+			}
+		}
+	}
+
+	return true;
+}
+
+bool CReadOnlyFlag::LoadUnicodeFiles(CStringArray &lines, IClipFormats *pFormats)
+{		
+	IClipFormat *pFormat = pFormats->FindFormatEx(CF_UNICODETEXT);
+	if(pFormat != NULL)
+	{
+		wchar_t *stringData = (wchar_t *)GlobalLock(pFormat->Data());
+		if(stringData != NULL)
+		{
+			CString string(stringData);
+			CString delim(_T("\r\n"));
+
+			CTokenizer token(string, delim);
+			CString line;
+			while(token.Next(line))
+			{
+				lines.Add(line);
+			}
+
+			GlobalUnlock(pFormat->Data());
+		}
+	}
+
+	return lines.GetSize() > 0;
+}
+
+bool CReadOnlyFlag::LoadTextFiles(CStringArray &lines, IClipFormats *pFormats)
+{		
+	IClipFormat *pFormat = pFormats->FindFormatEx(CF_TEXT);
+	if(pFormat != NULL)
+	{
+		char *stringData = (char *)GlobalLock(pFormat->Data());
+		if(stringData != NULL)
+		{
+			CStringA string(stringData);
+			CStringW unicodeString(CTextConvert::MultiByteToUnicodeString(string));
+			CString delim(_T("\r\n"));
+
+			CTokenizer token(unicodeString, delim);
+			CString line;
+			while(token.Next(line))
+			{
+				lines.Add(line);
+			}
+
+			GlobalUnlock(pFormat->Data());
+		}
+	}
+
+	return lines.GetSize() > 0;
+}
+
+bool CReadOnlyFlag::LoadHDropFiles(CStringArray &lines, IClipFormats *pFormats)
+{
+	IClipFormat *pFormat = pFormats->FindFormatEx(CF_HDROP);
+	if(pFormat != NULL)
+	{
+		HDROP drop = (HDROP)GlobalLock(pFormat->Data());
+		if(drop)
+		{
+			int nNumFiles = DragQueryFile(drop, -1, NULL, 0);
+			TCHAR file[MAX_PATH];
+
+			for(int nFile = 0; nFile < nNumFiles; nFile++)
+			{
+				if(DragQueryFile(drop, nFile, file, sizeof(file)) > 0)
+				{
+					lines.Add(file);
+				}
+			}
+
+			GlobalUnlock(pFormat->Data());
+		}
+	}
+
+	return lines.GetSize() > 0;
+}

+ 20 - 0
Addins/DittoUtil/ReadOnlyFlag.h

@@ -0,0 +1,20 @@
+#pragma once
+#include "..\..\Shared\DittoDefines.h"
+#include "..\..\Shared\IClip.h"
+
+#include <afxcoll.h>
+
+class CReadOnlyFlag
+{
+public:
+	CReadOnlyFlag(void);
+	~CReadOnlyFlag(void);
+
+	bool ResetReadOnlyFlag(const CDittoInfo &DittoInfo, IClip *pClip, bool resetFlag);
+
+protected:
+	bool LoadUnicodeFiles(CStringArray &lines, IClipFormats *pFormats);
+	bool LoadTextFiles(CStringArray &lines, IClipFormats *pFormats);
+	bool LoadHDropFiles(CStringArray &lines, IClipFormats *pFormats);
+};
+