summaryrefslogtreecommitdiff
path: root/desktop/source
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2013-08-23 18:34:24 +0200
committerStephan Bergmann <sbergman@redhat.com>2013-08-23 18:34:24 +0200
commit5300d637a39742c1d952d21651737c708ecc2f89 (patch)
tree4af919bceec65bad1e7b3c5b16bcaf2cb1fa85a8 /desktop/source
parent5e110ab8884bc033b4f2aab35bb3c8c520a2d8d1 (diff)
Clean up desktop::UserInstall
Change-Id: I0cbf15443877648b1b2d82bdcf03dcccdf5f26ac
Diffstat (limited to 'desktop/source')
-rw-r--r--desktop/source/app/app.cxx10
-rw-r--r--desktop/source/app/userinstall.cxx280
-rw-r--r--desktop/source/app/userinstall.hxx42
3 files changed, 147 insertions, 185 deletions
diff --git a/desktop/source/app/app.cxx b/desktop/source/app/app.cxx
index 47024cb8b91c..a3dd1165904e 100644
--- a/desktop/source/app/app.cxx
+++ b/desktop/source/app/app.cxx
@@ -1412,14 +1412,14 @@ int Desktop::Main()
SetSplashScreenProgress(10);
- UserInstall::UserInstallStatus inst_fin = UserInstall::finalize();
- if (inst_fin != UserInstall::Ok && inst_fin != UserInstall::Created)
+ userinstall::Status inst_fin = userinstall::finalize();
+ if (inst_fin != userinstall::EXISTED && inst_fin != userinstall::CREATED)
{
SAL_WARN( "desktop.app", "userinstall failed");
- if ( inst_fin == UserInstall::E_NoDiskSpace )
+ if ( inst_fin == userinstall::ERROR_NO_SPACE )
HandleBootstrapErrors(
BE_USERINSTALL_NOTENOUGHDISKSPACE, OUString() );
- else if ( inst_fin == UserInstall::E_NoWriteAccess )
+ else if ( inst_fin == userinstall::ERROR_CANT_WRITE )
HandleBootstrapErrors( BE_USERINSTALL_NOWRITEACCESS, OUString() );
else
HandleBootstrapErrors( BE_USERINSTALL_FAILED, OUString() );
@@ -1529,7 +1529,7 @@ int Desktop::Main()
if ( bAbort )
return EXIT_FAILURE;
- if (inst_fin == UserInstall::Created)
+ if (inst_fin == userinstall::CREATED)
{
Migration::migrateSettingsIfNecessary();
}
diff --git a/desktop/source/app/userinstall.cxx b/desktop/source/app/userinstall.cxx
index 2098d1bd5d79..7780064b8fce 100644
--- a/desktop/source/app/userinstall.cxx
+++ b/desktop/source/app/userinstall.cxx
@@ -17,184 +17,152 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
-#include <config_features.h>
-#include <config_folders.h>
-
#include "sal/config.h"
-#include "userinstall.hxx"
-
-#include <stdio.h>
-#include <rtl/ustring.hxx>
-#include <rtl/ustrbuf.hxx>
-#include <osl/file.hxx>
-#include <osl/mutex.hxx>
-#include <osl/process.h>
-#include <osl/diagnose.h>
-#include <osl/security.hxx>
-#include <rtl/ref.hxx>
+#include <cassert>
-#include <officecfg/Setup.hxx>
-#include <unotools/bootstrap.hxx>
-#include <svl/languageoptions.hxx>
-#include <unotools/syslocaleoptions.hxx>
-#include <i18nlangtag/mslangid.hxx>
-
-#include "app.hxx"
-
-using namespace osl;
-using namespace utl;
-using namespace com::sun::star::container;
-using namespace com::sun::star::uno;
-using namespace com::sun::star::lang;
-using namespace com::sun::star::beans;
-using namespace com::sun::star::util;
+#include "boost/shared_ptr.hpp"
+#include "com/sun/star/uno/Exception.hpp"
+#include "comphelper/configuration.hxx"
+#include "config_folders.h"
+#include "officecfg/Setup.hxx"
+#include "osl/file.h"
+#include "osl/file.hxx"
+#include "rtl/ustring.hxx"
+#include "sal/log.hxx"
+#include "unotools/bootstrap.hxx"
+#include "userinstall.hxx"
-namespace desktop {
+namespace desktop { namespace userinstall {
- static UserInstall::UserInstallStatus create_user_install(OUString&);
+namespace {
- static bool is_user_install()
- {
- try
- {
- return officecfg::Setup::Office::ooSetupInstCompleted::get();
+#if !(defined ANDROID || defined IOS)
+osl::FileBase::RC copyRecursive(
+ OUString const & srcUri, OUString const & dstUri)
+{
+ osl::DirectoryItem item;
+ osl::FileBase::RC e = osl::DirectoryItem::get(srcUri, item);
+ if (e != osl::FileBase::E_None) {
+ return e;
+ }
+ osl::FileStatus stat1(osl_FileStatus_Mask_Type);
+ e = item.getFileStatus(stat1);
+ if (e != osl::FileBase::E_None) {
+ return e;
+ }
+ if (stat1.getFileType() == osl::FileStatus::Directory) {
+ e = osl::Directory::create(dstUri);
+ if (e != osl::FileBase::E_None && e != osl::FileBase::E_EXIST) {
+ return e;
}
- catch (Exception const & e)
- {
- SAL_WARN(
- "desktop.app", "ignoring Exception \"" << e.Message << "\"");
- return false;
+ osl::Directory dir(srcUri);
+ e = dir.open();
+ if (e != osl::FileBase::E_None) {
+ return e;
}
- }
-
- UserInstall::UserInstallStatus UserInstall::finalize()
- {
- OUString aUserInstallPath;
- utl::Bootstrap::PathStatus aLocateResult =
- utl::Bootstrap::locateUserInstallation(aUserInstallPath);
-
- switch (aLocateResult) {
-
- case utl::Bootstrap::DATA_INVALID:
- case utl::Bootstrap::DATA_MISSING:
- case utl::Bootstrap::DATA_UNKNOWN:
- // cannot find a valid path or path is missing
- return E_Unknown;
-
- case utl::Bootstrap::PATH_EXISTS:
- {
- // path exists, check if an installation lives there
- if ( is_user_install() )
- {
- return Ok;
- }
- // Note: fall-thru intended.
+ for (;;) {
+ e = dir.getNextItem(item);
+ if (e == osl::FileBase::E_NOENT) {
+ break;
}
- case utl::Bootstrap::PATH_VALID:
- // found a path but need to create user install
- return create_user_install(aUserInstallPath);
- default:
- return E_Unknown;
- }
- }
-
-#if HAVE_FEATURE_DESKTOP
- static osl::FileBase::RC copy_recursive( const OUString& srcUnqPath, const OUString& dstUnqPath)
- {
- FileBase::RC err;
- DirectoryItem aDirItem;
- DirectoryItem::get(srcUnqPath, aDirItem);
- FileStatus aFileStatus(osl_FileStatus_Mask_All);
- aDirItem.getFileStatus(aFileStatus);
-
- if( aFileStatus.getFileType() == FileStatus::Directory)
- {
- // create directory if not already there
- err = Directory::create( dstUnqPath );
- if (err == osl::FileBase::E_EXIST)
- err = osl::FileBase::E_None;
-
- FileBase::RC next = err;
- if (err == osl::FileBase::E_None)
- {
- // iterate through directory contents
- Directory aDir( srcUnqPath );
- aDir.open();
- while (err == osl::FileBase::E_None &&
- (next = aDir.getNextItem( aDirItem )) == osl::FileBase::E_None)
- {
- aDirItem.getFileStatus(aFileStatus);
- // generate new src/dst pair and make recursive call
- OUString newSrcUnqPath = aFileStatus.getFileURL();
- OUString newDstUnqPath = dstUnqPath;
- OUString itemname = aFileStatus.getFileName();
- // append trailing '/' if needed
- if (newDstUnqPath.lastIndexOf(sal_Unicode('/')) != newDstUnqPath.getLength()-1)
- newDstUnqPath += OUString("/");
- newDstUnqPath += itemname;
- // recursion
- err = copy_recursive(newSrcUnqPath, newDstUnqPath);
- }
- aDir.close();
-
- if ( err != osl::FileBase::E_None )
- return err;
- if( next != FileBase::E_NOENT )
- err = FileBase::E_INVAL;
+ if (e != osl::FileBase::E_None) {
+ return e;
+ }
+ osl::FileStatus stat2(
+ osl_FileStatus_Mask_FileName | osl_FileStatus_Mask_FileURL);
+ e = item.getFileStatus(stat2);
+ if (e != osl::FileBase::E_None) {
+ return e;
+ }
+ assert(!dstUri.endsWith("/"));
+ e = copyRecursive(
+ stat2.getFileURL(), dstUri + "/" + stat2.getFileName());
+ // assumes that all files under presets/ have names that can be
+ // copied unencoded into file URLs
+ if (e != osl::FileBase::E_None) {
+ return e;
}
}
- else
- {
- // copy single file - foldback
- err = File::copy( srcUnqPath,dstUnqPath );
+ e = dir.close();
+ } else {
+ e = osl::File::copy(srcUri, dstUri);
+ if (e == osl::FileBase::E_EXIST) {
+ // Assume an earlier attempt failed half-way through:
+ e = osl::FileBase::E_None;
}
-
- return err;
}
+ return e;
+}
#endif
- static UserInstall::UserInstallStatus create_user_install(OUString& aUserPath)
+Status create(OUString const & uri) {
+ osl::FileBase::RC e = osl::Directory::createPath(uri);
+ if (e != osl::FileBase::E_None && e != osl::FileBase::E_EXIST) {
+ return ERROR_OTHER;
+ }
+#if !(defined ANDROID || defined IOS)
+#if defined UNIX
+ // Set safer permissions for the user directory by default:
+ osl::File::setAttributes(
+ uri,
+ (osl_File_Attribute_OwnWrite | osl_File_Attribute_OwnRead
+ | osl_File_Attribute_OwnExe));
+#endif
+ // As of now osl_copyFile does not work on Android => don't do this:
+ OUString baseUri;
+ if (utl::Bootstrap::locateBaseInstallation(baseUri)
+ != utl::Bootstrap::PATH_EXISTS)
{
- OUString aBasePath;
- if (utl::Bootstrap::locateBaseInstallation(aBasePath) != utl::Bootstrap::PATH_EXISTS)
- return UserInstall::E_InvalidBaseinstall;
-
- // create the user directory
- FileBase::RC rc = Directory::createPath(aUserPath);
- if ((rc != FileBase::E_None) && (rc != FileBase::E_EXIST)) return UserInstall::E_Creation;
-
-#if defined(UNIX) && !defined(ANDROID) && !defined(IOS)
- // Set safer permissions for the user directory by default:
- File::setAttributes(aUserPath, osl_File_Attribute_OwnWrite| osl_File_Attribute_OwnRead| osl_File_Attribute_OwnExe);
+ return ERROR_OTHER;
+ }
+ switch (copyRecursive(
+ baseUri + "/" LIBO_SHARE_PRESETS_FOLDER, uri + "/user"))
+ {
+ case osl::FileBase::E_None:
+ break;
+ case osl::FileBase::E_ACCES:
+ return ERROR_CANT_WRITE;
+ case osl::FileBase::E_NOSPC:
+ return ERROR_NO_SPACE;
+ default:
+ return ERROR_OTHER;
+ }
#endif
+ boost::shared_ptr<comphelper::ConfigurationChanges> batch(
+ comphelper::ConfigurationChanges::create());
+ officecfg::Setup::Office::ooSetupInstCompleted::set(true, batch);
+ batch->commit();
+ return CREATED;
+}
-#if !defined(ANDROID) && !defined(IOS)
- // as of now osl_copyFile does not work on Android => don't do this.
-
- // Copy data from shared data directory of base installation:
- rc = copy_recursive(
- aBasePath + OUString("/" LIBO_SHARE_PRESETS_FOLDER),
- aUserPath + OUString("/user"));
- if ((rc != FileBase::E_None) && (rc != FileBase::E_EXIST))
- {
- if ( rc == FileBase::E_NOSPC )
- return UserInstall::E_NoDiskSpace;
- else if ( rc == FileBase::E_ACCES )
- return UserInstall::E_NoWriteAccess;
- else
- return UserInstall::E_Creation;
- }
-#endif
+bool isCreated() {
+ try {
+ return officecfg::Setup::Office::ooSetupInstCompleted::get();
+ } catch (css::uno::Exception & e) {
+ SAL_WARN("desktop.app", "ignoring Exception \"" << e.Message << "\"");
+ return false;
+ }
+}
- boost::shared_ptr< comphelper::ConfigurationChanges > batch(
- comphelper::ConfigurationChanges::create());
- officecfg::Setup::Office::ooSetupInstCompleted::set(true, batch);
- batch->commit();
+}
- return UserInstall::Created;
+Status finalize() {
+ OUString uri;
+ switch (utl::Bootstrap::locateUserInstallation(uri)) {
+ case utl::Bootstrap::PATH_EXISTS:
+ if (isCreated()) {
+ return EXISTED;
+ }
+ // fall through
+ case utl::Bootstrap::PATH_VALID:
+ return create(uri);
+ default:
+ return ERROR_OTHER;
}
}
+} }
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/desktop/source/app/userinstall.hxx b/desktop/source/app/userinstall.hxx
index e7a56bab7522..38e8021d4588 100644
--- a/desktop/source/app/userinstall.hxx
+++ b/desktop/source/app/userinstall.hxx
@@ -17,31 +17,25 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
+#ifndef INCLUDED_DESKTOP_SOURCE_APP_USERINSTALL_HXX
+#define INCLUDED_DESKTOP_SOURCE_APP_USERINSTALL_HXX
-#include <sal/types.h>
-#include <rtl/ustring.hxx>
-
-namespace desktop
-{
-
-class UserInstall
-{
-public:
- enum UserInstallStatus {
- Ok, // no error, existing user installation found
- Created, // no error, new user installation created
- E_Creation, // error while creating user install
- E_InvalidBaseinstall, // corrupt base installation
- E_SetupFailed, // external setup did not run correctly
- E_Configuration, // error while accessing configuration
- E_License, // License not accepted
- E_NoDiskSpace, // not enough disk space
- E_NoWriteAccess, // no write access
- E_Unknown // unknown error
- };
-
- static UserInstallStatus finalize();
+#include "sal/config.h"
+
+namespace desktop { namespace userinstall {
+
+enum Status {
+ EXISTED,
+ CREATED,
+ ERROR_NO_SPACE,
+ ERROR_CANT_WRITE,
+ ERROR_OTHER
};
-}
+
+Status finalize();
+
+} }
+
+#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */