Beispiel #1
0
        public void InitData()
#endif
        {
#if !LIB
            mDataMemory = new Memory(dataSegmentSize);

            StreamResourceInfo dataSectionInfo = Application.GetResourceStream(new Uri("RebuildData\\" + dataName, UriKind.Relative));

            if (dataSectionInfo == null || dataSectionInfo.Stream == null)
            {
                MoSync.Util.CriticalError("No data_section.bin file available!");
            }

            Stream dataSection = dataSectionInfo.Stream;
            mDataMemory.WriteFromStream(0, dataSection, fileSize);
            dataSection.Close();

            int customEventDataSize = 60;
            sp -= customEventDataSize;
            mCustomEventPointer = dataSegmentSize - customEventDataSize;
#else
            mDataMemory         = new SystemMemory();
            mCustomEventPointer = MosyncLibrary.WindowsPhoneRuntimeComponent.GetValidEventPointer();
#endif
        }
Beispiel #2
0
         public void InitData()
#endif
         {
#if !LIB
            mDataMemory = new Memory(dataSegmentSize);

            StreamResourceInfo dataSectionInfo = Application.GetResourceStream(new Uri("RebuildData\\" + dataName, UriKind.Relative));

            if (dataSectionInfo == null || dataSectionInfo.Stream == null)
            {
                MoSync.Util.CriticalError("No data_section.bin file available!");
            }

            Stream dataSection = dataSectionInfo.Stream;
            mDataMemory.WriteFromStream(0, dataSection, fileSize);
            dataSection.Close();

            int customEventDataSize = 60;
            sp -= customEventDataSize;
            mCustomEventPointer = dataSegmentSize - customEventDataSize;
#else
            mDataMemory = new SystemMemory();
			mCustomEventPointer = MosyncLibrary.WindowsPhoneRuntimeComponent.GetValidEventPointer();
#endif
        }
Beispiel #3
0
        public void InitData(String dataName, int fileSize, int dataSegmentSize)
        {
            mDataMemory = new Memory(dataSegmentSize);

            StreamResourceInfo dataSectionInfo = Application.GetResourceStream(new Uri("RebuildData\\" + dataName, UriKind.Relative));

            if (dataSectionInfo == null || dataSectionInfo.Stream == null)
            {
                MoSync.Util.CriticalError("No data_section.bin file available!");
            }

            Stream dataSection = dataSectionInfo.Stream;
            mDataMemory.WriteFromStream(0, dataSection, fileSize);
            dataSection.Close();

            int customEventDataSize = 60;
            sp -= customEventDataSize;
            mCustomEventPointer = dataSegmentSize - customEventDataSize;
        }
