Skip to content

Commit

Permalink
Change File::Copy and Move methods to take File argument.
Browse files Browse the repository at this point in the history
Fixes copying/moving with relative path specified.
  • Loading branch information
enzo1982 committed Aug 5, 2018
1 parent faac8d4 commit 1e28bd1
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 15 deletions.
2 changes: 2 additions & 0 deletions ChangeLog
Expand Up @@ -21,6 +21,8 @@ dd.mm.18 hh:mm - smooth alpha 0.8.74.0
- driver.cpp - added Truncate() and Close() methods to public API
- implemented Flush() method for file drivers
- outstream.cpp - added Truncate() method
- file.cpp - Copy() and Move() method now take a const File & argument
- directory.cpp - Copy() and Move() method now take a const Directory & argument

- added Float32 and Float64 type defintions
- added stream API to CRC32 and CRC64 classes
Expand Down
8 changes: 4 additions & 4 deletions classes/files/directory.cpp
@@ -1,5 +1,5 @@
/* The smooth Class Library
* Copyright (C) 1998-2017 Robert Kausch <robert.kausch@gmx.net>
* Copyright (C) 1998-2018 Robert Kausch <robert.kausch@gmx.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of "The Artistic License, Version 2.0".
Expand Down Expand Up @@ -311,19 +311,19 @@ S::Int S::Directory::Create()
else return Success();
}

S::Int S::Directory::Copy(const String &destination)
S::Int S::Directory::Copy(const Directory &destination)
{
return Error();
}

S::Int S::Directory::Move(const String &destination)
S::Int S::Directory::Move(const Directory &destination)
{
if (!Exists()) return Error();

#ifdef __WIN32__
Bool result = MoveFile(String(GetUnicodePathPrefix(*this)).Append(*this), String(GetUnicodePathPrefix(destination)).Append(destination));
#else
Bool result = (rename(String(*this).ConvertTo("UTF-8"), destination.ConvertTo("UTF-8")) == 0);
Bool result = (rename(String(*this).ConvertTo("UTF-8"), String(destination).ConvertTo("UTF-8")) == 0);
#endif

if (result == False) return Error();
Expand Down
10 changes: 5 additions & 5 deletions classes/files/file.cpp
@@ -1,5 +1,5 @@
/* The smooth Class Library
* Copyright (C) 1998-2017 Robert Kausch <robert.kausch@gmx.net>
* Copyright (C) 1998-2018 Robert Kausch <robert.kausch@gmx.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of "The Artistic License, Version 2.0".
Expand Down Expand Up @@ -289,7 +289,7 @@ S::Int S::File::Create()
return Success();
}

S::Int S::File::Copy(const String &destination)
S::Int S::File::Copy(const File &destination)
{
if (!Exists()) return Error();

Expand All @@ -299,7 +299,7 @@ S::Int S::File::Copy(const String &destination)
Bool result = False;

FILE *source = fopen(String(*this).ConvertTo("UTF-8"), "rb");
FILE *dest = fopen(destination.ConvertTo("UTF-8"), "wb");
FILE *dest = fopen(String(destination).ConvertTo("UTF-8"), "wb");

if (source != NIL && dest != NIL)
{
Expand Down Expand Up @@ -331,7 +331,7 @@ S::Int S::File::Copy(const String &destination)
else return Success();
}

S::Int S::File::Move(const String &destination)
S::Int S::File::Move(const File &destination)
{
if (!Exists()) return Error();

Expand All @@ -345,7 +345,7 @@ S::Int S::File::Move(const String &destination)

SetFileAttributes(fileName, fileAttributes);
#else
Bool result = (rename(String(*this).ConvertTo("UTF-8"), destination.ConvertTo("UTF-8")) == 0);
Bool result = (rename(String(*this).ConvertTo("UTF-8"), String(destination).ConvertTo("UTF-8")) == 0);
#endif

if (result == False) return Error();
Expand Down
6 changes: 3 additions & 3 deletions include/smooth/files/directory.h
@@ -1,5 +1,5 @@
/* The smooth Class Library
* Copyright (C) 1998-2014 Robert Kausch <robert.kausch@gmx.net>
* Copyright (C) 1998-2018 Robert Kausch <robert.kausch@gmx.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of "The Artistic License, Version 2.0".
Expand Down Expand Up @@ -55,8 +55,8 @@ namespace smooth

Int Create();

Int Copy(const String &);
Int Move(const String &);
Int Copy(const Directory &);
Int Move(const Directory &);

Int Delete();
Int Empty();
Expand Down
6 changes: 3 additions & 3 deletions include/smooth/files/file.h
@@ -1,5 +1,5 @@
/* The smooth Class Library
* Copyright (C) 1998-2010 Robert Kausch <robert.kausch@gmx.net>
* Copyright (C) 1998-2018 Robert Kausch <robert.kausch@gmx.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of "The Artistic License, Version 2.0".
Expand Down Expand Up @@ -47,8 +47,8 @@ namespace smooth

Int Create();

Int Copy(const String &);
Int Move(const String &);
Int Copy(const File &);
Int Move(const File &);

Int Delete();
Int Truncate();
Expand Down

0 comments on commit 1e28bd1

Please sign in to comment.