| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- #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;
- }
- csDrive = drive;
- csDrive += _T(":/");
- pos = file.Find(csDrive);
- if(pos >= 0)
- {
- file = file.Mid(pos);
- break;
- }
- }
- }
- }
- BOOL success = FALSE;
- if(resetFlag)
- {
- success = ::SetFileAttributes(file, FILE_ATTRIBUTE_NORMAL);
- }
- else
- {
- success = ::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::AnsiToUnicode(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;
- }
|