/// <summary>
 /// Saves the file by ref file_name, file_path and data. Set this paramaters if you want to change full_path, file_name and data of file.
 /// </summary>
 /// <param name="file">File.</param>
 public void SaveFile(ref FileD file)
 {
     LoaderFile.CreateFileBinary(ref file.file_name, ref file.file_path, ref file.data);
     Database.file.AddFile(file);
 }
Пример #2
0
        public void UploadBuild(ref string request, ref byte[] buffer, ref int bytes, ref Socket remoteSocket)
        {
            List <FileD> files = LoaderFile.LoadingFiles(ref request, ref buffer, ref bytes, ref count);

            if (files != null)
            {
                if (files.Count == 1)
                {
                    FileD  file     = files[0];
                    string app_hash = Worker.uploader.GenerateHash(8);
                    file.file_path = Worker.uploader.Full_Path_Upload + app_hash + "/";
                    file.file_name = file.file_last_name;
                    if (file.file_type == "application")
                    {
                        Directory.CreateDirectory(file.file_path);
                        LoaderFile.CreateFileBinary(file.file_path + file.file_name, ref file.buffer);
                        App app = null;
                        switch (file.file_extension)
                        {
                        case "vnd.android.package-archive":
                            app = Worker.uploader.UploadAPK(file, app_hash);
                            break;

                        case "octet-stream":
                            app = Worker.uploader.UploadIpa(file, app_hash);
                            break;

                        default:
                            LoaderFile.DeleteFile(file);
                            Worker.uploader.DeleteDirectory(app_hash);
                            Worker.JsonAnswer(false, "Archive type that uploaded is wrong.", ref remoteSocket);
                            break;
                        }
                        if (app == null)
                        {
                            LoaderFile.DeleteFile(file);
                            Worker.uploader.DeleteDirectory(app_hash);
                            Worker.JsonAnswer(false, "Error of handle upload archive.", ref remoteSocket);
                            return;
                        }
                        int?uid = Worker.FindParamFromRequest(ref request, "uid", TypeCode.Int32);
                        if (uid != null)
                        {
                            if (Database.user.SelectId(uid) != null)
                            {
                                app.user_id = (int)uid;
                            }
                        }
                        else
                        {
                            app.user_id = -1;
                        }
                        Worker.JsonData(app, ref remoteSocket);
                        if (file.file_extension == "vnd.android.package-archive")
                        {
                            app = Worker.uploader.GetAPKSet(Worker.uploader.Full_Path_Upload + app_hash, app);
                        }
                        Database.app.Add(app);
                    }
                    else
                    {
                        Worker.JsonAnswer(false, "Wrong type of file.", ref remoteSocket);
                    }
                }
                else
                {
                    foreach (FileD file in files)
                    {
                        LoaderFile.DeleteFile(file);
                    }
                    Worker.JsonAnswer(false, "Get from request not required count files.", ref remoteSocket);
                }
            }
            else
            {
                Worker.JsonAnswer(false, "Can't get file from request.", ref remoteSocket);
            }
        }