just kick off another build
[moon.git] / src / xap.cpp
blob0f84439855346a07671fc899e3c67615a4f84599
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3 * xap.cpp:
5 * Contact:
6 * Moonlight List (moonlight-list@lists.ximian.com)
8 * Copyright 2008 Novell, Inc. (http://www.novell.com)
10 * See the LICENSE file included with the distribution for details.
14 #include <config.h>
16 #include <glib.h>
18 #include <string.h>
19 #include <stdlib.h>
21 #include "zip/unzip.h"
22 #include "xaml.h"
23 #include "error.h"
24 #include "utils.h"
25 #include "type.h"
26 #include "xap.h"
28 char *
29 Xap::Unpack (const char *fname)
31 unzFile zipfile;
32 char *xap_dir;
34 if (!(xap_dir = CreateTempDir (fname)))
35 return NULL;
37 if (!(zipfile = unzOpen (fname))) {
38 RemoveDir (xap_dir);
39 g_free (xap_dir);
40 return NULL;
43 // FIXME: at some point we'll want to pass 'true' here (as part of the
44 // fix for case-insensitive resource access)
45 if (!ExtractAll (zipfile, xap_dir, false)) {
46 RemoveDir (xap_dir);
47 unzClose (zipfile);
48 g_free (xap_dir);
49 return NULL;
52 return xap_dir;
55 Xap::Xap (XamlLoader *loader, char *xap_dir, DependencyObject *root)
57 this->loader = loader;
58 this->xap_dir = xap_dir;
59 this->root = root;
62 Xap::~Xap ()
64 g_free (xap_dir);
65 xap_dir = NULL;
68 Xap *
69 xap_create_from_file (XamlLoader *loader, const char *filename)
71 char *xap_dir = Xap::Unpack (filename);
72 Type::Kind element_type;
73 DependencyObject *element;
75 if (xap_dir == NULL)
76 return NULL;
78 // Load the AppManifest file
79 char *manifest = g_build_filename (xap_dir, "AppManifest.xaml", NULL);
80 element = loader->CreateDependencyObjectFromFile (manifest, false, &element_type);
81 g_free (manifest);
83 if (element_type != Type::DEPLOYMENT)
84 return NULL;
86 // TODO: Create a DependencyObject from the root node.
88 Xap *xap = new Xap (loader, xap_dir, element);
89 return xap;