2009-12-01 Jeffrey Stedfast <fejj@novell.com>
[moon.git] / src / xap.cpp
blob93ec88c8b838733fe50368d60c32a18e36bc086d
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 if (!ExtractAll (zipfile, xap_dir, CanonModeXap)) {
44 RemoveDir (xap_dir);
45 unzClose (zipfile);
46 g_free (xap_dir);
47 return NULL;
50 return xap_dir;
53 Xap::Xap (XamlLoader *loader, char *xap_dir, DependencyObject *root)
55 this->loader = loader;
56 this->xap_dir = xap_dir;
57 this->root = root;
60 Xap::~Xap ()
62 g_free (xap_dir);
63 xap_dir = NULL;
66 Xap *
67 xap_create_from_file (XamlLoader *loader, const char *filename)
69 char *xap_dir = Xap::Unpack (filename);
70 Type::Kind element_type;
71 DependencyObject *element;
73 if (xap_dir == NULL)
74 return NULL;
76 // Load the AppManifest file
77 char *manifest = g_build_filename (xap_dir, "appmanifest.xaml", NULL);
78 element = loader->CreateDependencyObjectFromFile (manifest, false, &element_type);
79 g_free (manifest);
81 if (element_type != Type::DEPLOYMENT)
82 return NULL;
84 // TODO: Create a DependencyObject from the root node.
86 Xap *xap = new Xap (loader, xap_dir, element);
87 return xap;