Use CSIDL on MS-Windows platforms instead of FHS paths.
authorJ. Ali Harlow <ali@juiblex.co.uk>
Fri Jan 09 15:28:50 2009 +0000 (2009-01-09)
changeset 3405962a461a5a3
parent 339 159067260aad
child 341 0a11e755ccda
Use CSIDL on MS-Windows platforms instead of FHS paths.
configure.ac
librazor/root.c
     1.1 --- a/configure.ac	Fri Jan 09 12:32:57 2009 +0000
     1.2 +++ b/configure.ac	Fri Jan 09 15:28:50 2009 +0000
     1.3 @@ -36,7 +36,7 @@
     1.4  case $host_os in
     1.5      *mingw*)	AC_DEFINE([MSWIN_API], 1,
     1.6  		  [Define to 1 to use Microsoft Windows native API.])
     1.7 -		EXTRA_LIBS='-lws2_32'
     1.8 +		EXTRA_LIBS='-lshell32 -lws2_32'
     1.9  		mswin_api=yes;;
    1.10      *)		mswin_api=no;;
    1.11  esac
     2.1 --- a/librazor/root.c	Fri Jan 09 12:32:57 2009 +0000
     2.2 +++ b/librazor/root.c	Fri Jan 09 15:28:50 2009 +0000
     2.3 @@ -1,6 +1,7 @@
     2.4  /*
     2.5   * Copyright (C) 2008  Kristian Høgsberg <krh@redhat.com>
     2.6   * Copyright (C) 2008  Red Hat, Inc
     2.7 + * Copyright (C) 2009  J. Ali Harlow <ali@juiblex.co.uk>
     2.8   *
     2.9   * This program is free software; you can redistribute it and/or modify
    2.10   * it under the terms of the GNU General Public License as published by
    2.11 @@ -17,6 +18,8 @@
    2.12   * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
    2.13   */
    2.14  
    2.15 +#include "config.h"
    2.16 +
    2.17  #include <stdlib.h>
    2.18  #include <stdint.h>
    2.19  #include <stdio.h>
    2.20 @@ -27,6 +30,9 @@
    2.21  #include <fcntl.h>
    2.22  #include <limits.h>
    2.23  #include <assert.h>
    2.24 +#ifdef MSWIN_API
    2.25 +#include <shlobj.h>
    2.26 +#endif
    2.27  
    2.28  #include "razor.h"
    2.29  #include "razor-internal.h"
    2.30 @@ -36,7 +42,12 @@
    2.31  static const char system_repo_files_filename[] = "system-files.rzdb";
    2.32  
    2.33  static const char next_repo_filename[] = "system-next.rzdb";
    2.34 -static const char razor_root_path[] = "/var/lib/razor";
    2.35 +#ifdef MSWIN_API
    2.36 +#define RAZOR_ROOT_PATH	NULL
    2.37 +#else
    2.38 +#define RAZOR_ROOT_PATH	"/var/lib/razor"
    2.39 +#endif
    2.40 +static const char *razor_root_path = RAZOR_ROOT_PATH;
    2.41  
    2.42  struct razor_root {
    2.43  	struct razor_set *system;
    2.44 @@ -47,6 +58,21 @@
    2.45  	char new_path[PATH_MAX];
    2.46  };
    2.47  
    2.48 +static void
    2.49 +razor_root_init(void)
    2.50 +{
    2.51 +#ifdef MSWIN_API
    2.52 +	static char root_path[MAX_PATH];
    2.53 +	if (!razor_root_path) {
    2.54 +		SHGetFolderPath(NULL,
    2.55 +			CSIDL_COMMON_APPDATA | CSIDL_FLAG_DONT_VERIFY, NULL, 0,
    2.56 +			root_path);
    2.57 +		strcat(root_path, "\\Razor");
    2.58 +		razor_root_path = root_path;
    2.59 +	}
    2.60 +#endif
    2.61 +}
    2.62 +
    2.63  RAZOR_EXPORT int
    2.64  razor_root_create(const char *root)
    2.65  {
    2.66 @@ -56,6 +82,7 @@
    2.67  
    2.68  	assert (root != NULL);
    2.69  
    2.70 +	razor_root_init();
    2.71  	if (root[0] == '\0') {
    2.72  		/* root is file system root */
    2.73  	} else if (stat(root, &buf) < 0) {
    2.74 @@ -112,6 +139,7 @@
    2.75  
    2.76  	assert (root != NULL);
    2.77  
    2.78 +	razor_root_init();
    2.79  	image = malloc(sizeof *image);
    2.80  	if (image == NULL)
    2.81  		return NULL;
    2.82 @@ -166,6 +194,7 @@
    2.83  
    2.84  	assert (root != NULL);
    2.85  
    2.86 +	razor_root_init();
    2.87  	snprintf(path, sizeof path, "%s%s/%s",
    2.88  		 root, razor_root_path, system_repo_filename);
    2.89  	snprintf(details_path, sizeof details_path,
    2.90 @@ -216,6 +245,7 @@
    2.91  	assert (root != NULL);
    2.92  	assert (next != NULL);
    2.93  
    2.94 +	razor_root_init();
    2.95  	razor_set_write_to_fd(next, root->fd, RAZOR_REPO_FILE_MAIN);
    2.96  	root->next = next;
    2.97