Prechádzať zdrojové kódy

FIX: Wrong data size when drag & drop text to file panel

Alexander Koblov 3 rokov pred
rodič
commit
44121c1b32
1 zmenil súbory, kde vykonal 17 pridanie a 22 odobranie
  1. 17 22
      src/platform/uOleDragDrop.pas

+ 17 - 22
src/platform/uOleDragDrop.pas

@@ -1148,12 +1148,11 @@ end;
 { TFileDropTarget.GetDropTextCreatedFilenames }
 { TFileDropTarget.GetDropTextCreatedFilenames }
 function TFileDropTarget.GetDropTextCreatedFilenames(var Medium: TSTGMedium; Format: TFormatETC): TStringList;
 function TFileDropTarget.GetDropTextCreatedFilenames(var Medium: TSTGMedium; Format: TFormatETC): TStringList;
 var
 var
-  FlagKeepGoing:boolean;
-  AnyPointer: Pointer;
-  UnicodeCharPointer: PUnicodeChar;
   hFile: THandle;
   hFile: THandle;
+  AnyPointer: Pointer;
+  MyUtf8String: String;
+  FlagKeepGoing: Boolean;
   DroppedTextFilename: String;
   DroppedTextFilename: String;
-  MyUnicodeString: UnicodeString;
 
 
   procedure SetDefaultFilename;
   procedure SetDefaultFilename;
   begin
   begin
@@ -1166,7 +1165,7 @@ var
   end;
   end;
 
 
 begin
 begin
-  result:=nil;
+  Result:= nil;
   FlagKeepGoing:=TRUE;
   FlagKeepGoing:=TRUE;
   SetDefaultFilename;
   SetDefaultFilename;
   if not gDragAndDropTextAutoFilename then FlagKeepGoing:=ShowInputQuery(rsCaptionForAskingFilename, rsMsgPromptAskingFilename, DroppedTextFilename);
   if not gDragAndDropTextAutoFilename then FlagKeepGoing:=ShowInputQuery(rsCaptionForAskingFilename, rsMsgPromptAskingFilename, DroppedTextFilename);
@@ -1183,35 +1182,31 @@ begin
         case Format.CfFormat of
         case Format.CfFormat of
           CF_TEXT:
           CF_TEXT:
             begin
             begin
-              FileWrite(hFile, PAnsiChar(AnyPointer)^, UTF8Length(PAnsiChar(AnyPointer)));
+              FileWrite(hFile, AnyPointer^, StrLen(PAnsiChar(AnyPointer)));
             end;
             end;
 
 
           CF_UNICODETEXT:
           CF_UNICODETEXT:
             begin
             begin
               if gDragAndDropSaveUnicodeTextInUFT8 then
               if gDragAndDropSaveUnicodeTextInUFT8 then
               begin
               begin
-                UnicodeCharPointer:=AnyPointer;
-                MyUnicodeString:='';
-                while UnicodeCharPointer^<>#$0000 do
-                begin
-                  MyUnicodeString:=MyUnicodeString+UnicodeCharPointer^;
-                  inc(UnicodeCharPointer);
-                end;
-
-                FileWrite(hFile, PChar(#$EF+#$BB+#$BF)[0], 3); //Adding Byte Order Mask for UTF8.
-                FileWrite(hFile, UTF16toUTF8(MyUnicodeString)[1], Length(UTF16toUTF8(MyUnicodeString)));
+                MyUtf8String:= CeUtf16toUtf8(PUnicodeChar(AnyPointer));
+                // Adding Byte Order Mark for UTF8
+                FileWrite(hFile, PAnsiChar(#$EF#$BB#$BF)[0], 3);
+                FileWrite(hFile, Pointer(MyUtf8String)^, Length(MyUtf8String));
               end
               end
-              else
-              begin
-                FileWrite(hFile, PChar(#$FF+#$FE)[0], 2); //Adding Byte Order Mask for UTF16, Little-Endian first.
-                FileWrite(hFile, PUnicodeChar(AnyPointer)^, Length(PUnicodeChar(AnyPointer))*2);
+              else begin
+                // Adding Byte Order Mark for UTF16LE
+                FileWrite(hFile, PAnsiChar(#$FF#$FE)[0], 2);
+                FileWrite(hFile, AnyPointer^, StrLen(PUnicodeChar(AnyPointer)) * SizeOf(WideChar));
               end;
               end;
             end;
             end;
 
 
           else
           else
             begin
             begin
-              if Format.CfFormat=CFU_HTML then FileWrite(hFile, PAnsiChar(AnyPointer)^, UTF8Length(PAnsiChar(AnyPointer)));
-              if Format.CfFormat=CFU_RICHTEXT then FileWrite(hFile, PAnsiChar(AnyPointer)^, UTF8Length(PAnsiChar(AnyPointer)));
+              if (Format.CfFormat = CFU_HTML) or (Format.CfFormat = CFU_RICHTEXT) then
+              begin
+                FileWrite(hFile, AnyPointer^, StrLen(PAnsiChar(AnyPointer)));
+              end;
             end;
             end;
         end;
         end;
       finally
       finally