/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
// This file is included by nsFileSpec.cp, and includes the Windows-specific
// implementations.
#include <direct.h>
#include <limits.h>
#include <stdlib.h>
#include "prio.h"
#include "nsError.h"
#include <windows.h>
#define INITGUID
#include <objbase.h>
#endif
#include <shlobj.h>
#include <shellapi.h>
#include <shlguid.h>
#ifdef UNICODE
#else
#endif
//----------------------------------------------------------------------------------------
// Canonify, make absolute, and check whether directories exist. This
// takes a (possibly relative) native path and converts it into a
// fully qualified native path.
//----------------------------------------------------------------------------------------
{
return;
"This smells like a Unix path. Native path expected! "
"Please fix.");
if (inMakeDirs)
{
}
errno = 0;
*buffer = '\0';
if (canonicalPath)
{
if (canonicalPath[0] == '\0')
return;
}
} // nsFileSpecHelpers::Canonify
//----------------------------------------------------------------------------------------
// This just does string manipulation. It doesn't check reality, or canonify, or
// anything
//----------------------------------------------------------------------------------------
{
// Allow for relative or absolute. We can do this in place, because the
// native path is never longer.
return;
// Strip initial slash for an absolute path
if (*src == '/') {
if (!src[1]) {
// allocate new string by copying from ioPath[1]
return;
}
// Since it was an absolute path, check for the drive letter
*colonPointer = ':';
// allocate new string by copying from ioPath[1]
}
// Convert '/' to '\'. (Must check EVERY character: consider UNC path
// case.)
{
if (*src == '/')
*src = '\\';
}
} // nsFileSpecHelpers::UnixToNative
//----------------------------------------------------------------------------------------
// This just does string manipulation. It doesn't check reality, or canonify, or
// anything. The unix path is longer, so we can't do it in place.
//----------------------------------------------------------------------------------------
{
return;
// Convert the drive-letter separator, if present
else
cp--;
else
// Convert '\' to '/'
{
{
cp++;
continue;
}
if (*cp == '\\')
*cp = '/';
}
// Add the slash in front.
}
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
{
// NS_ASSERTION(0, "nsFileSpec is unsupported - use nsIFile!");
*this = inPath;
}
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
{
} // nsFileSpec::operator =
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
{
*this = inSpec;
} // nsFilePath::nsFilePath
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
{
} // nsFilePath::operator =
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
{
} // nsFileSpec::SetLeafName
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
{
} // nsFileSpec::GetLeafName
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
{
} // nsFileSpec::Exists
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
{
else
outStamp = 0;
} // nsFileSpec::GetModDate
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
{
return 0;
} // nsFileSpec::GetFileSize
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
{
} // nsFileSpec::IsFile
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
{
} // nsFileSpec::IsDirectory
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
{
{
if (FILE_ATTRIBUTE_HIDDEN & attr)
}
return hidden;
}
// nsFileSpec::IsHidden
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
{
// Get a pointer to the IShellLink interface.
{
// Get a pointer to the IPersistFile interface.
{
// Ensure that the string is Unicode.
// Load the shortcut.
{
}
// Release the pointer to the IPersistFile interface.
}
// Release the pointer to the IShellLink interface.
}
return isSymlink;
}
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
{
if (Exists())
return NS_OK;
// Get a pointer to the IShellLink interface.
{
// Get a pointer to the IPersistFile interface.
{
// Ensure that the string is Unicode.
// Load the shortcut.
{
// Resolve the link.
{
// Get the path to the link target.
{
// Here we modify the nsFileSpec;
}
}
}
else {
// It wasn't a shortcut. Oh well. Leave it like it was.
hres = 0;
}
// Release the pointer to the IPersistFile interface.
}
// Release the pointer to the IShellLink interface.
}
return NS_OK;
return NS_FILE_FAILURE;
}
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
{
if (cp++)
} // nsFileSpec::GetParent
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
{
return;
mPath += "x";
else
mPath += "\\x";
// If it's a (unix) relative path, make it native
} // nsFileSpec::operator +=
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
{
// Note that mPath is canonical!
mkdir(nsNSPRPath(*this));
} // nsFileSpec::CreateDirectory
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
{
if (IsDirectory())
{
if (inRecursive)
{
{
}
}
rmdir(nsNSPRPath(*this));
}
{
remove(nsNSPRPath(*this));
}
} // nsFileSpec::Delete
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
{
if (IsDirectory())
{
{
}
{
if (child.IsDirectory())
{
tmpDirSpec += leafname;
}
else
{
}
}
}
{
{
}
}
} // nsFileSpec::RecursiveCopy
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
{
// Leave it to Microsoft to open an existing file with a function
// named "CreateFile".
NULL,
NULL);
if (hFile == INVALID_HANDLE_VALUE)
return NS_FILE_FAILURE;
// Seek to new, desired end of file
if (status == 0xffffffff)
goto error;
// Truncate file at current cursor position
if (!SetEndOfFile(hFile))
goto error;
if (!CloseHandle(hFile))
return NS_FILE_FAILURE;
return NS_OK;
return NS_FILE_FAILURE;
} // nsFileSpec::Truncate
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
{
// This function should not be used to move a file on disk.
return NS_FILE_FAILURE;
{
// Could not rename, set back to the original.
return NS_FILE_FAILURE;
}
return NS_OK;
} // nsFileSpec::Rename
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
{
// We can only copy into a directory, and (for now) can not copy entire directories
{
destPath += "\\";
// CopyFile returns non-zero if succeeds
if (copyOK)
return NS_OK;
}
return NS_FILE_FAILURE;
} // nsFileSpec::CopyToDir
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
{
// We can only copy into a directory, and (for now) can not copy entire directories
{
destPath += "\\";
// MoveFile returns non-zero if succeeds
if (copyOK)
{
*this = inNewParentDirectory + GetLeafName();
return NS_OK;
}
}
return NS_FILE_FAILURE;
} // nsFileSpec::MoveToDir
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
{
if (!IsDirectory())
{
if (execResult > 31)
return NS_OK;
}
return NS_FILE_FAILURE;
} // nsFileSpec::Execute
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
{
if (aDrive[0] == '\0')
{
// The back end is always trying to pass us paths that look
{
}
else
{
// Return bogus large number and hope for the best
return int64;
}
}
// Check disk space
double nBytes = 0;
{
}
{
}
{
}
}
//========================================================================================
// nsDirectoryIterator
//========================================================================================
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
{
mCurrent += "dummy";
mStarting += "dummy";
++(*this);
} // nsDirectoryIterator::nsDirectoryIterator
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
{
if (mDir)
} // nsDirectoryIterator::nsDirectoryIterator
//----------------------------------------------------------------------------------------
nsDirectoryIterator& nsDirectoryIterator::operator ++ ()
//----------------------------------------------------------------------------------------
{
if (!mDir)
return *this;
if (entry)
{
if (mResoveSymLinks)
{
}
}
return *this;
} // nsDirectoryIterator::operator ++
//----------------------------------------------------------------------------------------
nsDirectoryIterator& nsDirectoryIterator::operator -- ()
//----------------------------------------------------------------------------------------
{
return ++(*this); // can't do it backwards.
} // nsDirectoryIterator::operator --