Beispiel #4
0
        public void InitData(String dataName, int fileSize, int dataSegmentSize)
        {
            mDataMemory = new Memory(dataSegmentSize);

            StreamResourceInfo dataSectionInfo = Application.GetResourceStream(new Uri("RebuildData\\" + dataName, UriKind.Relative));

            if (dataSectionInfo == null || dataSectionInfo.Stream == null)
            {
                MoSync.Util.CriticalError("No data_section.bin file available!");
            }

            Stream dataSection = dataSectionInfo.Stream;

            mDataMemory.WriteFromStream(0, dataSection, fileSize);
            dataSection.Close();

            int customEventDataSize = 60;

            sp -= customEventDataSize;
            mCustomEventPointer = dataSegmentSize - customEventDataSize;
        }
        public void Init(Ioctls ioctls, Core core, Runtime runtime)
        {
            mCamera = new PhotoCamera(CameraType.Primary);
            mVideoBrush = new VideoBrush();
            mVideoBrush.SetSource(mCamera);
            mVideoBrush.Stretch = Stretch.Uniform;

            runtime.RegisterCleaner(delegate()
            {
                mCamera.Dispose();
                mCamera = null;
            });

            // this should be set according to the orientation of
            // the device I guess.
            mVideoBrush.RelativeTransform = new CompositeTransform()
            {
                CenterX = 0.5,
                CenterY = 0.5,
                Rotation = 90
            };

            ioctls.maCameraFormat = delegate(int _index, int _fmt)
            {
                System.Windows.Size dim;
                if (GetCameraFormat(_index, out dim) == false)
                    return MoSync.Constants.MA_CAMERA_RES_FAILED;

                core.GetDataMemory().WriteInt32(_fmt + MoSync.Struct.MA_CAMERA_FORMAT.width,
                    (int)dim.Width);
                core.GetDataMemory().WriteInt32(_fmt + MoSync.Struct.MA_CAMERA_FORMAT.height,
                    (int)dim.Height);

                return MoSync.Constants.MA_CAMERA_RES_OK;
            };

            ioctls.maCameraFormatNumber = delegate()
            {
                IEnumerable<System.Windows.Size> res = mCamera.AvailableResolutions;
                if (res == null) return 0;
                IEnumerator<System.Windows.Size> resolutions = res.GetEnumerator();
                resolutions.MoveNext();
                int number = 0;
                while (resolutions.Current != null)
                {
                    number++;
                }
                return number;
            };

            ioctls.maCameraStart = delegate()
            {
                return 0;
            };

            ioctls.maCameraStop = delegate()
            {
                return 0;
            };

            ioctls.maCameraSetPreview = delegate(int _widgetHandle)
            {
                // something like
                // videoBrush = ((CameraViewFinder)runtime.GetModule<MoSyncNativeUIModule>.GetWidget(_widgetHandle)).GetBrush();
                // videoBrush.SetSource(mCamera)
                IWidget w = runtime.GetModule<NativeUIModule>().GetWidget(_widgetHandle);
                if (w.GetType() != typeof(MoSync.NativeUI.CameraPreview))
                {
                    return MoSync.Constants.MA_CAMERA_RES_FAILED;
                }
                NativeUI.CameraPreview prev = (NativeUI.CameraPreview)w;
                System.Windows.Controls.Canvas canvas = prev.GetViewFinderCanvas();
                MoSync.Util.RunActionOnMainThreadSync(() =>
                {
                    canvas.Background = mVideoBrush;
                });

                return 0;
            };

            ioctls.maCameraSelect = delegate(int _cameraNumber)
            {
                CameraType cameraType = CameraType.Primary;
                if(_cameraNumber == MoSync.Constants.MA_CAMERA_CONST_BACK_CAMERA)
                {
                    cameraType = CameraType.Primary;
                }
                else if(_cameraNumber == MoSync.Constants.MA_CAMERA_CONST_FRONT_CAMERA)
                {
                    cameraType = CameraType.FrontFacing;
                }

                if(mCamera==null || mCamera.CameraType != cameraType)
                {
                    mCamera = new PhotoCamera(cameraType);
                    if(mVideoBrush == null)
                        mVideoBrush = new VideoBrush();
                    mVideoBrush.SetSource(mCamera);
                }

                return 0;
            };

            ioctls.maCameraNumber = delegate()
            {
                // front facing and back facing is the standard I believe.
                return 2;
            };

            ioctls.maCameraSnapshot = delegate(int _formatIndex, int _placeHolder)
            {
                AutoResetEvent are = new AutoResetEvent(false);

                System.Windows.Size dim;
                if (GetCameraFormat(_formatIndex, out dim) == false)
                    return MoSync.Constants.MA_CAMERA_RES_FAILED;

                mCamera.Resolution = dim;

                if (mCameraSnapshotDelegate != null)
                    mCamera.CaptureImageAvailable -= mCameraSnapshotDelegate;
                mCameraSnapshotDelegate = delegate(object o, ContentReadyEventArgs args)
                {
                    MoSync.Util.RunActionOnMainThreadSync(() =>
                    {
                        Resource res = runtime.GetResource(MoSync.Constants.RT_PLACEHOLDER, _placeHolder);
                        Stream data = args.ImageStream;
                        Memory dataMem = new Memory((int)data.Length);
                        dataMem.WriteFromStream(0, data, (int)data.Length);
                        res.SetInternalObject(dataMem);
                    });
                    are.Set();
                };

                mCamera.CaptureImageAvailable += mCameraSnapshotDelegate;

                mCamera.CaptureImage();

                are.WaitOne();
                return 0;
            };

            ioctls.maCameraSetProperty = delegate(int _property, int _value)
            {
                return 0;
            };

            ioctls.maCameraSelect = delegate(int _camera)
            {
                return 0;
            };

            ioctls.maCameraGetProperty = delegate(int _property, int _value, int _bufSize)
            {
                String property = core.GetDataMemory().ReadStringAtAddress(_property);

                if (property.Equals(MoSync.Constants.MA_CAMERA_MAX_ZOOM))
                {
                    core.GetDataMemory().WriteStringAtAddress(
                        _value,
                        "0",
                        _bufSize);
                }

                return 0;
            };

            ioctls.maCameraRecord = delegate(int _stopStartFlag)
            {
                return 0;
            };
        }
