public void RequestRoomBundles()
        {
            // Generate temp bundle storage directory
            string roomBundleStorageDirectory = Config.Current.Room.CompileAbsoluteAssetDirectory() + "/temp";

            AbnormalDirectoryHandler.CreateDirectory(roomBundleStorageDirectory);
            //Directory.CreateDirectory(roomBundleStorageDirectory);

            Debug.debugging = true;
            Debug.Log("Testing whether room bundle was created at " + roomBundleStorageDirectory);
            if (Directory.Exists(roomBundleStorageDirectory))
            {
                Debug.Log("Room bundle storage directory exists!");
            }
            else
            {
                Debug.Log("Room bundle storage directory does NOT exist!");
            }
            Debug.debugging = false;

            Debug.Log("Room bundle storage directory = " + roomBundleStorageDirectory);
#if UNITY_ANDROID
            SocketClient_PC.RequestFiles(ServerFinder.serverIP, Config.Ports.AndroidRoomBundle, roomBundleStorageDirectory);
#else
            SocketClient_PC.RequestFiles(ServerFinder.serverIP, Config.Ports.RoomBundle, roomBundleStorageDirectory);
#endif

            InvokeRepeating("CopyRoomBundles", 3, 1);
        }
示例#2
0
        //public static void InstantiateRoomFromResources(string roomName)
        //{
        //    string matrixArrayFilepath = Config.AssetBundle.Current.CompileAbsoluteRoomPath(UWB_Texturing.Config.MatrixArray.CompileFilename(), roomName);
        //    string rawRoomBundlePath = Config.AssetBundle.Current.CompileAbsoluteBundlePath(UWB_Texturing.Config.AssetBundle.RawPackage.CompileFilename());
        //    string customMatricesDestinationDirectory = Config.AssetBundle.Current.CompileAbsoluteRoomDirectory(roomName);
        //    string customOrientationDestinationDirectory = Config.AssetBundle.Current.CompileAbsoluteRoomDirectory(roomName);
        //    string customMeshesDestinationDirectory = Config.AssetBundle.Current.CompileAbsoluteRoomDirectory(roomName);
        //    string textureImagesDestinationDirectory = Config.AssetBundle.Current.CompileAbsoluteRoomDirectory(roomName);
        //    UWB_Texturing.BundleHandler.InstantiateRoomFromResources(roomName, rawRoomBundlePath, customMatricesDestinationDirectory, customOrientationDestinationDirectory, customMeshesDestinationDirectory, textureImagesDestinationDirectory, matrixArrayFilepath);
        //}

        public static void GenerateRoomFolder(UWB_Texturing.RoomNameChangedEventArgs e)
        {
            string roomName = e.NewName;
            //string roomDirectory = Config.Room.CompileAbsoluteRoomDirectory(roomName);
            string roomDirectory = Config.Current.Room.CompileAbsoluteAssetDirectory(roomName);

            if (!Directory.Exists(roomDirectory))
            {
                AbnormalDirectoryHandler.CreateDirectory(roomDirectory);
            }
        }
示例#3
0
 void FixedUpdate()
 {
     if (!RoomName.Equals(UWB_Texturing.Config.RoomObject.GameObjectName))
     {
         UWB_Texturing.Config.RoomObject.GameObjectName = RoomName;
         // Make the directory for this room
         //string directoryPath = Config_Base.CompileAbsoluteRoomDirectory(RoomName);
         string directoryPath = Config.Current.Room.CompileAbsoluteAssetDirectory(RoomName);
         //string directoryPath = UWB_Texturing.Config.RoomObject.CompileAbsoluteAssetDirectory(RoomName);
         AbnormalDirectoryHandler.CreateDirectory(directoryPath);
     }
 }
