예제 #1
0
        public void Update(float deltaTime, EUpdatePriority startPriority, EUpdatePriority endPriority)
        {
            int startIndex = (int)startPriority;
            int endIndex   = (int)endPriority;

            for (int i = startIndex; i <= endIndex; ++i)
            {
                List <CUpdateScope> updates = m_priorityUpdateBuckets[i];
                for (int j = updates.Count - 1; j >= 0; --j)
                {
                    CUpdateScope update = updates[j];
                    if (update.IsConnected())
                    {
                        update.Callback(deltaTime);
                    }
                    else
                    {
                        // If the update was disconnected remove it from the list
                        ContainerUtilities.RemoveSwapAt(updates, j);
                    }
                }

                List <CUpdateScope> singleUpdates = m_oneTimeUpdateBucket[i];
                for (int j = 0; j < singleUpdates.Count; j++)
                {
                    CUpdateScope update = singleUpdates[j];
                    if (update.IsConnected())
                    {
                        update.Callback(deltaTime);
                    }
                    update.Disconnect();
                }
                singleUpdates.Clear();
            }
        }
예제 #2
0
        private void Container_Change_Password_Click(object sender, RoutedEventArgs e)
        {
            if (Settings.ContainerOpen)
            {
                ContainerSetPassword containerSetPassword = new ContainerSetPassword();
                containerSetPassword.Owner = this; // for centering in parent window
                containerSetPassword.ShowDialog();

                if (containerSetPassword.PasswordSet)
                {
                    string password = containerSetPassword.PasswordText;

                    (Settings.ContainerOuter, Settings.ContainerKey) = ContainerUtilities.CreateOuterContainer(password);

                    Settings.ContainerSaved = false;

                    UpdateContainerText();

                    MessageBox.Show("Password Changed", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
                }
            }
            else
            {
                MessageBox.Show("No container open", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
예제 #3
0
        private void ContainerWrite(string path)
        {
            byte[] contents;

            try
            {
                contents = ContainerUtilities.EncryptOuterContainer(Settings.ContainerOuter, Settings.ContainerInner, Settings.ContainerKey);
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Format("Failed to encrypt container: {0}", ex.Message), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            try
            {
                File.WriteAllBytes(path, contents);
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Format("Failed to write file: {0}", ex.Message), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            Settings.ContainerPath  = path;
            Settings.ContainerSaved = true;

            UpdateContainerText();
        }
예제 #4
0
        private void Container_New_Click(object sender, RoutedEventArgs e)
        {
            if (Settings.ContainerOpen)
            {
                MessageBox.Show("A container is already open", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            ContainerSetPassword containerSetPassword = new ContainerSetPassword();

            containerSetPassword.Owner = this; // for centering in parent window
            containerSetPassword.ShowDialog();

            if (containerSetPassword.PasswordSet)
            {
                string password = containerSetPassword.PasswordText;

                Settings.ContainerOpen  = true;
                Settings.ContainerSaved = false;
                Settings.ContainerPath  = string.Empty;
                (Settings.ContainerOuter, Settings.ContainerKey) = ContainerUtilities.CreateOuterContainer(password);
                Settings.ContainerInner = ContainerUtilities.CreateInnerContainer();

                UpdateContainerText();
            }
        }
예제 #5
0
        public void UpdateResources(DeviceContext deviceContext)
        {
            for (int i = m_waitingAssets.Count - 1; i >= 0; --i)
            {
                CAsset asset = m_waitingAssets[i];
                if (asset.IsLoaded)
                {
                    CResource resource = m_registeredResources[asset.Guid];
                    System.Diagnostics.Debug.Assert(resource != null);
                    Task.Run(() => CreateResource(resource, asset));

                    ContainerUtilities.RemoveSwapAt(m_waitingAssets, i);
                    break;
                }
            }

            lock (m_resourceMutex)
            {
                for (int i = 0; i < m_waitingResources.Count; ++i)
                {
                    m_waitingResources[i].InitWithContext(m_graphicsDevice, deviceContext);
                }
                m_waitingResources.Clear();
            }
        }
예제 #6
0
        void ContainerEdit_Closing(object sender, CancelEventArgs e)
        {
            string currentContainer = ContainerUtilities.SerializeInnerContainer(Settings.ContainerInner).OuterXml;

            if (OriginalContainer != currentContainer)
            {
                Settings.ContainerSaved = false;
            }
        }
예제 #7
0
 public void Update(float deltaTime)
 {
     for (int i = m_remainingTimes.Count - 1; i >= 0; --i)
     {
         m_remainingTimes[i] -= deltaTime;
         if (m_remainingTimes[i] <= 0.0f)
         {
             ContainerUtilities.RemoveSwapAt(m_remainingTimes, i);
             ContainerUtilities.RemoveSwapAt(m_persistentDrawCommands, i);
         }
     }
 }
예제 #8
0
 public void Update(float deltaTime)
 {
     for (int i = m_lineRemainingTime.Count - 1; i >= 0; --i)
     {
         float timeRemaining = m_lineRemainingTime[i] - deltaTime;
         m_lineRemainingTime[i] = timeRemaining;
         if (timeRemaining <= 0.0f)
         {
             ContainerUtilities.RemoveSwapAt(m_lineRemainingTime, i);
             ContainerUtilities.RemoveSwapAt(m_persistentLineData, i);
         }
     }
 }
예제 #9
0
        public ContainerEdit()
        {
            InitializeComponent();

            OriginalContainer = ContainerUtilities.SerializeInnerContainer(Settings.ContainerInner).OuterXml;

            keysListView.ItemsSource = Settings.ContainerInner.Keys;

            keysListView.SelectionChanged += KeysListView_SelectionChanged;

            groupsListView.ItemsSource = Settings.ContainerInner.Groups;

            groupsListView.SelectionChanged += GroupsListView_SelectionChanged;
        }
예제 #10
0
 public void Update(float deltaTime)
 {
     for (int i = 0; i < (int)EDebugPrimitiveType.Count; i++)
     {
         List <float> remainingTimes = m_remainingTimesPerPrimitive[i];
         for (int j = remainingTimes.Count - 1; j >= 0; --j)
         {
             remainingTimes[j] -= deltaTime;
             if (remainingTimes[j] <= 0.0f)
             {
                 ContainerUtilities.RemoveSwapAt(remainingTimes, j);
                 ContainerUtilities.RemoveSwapAt(m_persistentDrawDataPerPrimitive[i], j);
             }
         }
     }
 }
예제 #11
0
        private void Container_Open_Click(object sender, RoutedEventArgs e)
        {
            if (Settings.ContainerOpen)
            {
                MessageBox.Show("A container is already open", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter = "Encrypted Key Container (*.ekc)|*.ekc|All files (*.*)|*.*";

            if (openFileDialog.ShowDialog() == true)
            {
                string filePath = openFileDialog.FileName;

                if (filePath.Equals(string.Empty))
                {
                    MessageBox.Show("No file selected", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }

                ContainerEnterPassword containerEnterPassword = new ContainerEnterPassword();
                containerEnterPassword.Owner = this; // for centering in parent window
                containerEnterPassword.ShowDialog();

                if (containerEnterPassword.PasswordSet)
                {
                    string password = containerEnterPassword.PasswordText;

                    byte[] fileContents;

                    try
                    {
                        fileContents = File.ReadAllBytes(filePath);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(string.Format("Failed to read file: {0}", ex.Message), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                        return;
                    }

                    OuterContainer outerContainer;
                    InnerContainer innerContainer;
                    byte[]         key;

                    try
                    {
                        (outerContainer, innerContainer, key) = ContainerUtilities.DecryptOuterContainer(fileContents, password);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(string.Format("Failed to decrypt container: {0}", ex.Message), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                        return;
                    }

                    Settings.ContainerOpen  = true;
                    Settings.ContainerSaved = true;
                    Settings.ContainerPath  = filePath;
                    Settings.ContainerKey   = key;
                    Settings.ContainerOuter = outerContainer;
                    Settings.ContainerInner = innerContainer;

                    UpdateContainerText();
                }
            }
        }
예제 #12
0
        /// <summary>Open a container given all the settings</summary>
        /// <param name="path">Path to container on local file system</param>
        /// <param name="mode">See System.IO.FileMode in .NET SDK</param>
        /// <param name="access">See System.IO.FileAccess in .NET SDK</param>
        /// <param name="share">See System.IO.FileShare in .NET SDK</param>
        /// <param name="sectorSize">Compound File sector size, must be 512 or 4096</param>
        /// <returns>StorageRoot instance representing the file</returns>
        internal static StorageRoot Open(
            string path,
            FileMode mode,
            FileAccess access,
            FileShare share,
            int sectorSize)
        {
            int grfMode     = 0;
            int returnValue = 0;

            // Simple path validation
            ContainerUtilities.CheckStringAgainstNullAndEmpty(path, "Path");

            Guid IID_IStorage = new Guid(0x0000000B, 0x0000, 0x0000, 0xC0, 0x00,
                                         0x00, 0x00, 0x00, 0x00, 0x00, 0x46);

            IStorage newRootStorage;

            ////////////////////////////////////////////////////////////////////
            // Generate STGM from FileMode
            switch (mode)
            {
            case FileMode.Append:
                throw new ArgumentException(
                          SR.FileModeUnsupported);

            case FileMode.Create:
                grfMode |= SafeNativeCompoundFileConstants.STGM_CREATE;
                break;

            case FileMode.CreateNew:
            {
                FileInfo existTest = new FileInfo(path);
                if (existTest.Exists)
                {
                    throw new IOException(
                              SR.FileAlreadyExists);
                }
            }
                goto case FileMode.Create;

            case FileMode.Open:
                break;

            case FileMode.OpenOrCreate:
            {
                FileInfo existTest = new FileInfo(path);
                if (existTest.Exists)
                {
                    // File exists, use open code path
                    goto case FileMode.Open;
                }
                else
                {
                    // File does not exist, use create code path
                    goto case FileMode.Create;
                }
            }

            case FileMode.Truncate:
                throw new ArgumentException(
                          SR.FileModeUnsupported);

            default:
                throw new ArgumentException(
                          SR.FileModeInvalid);
            }

            // Generate the access flags from the access parameter
            SafeNativeCompoundFileMethods.UpdateModeFlagFromFileAccess(access, ref grfMode);

            // Generate STGM from FileShare

            // Note: the .NET SDK does not specify the proper behavior in reaction to
            //  incompatible flags being sent in together.  Should ArgumentException be
            //  thrown?  Or do some values "trump" others?
            if (0 != (share & FileShare.Inheritable))
            {
                throw new ArgumentException(
                          SR.FileShareUnsupported);
            }
            else if (share == FileShare.None) // FileShare.None is zero, using "&" to check causes unreachable code error
            {
                grfMode |= SafeNativeCompoundFileConstants.STGM_SHARE_EXCLUSIVE;
            }
            else if (share == FileShare.Read)
            {
                grfMode |= SafeNativeCompoundFileConstants.STGM_SHARE_DENY_WRITE;
            }
            else if (share == FileShare.Write)
            {
                grfMode |= SafeNativeCompoundFileConstants.STGM_SHARE_DENY_READ; // Note that this makes little sense when we don't support combination of flags
            }
            else if (share == FileShare.ReadWrite)
            {
                grfMode |= SafeNativeCompoundFileConstants.STGM_SHARE_DENY_NONE;
            }
            else
            {
                throw new ArgumentException(
                          SR.FileShareInvalid);
            }

            if (0 != (grfMode & SafeNativeCompoundFileConstants.STGM_CREATE))
            {
                // STGM_CREATE set, call StgCreateStorageEx.
                returnValue = SafeNativeCompoundFileMethods.SafeStgCreateStorageEx(
                    path,
                    grfMode,
                    stgFormatDocFile,
                    0,
                    IntPtr.Zero,
                    IntPtr.Zero,
                    ref IID_IStorage,
                    out newRootStorage);
            }
            else
            {
                // STGM_CREATE not set, call StgOpenStorageEx.
                returnValue = SafeNativeCompoundFileMethods.SafeStgOpenStorageEx(
                    path,
                    grfMode,
                    stgFormatDocFile,
                    0,
                    IntPtr.Zero,
                    IntPtr.Zero,
                    ref IID_IStorage,
                    out newRootStorage);
            }

            switch (returnValue)
            {
            case SafeNativeCompoundFileConstants.S_OK:
                return(StorageRoot.CreateOnIStorage(
                           newRootStorage));

            case SafeNativeCompoundFileConstants.STG_E_FILENOTFOUND:
                throw new FileNotFoundException(
                          SR.ContainerNotFound);

            case SafeNativeCompoundFileConstants.STG_E_INVALIDFLAG:
                throw new ArgumentException(
                          SR.StorageFlagsUnsupported,
                          new COMException(
                              SR.CFAPIFailure,
                              returnValue));

            default:
                throw new IOException(
                          SR.ContainerCanNotOpen,
                          new COMException(
                              SR.CFAPIFailure,
                              returnValue));
            }
        }
예제 #13
0
 public override int GetHashCode()
 {
     return(ContainerUtilities.CombineHashes(m_entityId, m_componentId));
 }
예제 #14
0
        private void InitializeEntityMenues()
        {
            List <CAddComponentEntryViewModel> tempList = new List <CAddComponentEntryViewModel>(128);
            Dictionary <string, List <CAddComponentEntryViewModel> > components = new Dictionary <string, List <CAddComponentEntryViewModel> >(12);

            foreach (var type in CKlaxScriptRegistry.Instance.Types)
            {
                if (type.Type.IsSubclassOf(typeof(CEntityComponent)))
                {
                    KlaxComponentAttribute attribute = type.Type.GetCustomAttribute <KlaxComponentAttribute>();

                    if (attribute.HideInEditor)
                    {
                        continue;
                    }

                    CAddComponentEntryViewModel vm = new CAddComponentEntryViewModel(type.Name, type.Type);

                    if (components.TryGetValue(attribute.Category, out List <CAddComponentEntryViewModel> list))
                    {
                        list.Add(vm);
                    }
                    else
                    {
                        List <CAddComponentEntryViewModel> newList = new List <CAddComponentEntryViewModel>(8);
                        components.Add(attribute.Category, newList);

                        newList.Add(vm);
                    }
                }
            }

            List <CAddComponentCategoryViewModel> orderedList = new List <CAddComponentCategoryViewModel>(components.Count);

            foreach (var entry in components)
            {
                CAddComponentCategoryViewModel vm = new CAddComponentCategoryViewModel(entry.Key, entry.Value);
                orderedList.Add(vm);
            }

            orderedList = orderedList.OrderBy(p => p.Name).ToList();
            //Always show Common on top
            for (int i = 0, count = orderedList.Count; i < count; i++)
            {
                if (orderedList[i].Name == "Common")
                {
                    ContainerUtilities.Swap(orderedList, i, 0);
                    break;
                }
            }

            m_addComponentMenuCategories = new ObservableCollection <CAddComponentCategoryViewModel>(orderedList);

            m_entityCommands = new ObservableCollection <CEntityCommandViewModel>();
            m_entityCommands.Add(new CEntityCommandViewModel("Save as Asset", new CRelayCommand((obj) =>
            {
                EntityCommandsMenuOpen = false;

                CAssetBrowserViewModel assetBrowser = CWorkspace.Instance.GetTool <CAssetBrowserViewModel>();
                string assetPath = assetBrowser.ActiveDirectory;
                SEntityId id     = m_selectedObject.GetTargetEntityId();

                CEngine.Instance.Dispatch(EEngineUpdatePriority.BeginFrame, () =>
                {
                    CEntity entity = id.GetEntity();
                    CEntityAsset <CEntity> .CreateFromEntity(entity, assetPath);
                    Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)(() =>
                    {
                        assetBrowser.UpdateShownAssets();
                    }));
                });
            })));
        }