Beispiel #6
0
        public void Init(Ioctls ioctls, Core core, Runtime runtime)
        {
            IsolatedStorageFile isolatedStorage = IsolatedStorageFile.GetUserStoreForApplication();

            MoSync.SystemPropertyManager.RegisterSystemPropertyProvider("mosync.path.local",
                                                                        delegate(String key)
            {
                // The isolated storage becomes the "root"
                return("/");
            }
                                                                        );

            ioctls.maFileOpen = delegate(int _path, int _mode)
            {
                String path = core.GetDataMemory().ReadStringAtAddress(_path);
                path = ConvertPath(path);

                File       file   = null;
                FileAccess access = 0;

                if (_mode == MoSync.Constants.MA_ACCESS_READ)
                {
                    access = FileAccess.Read;
                }
                else if (_mode == MoSync.Constants.MA_ACCESS_READ_WRITE)
                {
                    access = FileAccess.ReadWrite;
                }
                else
                {
                    throw new Exception("Invalid file access mode");
                }

                file = new File(path, access);

                if (file.IsDirectory)
                {
                    if (isolatedStorage.FileExists(path))
                    {
                        return(MoSync.Constants.MA_FERR_WRONG_TYPE);
                    }
                }
                else
                {
                    if (isolatedStorage.DirectoryExists(path))
                    {
                        return(MoSync.Constants.MA_FERR_WRONG_TYPE);
                    }
                    try
                    {
                        file.TryOpen();
                    }
                    catch (IsolatedStorageException e)
                    {
                        MoSync.Util.Log(e);
                        return(MoSync.Constants.MA_FERR_GENERIC);
                    }
                }

                mFileHandles.Add(mNextFileHandle, file);
                return(mNextFileHandle++);
            };

            ioctls.maFileClose = delegate(int _file)
            {
                File file = mFileHandles[_file];
                file.Close();
                mFileHandles.Remove(_file);
                return(0);
            };

            ioctls.maFileRead = delegate(int _file, int _dst, int _len)
            {
                File file = mFileHandles[_file];
                if (file.IsDirectory)
                {
                    return(MoSync.Constants.MA_FERR_WRONG_TYPE);
                }
                IsolatedStorageFileStream fileStream = file.FileStream;
                if (fileStream == null)
                {
                    return(MoSync.Constants.MA_FERR_GENERIC);
                }
                core.GetDataMemory().WriteFromStream(_dst, fileStream, _len);
                return(0);
            };

            ioctls.maFileReadToData = delegate(int _file, int _data, int _offset, int _len)
            {
                File file = mFileHandles[_file];
                if (file.IsDirectory)
                {
                    return(MoSync.Constants.MA_FERR_WRONG_TYPE);
                }
                IsolatedStorageFileStream fileStream = file.FileStream;
                if (fileStream == null)
                {
                    return(MoSync.Constants.MA_FERR_GENERIC);
                }
                Resource dataRes = runtime.GetResource(MoSync.Constants.RT_BINARY, _data);
                Memory   data    = (Memory)dataRes.GetInternalObject();
                data.WriteFromStream(_offset, fileStream, _len);
                return(0);
            };

            ioctls.maFileWriteFromData = delegate(int _file, int _data, int _offset, int _len)
            {
                File file = mFileHandles[_file];
                if (file.IsDirectory)
                {
                    return(MoSync.Constants.MA_FERR_WRONG_TYPE);
                }
                IsolatedStorageFileStream fileStream = file.FileStream;
                if (fileStream == null)
                {
                    return(MoSync.Constants.MA_FERR_GENERIC);
                }
                Resource dataRes = runtime.GetResource(MoSync.Constants.RT_BINARY, _data);
                Memory   data    = (Memory)dataRes.GetInternalObject();
                byte[]   bytes   = new byte[_len];
                data.ReadBytes(bytes, _offset, _len);
                fileStream.Write(bytes, 0, _len);
                fileStream.Flush();
                return(0);
            };

            ioctls.maFileWrite = delegate(int _file, int _src, int _len)
            {
                File file = mFileHandles[_file];
                if (file.IsDirectory)
                {
                    return(MoSync.Constants.MA_FERR_WRONG_TYPE);
                }
                IsolatedStorageFileStream fileStream = file.FileStream;
                if (fileStream == null)
                {
                    return(MoSync.Constants.MA_FERR_GENERIC);
                }
                byte[] bytes = new byte[_len];
                core.GetDataMemory().ReadBytes(bytes, _src, _len);
                fileStream.Write(bytes, 0, _len);
                fileStream.Flush();
                return(0);
            };

            ioctls.maFileSeek = delegate(int _file, int _offset, int _whence)
            {
                File file = mFileHandles[_file];
                if (file.IsDirectory)
                {
                    return(MoSync.Constants.MA_FERR_WRONG_TYPE);
                }
                IsolatedStorageFileStream fileStream = file.FileStream;
                SeekOrigin origin;
                switch (_whence)
                {
                case MoSync.Constants.MA_SEEK_SET:
                    origin = SeekOrigin.Begin;
                    break;

                case MoSync.Constants.MA_SEEK_CUR:
                    origin = SeekOrigin.Current;
                    break;

                case MoSync.Constants.MA_SEEK_END:
                    origin = SeekOrigin.End;
                    break;

                default:
                    throw new Exception("maFileSeek whence");
                }

                try
                {
                    return((int)fileStream.Seek(_offset, origin));
                }
                catch (IOException e)
                {
                    MoSync.Util.Log(e);
                    return(MoSync.Constants.MA_FERR_GENERIC);
                }
            };

            ioctls.maFileTell = delegate(int _file)
            {
                File file = mFileHandles[_file];
                if (file.IsDirectory)
                {
                    return(MoSync.Constants.MA_FERR_WRONG_TYPE);
                }
                IsolatedStorageFileStream fileStream = file.FileStream;
                return((int)fileStream.Position);
            };

            ioctls.maFileExists = delegate(int _file)
            {
                File file = mFileHandles[_file];
                return(file.Exists ? 1 : 0);
            };

            ioctls.maFileCreate = delegate(int _file)
            {
                File file = mFileHandles[_file];
                if (file.Exists)
                {
                    return(MoSync.Constants.MA_FERR_GENERIC);
                }
                file.Create();
                return(0);
            };

            ioctls.maFileDelete = delegate(int _file)
            {
                File file = mFileHandles[_file];
                try
                {
                    file.Delete();
                }
                catch (IsolatedStorageException e)
                {
                    MoSync.Util.Log(e);
                    return(MoSync.Constants.MA_FERR_GENERIC);
                }
                return(0);
            };

            ioctls.maFileSize = delegate(int _file)
            {
                File file = mFileHandles[_file];
                return(file.Size());
            };

            ioctls.maFileAvailableSpace = delegate(int _file)
            {
                File file = mFileHandles[_file];
                return(file.AvailableSpace());
            };

            ioctls.maFileTotalSpace = delegate(int _file)
            {
                File file = mFileHandles[_file];
                return(file.TotalSpace());
            };

            ioctls.maFileDate = delegate(int _file)
            {
                File file = mFileHandles[_file];
                return(Util.ToUnixTimeUtc(file.Date().ToFileTime()));
            };

            ioctls.maFileRename = delegate(int _file, int _newName)
            {
                File   file    = mFileHandles[_file];
                String newName = core.GetDataMemory().ReadStringAtAddress(_newName);
                newName = ConvertPath(newName);
                if (newName.Contains("\\"))
                {
                    if (newName[0] != '\\')
                    {
                        throw new Exception("Invalid newName");
                    }
                }
                else
                {   // add directory of old file.
                    newName = Path.GetDirectoryName(file.Path) + "\\" + newName;
                }
                file.Rename(newName);
                return(0);
            };

            ioctls.maFileTruncate = delegate(int _file, int _offset)
            {
                File file = mFileHandles[_file];
                file.Truncate(_offset);
                return(0);
            };

            ioctls.maFileListStart = delegate(int _path, int _filter, int _sorting)
            {
                // todo: respect _sorting.
                String path = core.GetDataMemory().ReadStringAtAddress(_path);
                path = ConvertPath(path);
                String filter           = core.GetDataMemory().ReadStringAtAddress(_filter);
                String pattern          = path + filter;
                IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication();
                FileList            fl  = new FileList();
                fl.dirs  = isf.GetDirectoryNames(pattern);
                fl.files = isf.GetFileNames(pattern);
                fl.pos   = 0;

                mFileListHandles.Add(mNextFileListHandle, fl);
                return(mNextFileListHandle++);
            };

            ioctls.maFileListNext = delegate(int _list, int _nameBuf, int _bufSize)
            {
                FileList fl = mFileListHandles[_list];
                String   name;
                if (fl.pos < fl.dirs.Length)
                {
                    name = fl.dirs[fl.pos] + "/";
                }
                else if (fl.pos < fl.dirs.Length + fl.files.Length)
                {
                    name = fl.files[fl.pos - fl.dirs.Length];
                }
                else
                {
                    return(0);
                }
                if (name.Length >= _bufSize)
                {
                    return(name.Length);
                }
                core.GetDataMemory().WriteStringAtAddress(_nameBuf,
                                                          name, _bufSize);
                fl.pos++;
                return(name.Length);
            };

            ioctls.maFileListClose = delegate(int _list)
            {
                FileList fl = mFileListHandles[_list];
                mFileListHandles.Remove(_list);
                return(0);
            };
        }