示例#4
0
        public static new void ReceiveFiles(Socket socket, string receiveDirectory)
        {
            if (!Directory.Exists(receiveDirectory))
            {
                AbnormalDirectoryHandler.CreateDirectory(receiveDirectory);
            }

            int bufferLength = 1024;

            byte[] data             = new byte[bufferLength];
            int    numBytesReceived = 0;

            MemoryStream fileStream = new MemoryStream();

            int    headerIndex     = 0;
            int    dataLengthIndex = 0;
            string dataHeader      = string.Empty;

            do
            {
                // Get the first receive from the socket
                numBytesReceived = socket.Receive(data, bufferLength, SocketFlags.None);
                int numBytesAvailable = numBytesReceived;
                int dataIndex         = 0;

                // If there are any bytes that continue a file from the last buffer read, handle that here
                if (dataLengthIndex > 0 && dataLengthIndex < numBytesReceived)
                {
                    fileStream.Write(data, 0, dataLengthIndex);
                    string filename = dataHeader.Split(';')[headerIndex++];
                    File.WriteAllBytes(Path.Combine(receiveDirectory, filename), fileStream.ToArray());
                    // MemoryStream flush does literally nothing.
                    fileStream.Close();
                    fileStream.Dispose();
                    fileStream = new MemoryStream();
                }
                else if (numBytesReceived <= 0)
                {
                    string filename = dataHeader.Split(';')[headerIndex++];
                    File.WriteAllBytes(Path.Combine(receiveDirectory, filename), fileStream.ToArray());
                    // MemoryStream flush does literally nothing.
                    fileStream.Close();
                    fileStream.Dispose();
                    fileStream = new MemoryStream();
                }

                // While there are file pieces we can get from the gathered data,
                // determine where the bytes designating the lengths of files about to be
                // transferred over are and then grab the file lengths and file bytes
                while (dataLengthIndex >= 0 && dataLengthIndex < numBytesReceived)
                {
                    // Get the 4 bytes indicating the length
                    int dataLength = 0;
                    if (dataLengthIndex <= numBytesReceived - 4)
                    {
                        // If length is shown fully within the buffer (i.e. length bytes aren't split between reads)...
                        dataLength = System.BitConverter.ToInt32(data, dataLengthIndex);

                        if (dataLength <= 0)
                        {
                            // Handle case where end of stream is reached
                            break;
                        }
                    }
                    //else
                    else if (dataLengthIndex < numBytesReceived && dataLengthIndex > numBytesReceived - 4)
                    {
                        // Else length bytes are split between reads...
                        byte[] dataLengthBuffer         = new byte[4];
                        int    numDataLengthBytesCopied = numBytesReceived - dataLengthIndex;
                        System.Buffer.BlockCopy(data, dataLengthIndex, dataLengthBuffer, 0, numDataLengthBytesCopied);
                        numBytesReceived  = socket.Receive(data, bufferLength, SocketFlags.None);
                        numBytesAvailable = numBytesReceived;
                        System.Buffer.BlockCopy(data, 0, dataLengthBuffer, numDataLengthBytesCopied, 4 - numDataLengthBytesCopied);

                        dataLength       = System.BitConverter.ToInt32(dataLengthBuffer, 0);
                        dataLengthIndex -= numBytesReceived;
                    }
                    dataIndex         = dataLengthIndex + 4;
                    dataLengthIndex   = dataIndex + dataLength; // Update the data length index for the while loop check
                    numBytesAvailable = numBytesReceived - dataIndex;

                    // Handle instances where whole file is contained in part of buffer
                    if (numBytesAvailable > 0 && dataIndex + dataLength < numBytesAvailable)
                    {
                        byte[] fileData = new byte[dataLength];
                        System.Buffer.BlockCopy(data, dataIndex, fileData, 0, dataLength);
                        if (dataHeader.Equals(string.Empty))
                        {
                            // If the header hasn't been received yet
                            dataHeader = BytesToString(fileData);
                            //dataHeader = System.Text.Encoding.UTF8.GetString(fileData);
                        }
                        else
                        {
                            // If the header's been received, that means we're looking at actual file data
                            string filename = dataHeader.Split(';')[headerIndex++];
                            File.WriteAllBytes(Path.Combine(receiveDirectory, filename), fileData);
                        }
                    }
                }

                // Write remainder of bytes in buffer to the file memory stream to store for the next buffer read
                if (numBytesAvailable < 0)
                {
                    Debug.Log("TCP Error: Stream read logic error.");
                    break;
                }
                else
                {
                    fileStream.Write(data, dataIndex, numBytesAvailable);
                    dataLengthIndex -= numBytesReceived;
                }
                // continue;
            } while (numBytesReceived > 0);

            fileStream.Close();
            fileStream.Dispose();
//#if UNITY_EDITOR
//            UnityEditor.AssetDatabase.Refresh();
//#endif
        }
        public static async void ReceiveFilesAsync(StreamSocket socket, string receiveDirectory)
        {
            if (!Directory.Exists(receiveDirectory))
            {
                AbnormalDirectoryHandler.CreateDirectory(receiveDirectory);
            }

            MemoryStream fileStream = new MemoryStream();

            DataReader reader = new DataReader(socket.InputStream);

            uint   bufferLength     = 1048576;
            int    numBytesReceived = 0;
            int    headerIndex      = 0;
            int    dataLengthIndex  = 0;
            string dataHeader       = string.Empty;

            do
            {
                numBytesReceived = (int)(await reader.LoadAsync(bufferLength));
                int numBytesAvailable = numBytesReceived;
                int dataIndex         = 0;

                // If there are any bytes that continue a file from the last buffer read, handle that here
                //if (numBytesRemaining > 0)
                if (dataLengthIndex > 0 && dataLengthIndex < numBytesReceived)
                {
                    byte[] bytesRemaining = reader.ReadBuffer((uint)numBytesAvailable).ToArray();
                    fileStream.Write(bytesRemaining, 0, numBytesAvailable);

                    string filename = dataHeader.Split(';')[headerIndex++];
                    File.WriteAllBytes(Path.Combine(receiveDirectory, filename), fileStream.ToArray());

                    // fileStream.Close(); // Doesn't exist in UWP?
                    fileStream.Dispose();
                    fileStream = new MemoryStream();
                }

                //while (reader.UnconsumedBufferLength > 0)
                while (dataLengthIndex >= 0 && dataLengthIndex < numBytesReceived)
                {
                    // Read in the first four bytes for the length
                    int dataLength = 0;
                    if (dataLengthIndex <= numBytesReceived - 4)
                    {
                        // Convert to length
                        byte[] dataLengthBuffer = reader.ReadBuffer(4).ToArray();
                        dataLength = System.BitConverter.ToInt32(dataLengthBuffer, 0);

                        if (dataLength <= 0)
                        {
                            // Handle case where end of stream is reached
                            break;
                        }
                    }
                    //else
                    else if (dataLengthIndex < numBytesReceived && dataLengthIndex > numBytesReceived - 4)
                    {
                        // Else length bytes are split between reads...
                        MemoryStream dataLengthMS       = new MemoryStream();
                        uint         numDataLengthBytes = (uint)(numBytesReceived - dataLengthIndex);
                        dataLengthMS.Write(reader.ReadBuffer(numDataLengthBytes).ToArray(), dataLengthIndex, (int)numDataLengthBytes);


                        numBytesReceived   = (int)(await reader.LoadAsync(bufferLength));
                        numBytesAvailable  = numBytesReceived;
                        numDataLengthBytes = 4 - numDataLengthBytes;
                        dataLengthMS.Write(reader.ReadBuffer(numDataLengthBytes).ToArray(), 0, (int)numDataLengthBytes);

                        dataLength       = System.BitConverter.ToInt32(dataLengthMS.ToArray(), 0);
                        dataLengthIndex -= numBytesReceived;
                        dataLengthMS.Dispose();
                    }

                    // Handle instances where whole file is contained in part of buffer
                    if (numBytesAvailable > 0 && dataIndex + dataLength < numBytesAvailable)
                    {
                        if (dataHeader.Equals(string.Empty))
                        {
                            fileStream.Write(reader.ReadBuffer((uint)dataLength).ToArray(), 0, dataLength);

                            dataHeader = BytesToString(fileStream.ToArray());

                            fileStream.Dispose();
                            fileStream = new MemoryStream();
                        }
                        else
                        {
                            fileStream.Write(reader.ReadBuffer((uint)dataLength).ToArray(), 0, dataLength);

                            string filename = dataHeader.Split(';')[headerIndex++];
                            File.WriteAllBytes(Path.Combine(receiveDirectory, filename), fileStream.ToArray());

                            fileStream.Dispose();
                            fileStream = new MemoryStream();
                        }
                    }
                }

                // Write remainder of bytes in buffer to the file memory stream to store for the next buffer read
                if (numBytesAvailable < 0)
                {
                    break;
                }
                else
                {
                    fileStream.Write(reader.ReadBuffer((uint)numBytesAvailable).ToArray(), 0, numBytesAvailable);
                    dataLengthIndex -= (int)numBytesReceived;
                }
            } while (numBytesReceived > 0);

            fileStream.Dispose();
        }
        private void CopyRoomBundles()
        {
            string roomBundleStorageDirectory = Config.Current.Room.CompileAbsoluteAssetDirectory() + "/temp";

            string[] tempRoomNames = Directory.GetFiles(roomBundleStorageDirectory);
            Debug.Log("# of Room names found = " + tempRoomNames.Length);
            List <string> roomBundleList = new List <string>();

            foreach (string tempRoomName in tempRoomNames)
            {
                if (!Path.HasExtension(tempRoomName))
                {
                    string[] pass       = tempRoomName.Split('/');
                    string[] pass2      = pass[pass.Length - 1].Split('\\');
                    string   bundleName = pass2[pass2.Length - 1];
                    //roomNameList.Add(UWB_Texturing.Config.AssetBundle.RoomPackage.ExtractRoomName(bundleName));
                    roomBundleList.Add(bundleName);
                }
            }

            // Make room directories
            string[] roomBundles = roomBundleList.ToArray();
            foreach (string roomBundle in roomBundles)
            {
                string roomName = UWB_Texturing.Config.AssetBundle.RoomPackage.ExtractRoomName(roomBundle);
                Debug.Log("Making directory for room named: " + roomBundle);

                string roomDirectory = Config.Current.Room.CompileAbsoluteAssetDirectory(roomName);
                if (!Directory.Exists(roomDirectory))
                {
                    AbnormalDirectoryHandler.CreateDirectory(roomDirectory);
                }

                // Copy asset bundles to room directories
                string sourceFilePath;
                string destinationFilePath;
#if UNITY_EDITOR
                if (File.Exists(Config.Current.Room.CompileAbsoluteAssetPath(roomBundle)))
                {
                    Debug.LogError("Room asset bundle exists! File not copied to room directory to avoid potentially overwriting data. Manually copy from " + roomBundleStorageDirectory + " if you would like to update the room.");
                }
                else
                {
                    sourceFilePath      = Path.Combine(roomBundleStorageDirectory, roomBundle);
                    destinationFilePath = Config.Current.Room.CompileAbsoluteAssetPath(roomName, roomBundle);
                    File.Copy(sourceFilePath, destinationFilePath);
                }
#else
                sourceFilePath      = Path.Combine(roomBundleStorageDirectory, roomBundle);
                destinationFilePath = Config.Current.Room.CompileAbsoluteAssetPath(roomName, roomBundle);
                if (File.Exists(destinationFilePath))
                {
                    File.Delete(destinationFilePath);
                }
                File.Copy(sourceFilePath, destinationFilePath);
#endif

                // Copy asset bundles to asset bundle directories
                if (File.Exists(Config.Current.AssetBundle.CompileAbsoluteAssetPath(roomBundle)))
                {
                    File.Delete(Config.Current.AssetBundle.CompileAbsoluteAssetPath(roomBundle));
                }
                sourceFilePath      = Path.Combine(roomBundleStorageDirectory, roomBundle);
                destinationFilePath = Config.Current.AssetBundle.CompileAbsoluteAssetPath(roomBundle);
                File.Copy(sourceFilePath, destinationFilePath);

                // Remove file from temp folder
                File.Delete(Path.Combine(roomBundleStorageDirectory, roomBundle));
            }

            if (Directory.GetFiles(roomBundleStorageDirectory).Length <= 0)
            {
                CancelInvoke("CopyRoomBundles");

                // Clean up temp storage folder
                string[] tempFiles = Directory.GetFiles(roomBundleStorageDirectory);
                foreach (string tempFile in tempFiles)
                {
                    File.Delete(tempFile);
                }

                Directory.Delete(roomBundleStorageDirectory);

                // Generate the rooms
                UWB_Texturing.BundleHandler.UnpackAllFinalRoomTextureBundles();
            }
        }