mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
236 lines
6.5 KiB
C++
236 lines
6.5 KiB
C++
//------------------------------------------------------------------------------
|
|
/*
|
|
This file is part of Beast: https://github.com/vinniefalco/Beast
|
|
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
|
|
|
|
Portions of this file are from JUCE.
|
|
Copyright (c) 2013 - Raw Material Software Ltd.
|
|
Please visit http://www.juce.com
|
|
|
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
purpose with or without fee is hereby granted, provided that the above
|
|
copyright notice and this permission notice appear in all copies.
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
*/
|
|
//==============================================================================
|
|
|
|
bool File::copyInternal (const File& dest) const
|
|
{
|
|
FileInputStream in (*this);
|
|
|
|
if (dest.deleteFile())
|
|
{
|
|
{
|
|
FileOutputStream out (dest);
|
|
|
|
if (out.failedToOpen())
|
|
return false;
|
|
|
|
if (out.writeFromInputStream (in, -1) == getSize())
|
|
return true;
|
|
}
|
|
|
|
dest.deleteFile();
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
void File::findFileSystemRoots (Array<File>& destArray)
|
|
{
|
|
destArray.add (File ("/"));
|
|
}
|
|
|
|
//==============================================================================
|
|
bool File::isOnCDRomDrive() const
|
|
{
|
|
return false;
|
|
}
|
|
|
|
bool File::isOnHardDisk() const
|
|
{
|
|
return true;
|
|
}
|
|
|
|
bool File::isOnRemovableDrive() const
|
|
{
|
|
return false;
|
|
}
|
|
|
|
bool File::isHidden() const
|
|
{
|
|
return getFileName().startsWithChar ('.');
|
|
}
|
|
|
|
//==============================================================================
|
|
namespace
|
|
{
|
|
File beast_readlink (const String& file, const File& defaultFile)
|
|
{
|
|
const int size = 8192;
|
|
HeapBlock<char> buffer;
|
|
buffer.malloc (size + 4);
|
|
|
|
const size_t numBytes = readlink (file.toUTF8(), buffer, size);
|
|
|
|
if (numBytes > 0 && numBytes <= size)
|
|
return File (file).getSiblingFile (String::fromUTF8 (buffer, (int) numBytes));
|
|
|
|
return defaultFile;
|
|
}
|
|
}
|
|
|
|
File File::getLinkedTarget() const
|
|
{
|
|
return beast_readlink (getFullPathName().toUTF8(), *this);
|
|
}
|
|
|
|
//==============================================================================
|
|
File File::getSpecialLocation (const SpecialLocationType type)
|
|
{
|
|
switch (type)
|
|
{
|
|
case userHomeDirectory:
|
|
case userDocumentsDirectory:
|
|
case userMusicDirectory:
|
|
case userMoviesDirectory:
|
|
case userPicturesDirectory:
|
|
case userApplicationDataDirectory:
|
|
case commonDocumentsDirectory:
|
|
case userDesktopDirectory:
|
|
return File (android.appDataDir);
|
|
|
|
case commonApplicationDataDirectory:
|
|
return File (android.appDataDir);
|
|
|
|
case globalApplicationsDirectory:
|
|
return File ("/system/app");
|
|
|
|
case tempDirectory:
|
|
return File (android.appDataDir).getChildFile (".temp");
|
|
|
|
case invokedExecutableFile:
|
|
case currentExecutableFile:
|
|
case currentApplicationFile:
|
|
case hostApplicationPath:
|
|
return beast_getExecutableFile();
|
|
|
|
default:
|
|
bassertfalse; // unknown type?
|
|
break;
|
|
}
|
|
|
|
return File::nonexistent ();
|
|
}
|
|
|
|
//==============================================================================
|
|
String File::getVersion() const
|
|
{
|
|
return String::empty;
|
|
}
|
|
|
|
//==============================================================================
|
|
bool File::moveToTrash() const
|
|
{
|
|
if (! exists())
|
|
return true;
|
|
|
|
// TODO
|
|
|
|
return false;
|
|
}
|
|
|
|
//==============================================================================
|
|
class DirectoryIterator::NativeIterator::Pimpl : public Uncopyable
|
|
{
|
|
public:
|
|
Pimpl (const File& directory, const String& wildCard_)
|
|
: parentDir (File::addTrailingSeparator (directory.getFullPathName())),
|
|
wildCard (wildCard_),
|
|
dir (opendir (directory.getFullPathName().toUTF8()))
|
|
{
|
|
}
|
|
|
|
~Pimpl()
|
|
{
|
|
if (dir != 0)
|
|
closedir (dir);
|
|
}
|
|
|
|
bool next (String& filenameFound,
|
|
bool* const isDir, bool* const isHidden, int64* const fileSize,
|
|
Time* const modTime, Time* const creationTime, bool* const isReadOnly)
|
|
{
|
|
if (dir != 0)
|
|
{
|
|
const char* wildcardUTF8 = nullptr;
|
|
|
|
for (;;)
|
|
{
|
|
struct dirent* const de = readdir (dir);
|
|
|
|
if (de == nullptr)
|
|
break;
|
|
|
|
if (wildcardUTF8 == nullptr)
|
|
wildcardUTF8 = wildCard.toUTF8();
|
|
|
|
if (fnmatch (wildcardUTF8, de->d_name, FNM_CASEFOLD) == 0)
|
|
{
|
|
filenameFound = CharPointer_UTF8 (de->d_name);
|
|
|
|
updateStatInfoForFile (parentDir + filenameFound, isDir, fileSize, modTime, creationTime, isReadOnly);
|
|
|
|
if (isHidden != 0)
|
|
*isHidden = filenameFound.startsWithChar ('.');
|
|
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
private:
|
|
String parentDir, wildCard;
|
|
DIR* dir;
|
|
};
|
|
|
|
|
|
DirectoryIterator::NativeIterator::NativeIterator (const File& directory, const String& wildCard)
|
|
: pimpl (new DirectoryIterator::NativeIterator::Pimpl (directory, wildCard))
|
|
{
|
|
}
|
|
|
|
DirectoryIterator::NativeIterator::~NativeIterator()
|
|
{
|
|
}
|
|
|
|
bool DirectoryIterator::NativeIterator::next (String& filenameFound,
|
|
bool* const isDir, bool* const isHidden, int64* const fileSize,
|
|
Time* const modTime, Time* const creationTime, bool* const isReadOnly)
|
|
{
|
|
return pimpl->next (filenameFound, isDir, isHidden, fileSize, modTime, creationTime, isReadOnly);
|
|
}
|
|
|
|
|
|
//==============================================================================
|
|
bool Process::openDocument (const String& fileName, const String& parameters)
|
|
{
|
|
const LocalRef<jstring> t (javaString (fileName));
|
|
android.activity.callVoidMethod (BeastAppActivity.launchURL, t.get());
|
|
return true;
|
|
}
|
|
|
|
void File::revealToUser() const
|
|
{
|
|
}
|