Beispiel #7
0
        public bool LoadResources(Stream file)
        {
            if (MoSync.Util.StreamReadInt8(file) != 'M')
            {
                return(false);
            }
            if (MoSync.Util.StreamReadInt8(file) != 'A')
            {
                return(false);
            }
            if (MoSync.Util.StreamReadInt8(file) != 'R')
            {
                return(false);
            }
            if (MoSync.Util.StreamReadInt8(file) != 'S')
            {
                return(false);
            }

            uint numResources = ReadUnsignedVarInt(file);
            uint resSize      = ReadUnsignedVarInt(file);


            mCurrentResourceHandle = 1;

            while (true)
            {
                byte type = MoSync.Util.StreamReadUint8(file);
                if (type == 0)
                {
                    break;
                }

                uint size = ReadUnsignedVarInt(file);
                Util.Log("Resource type " + type + ", size " + size + "\n");

                Resource resource = new Resource(null, type);
                mResources.Add(mCurrentResourceHandle, resource);

                switch (type)
                {
                case MoSync.Constants.RT_PLACEHOLDER:
                    break;

                case MoSync.Constants.RT_UBIN:
                case MoSync.Constants.RT_BINARY:
                    Memory memory = new Memory((int)size);
                    memory.WriteFromStream(0, file, (int)size);
                    resource.SetInternalObject(memory);
                    break;

                case MoSync.Constants.RT_IMAGE:
                    byte[] bytes = new byte[size];
                    file.Read(bytes, 0, (int)size);
                    using (MemoryStream ms = new MemoryStream(bytes, 0, bytes.Length))
                    {
                        /*
                         * MoSync.Util.RunActionOnMainThreadSync(() =>
                         * {
                         *  BitmapImage im = new BitmapImage();
                         *  im.CreateOptions = BitmapCreateOptions.None;
                         *  im.SetSource(ms);
                         *  WriteableBitmap wb = new WriteableBitmap(im);
                         *  resource.SetInternalObject(wb);
                         * });
                         */

                        resource.SetInternalObject(MoSync.Util.CreateWriteableBitmapFromStream(ms));
                        ms.Close();
                    }
                    break;

                case MoSync.Constants.RT_LABEL:
                    bytes = new byte[size];
                    file.Read(bytes, 0, (int)size);
                    if (bytes[size - 1] != 0)
                    {
                        throw new Exception("invalid label (no null terminator)");
                    }
                    String s = System.Text.Encoding.UTF8.GetString(bytes, 0, (int)size - 1);
                    if (mLabels.ContainsKey(s))
                    {
                        throw new Exception("duplicate label");
                    }
                    mLabels.Add(s, mCurrentResourceHandle);
                    break;

                default:
                    Util.Log("Unknown resource type " + type + ", size " + size + "\n");
                    file.Seek(size, SeekOrigin.Current);
                    break;
                }

                mCurrentResourceHandle++;
            }

            return(true);
        }