internal bool ExportPrim0(BotClient Client, SimObject exportPrim, OutputDelegate Failure, ImportSettings settings)
 {
     if (IsSkipped(exportPrim, settings)) return false;
     Simulator CurSim = exportPrim.GetSimulator();
     //settings.CurSim = CurSim;
     WorldObjects.EnsureSelected(exportPrim.LocalID, CurSim);
     string pathStem = Path.Combine(dumpDir, exportPrim.ID.ToString());
     if (settings.Contains("task") || showsMissingOnly)
     {
         exportPrim.StartGetTaskInventory();
     }
     if (settings.Contains("wait"))
     {
         var waitUntil = DateTime.Now.AddSeconds(10);
         bool needsLoop = true;
         while (needsLoop && waitUntil > DateTime.Now)
         {
             needsLoop = false;
             if (exportPrim.Properties == null || CogbotHelpers.IsNullOrZero(exportPrim.Properties.OwnerID))
             {
                 needsLoop = true;
             }
             if (settings.Contains("task"))
             {
                 var ti = exportPrim.TaskInventory;
                 if (ti == null)
                 {
                     needsLoop = true;
                 }
             }
         }
         if (needsLoop)
         {
             Success("needs loop " + named(exportPrim));
             string bissues = exportPrim.MissingData;
             if (!string.IsNullOrEmpty(bissues) && !settings.Allows(bissues ,exportPrim))
             {
                 Failure("Cant wait out the Issues " + bissues + ": " + named(exportPrim));
                 if (LocalFailures == 0) LocalFailures++;
               //  return;
             }
         }
     }
     string issues = exportPrim.MissingData;           
     if (!string.IsNullOrEmpty(issues) && !settings.Allows(issues, exportPrim))
     {
         Failure("Issues " + issues + " " + named(exportPrim));
         if (LocalFailures == 0) LocalFailures++;
         //return false;
     }
     //ImportCommand.PrimToCreate ptc = ImportCommand.Running.APrimToCreate(exportPrim.ID);
     //ptc._prim = exportPrim.Prim;
     bool passedOK = true;
     if (settings.Contains("llsd"))
     {
         SaveLLSD(Client, pathStem, exportPrim, Failure, settings);
     }
     if (exportPrim.IsRoot && (true || exportPrim.Children.Count > 0))
     {
         if (settings.Contains("link")) SaveLinksetInfo(Client, pathStem, exportPrim, Failure, settings);
         string exportFile = pathStem + ".link";
         //lock (fileWriterLock) if (File.Exists(exportFile))
         {
             foreach (var c in exportPrim.Children)
             {
                 var ch = ExportPrim(Client, c, Failure, settings);
                 if (!ch) passedOK = false;
             }
         }
     }
     if (settings.Contains("task"))
     {
         if (!SaveTaskInv(settings, Client, pathStem, exportPrim, Failure)) passedOK = false;
         // ImportCommand.PrimToCreate ptc = ImportCommand.Running.APrimToCreate(exportPrim.ID);
         //  if (!ptc.EnsureTaskInv()) return false;
     }
     if (!settings.Contains("dep")) return passedOK;
     AddRelatedTextures(exportPrim);
     SaveRelatedAssets(pathStem, exportPrim, Failure);
     return passedOK;
 }
Esempio n. 2
0
        public CmdResult Execute(string[] args, UUID fromAgentID, OutputDelegate WriteLine)
        {
            Client.Self.Movement.Camera.Far = 1023;
            Client.Self.Movement.SendUpdate(true);
            Exporting = this;
            IsExporting = true;
            var CurSim = Client.Network.CurrentSim;
            RegionHandle = CurSim.Handle;
            haveBeenTo.AddPoint(TheSimAvatar.SimPosition);
            AttemptSitMover();
            WorldObjects.MaintainSimObjectInfoMap = false;
            SimObjectImpl.AffordinancesGuessSimObjectTypes = false;
            WorldSystem.IgnoreKillObjects = true;
            inventoryHolder.Clear();
            lslScripts.Clear();
            successfullyExportedPrims.Clear();
            const string hlp = @"
            
            Toplevel Directives

            // todo  = shows what must be done for export to be complete (suggest adding verbose)
            // perms  = shows what perms are going to be a problem (suggest adding verbose)
            // clear - clear the export dir
            // reset - reset the exporter state
            // cache - blow away asset cache
            // move - begin moving arround
            // nomove - stop moving arround

            // spec [spec] - do only prims meeting spec (default is 'spec $region') 
            // incr - do only do what is 'todo'
            // nonincr - do things 'todo' but also 'redo' things already done

            // noperms = dont skip things when perms might be a problem
            // quietly = terser output
            // verbose = more verbose
            // request = will rerequest missing things like textures
            // force = will allow unequal LLSD files - this should only be used as last resort

            // users - users files 
            // groups - groups files 
            // terrain - terrain files 
            // parcels - parcels files 
            // estate - estate files (TODO)
            // siminfo - estate files (TODO)
            // llsd - llsd files 
            // links - operate on linset
            // deps - operate on dependant assets
            // dl - operate on dependant downloads
            // tasks - save task files
            // taskobj - task objects
            // all = llsd tasks deps links (dl and taskobj not included)

           
            ";
            if (args == null || args.Length == 0) return Failure(hlp);
            string[] nargs = { "$region" };
            ImportSettings arglist = new ImportSettings
                                         {
                                             CurSim = Client.Network.CurrentSim,
                                             GroupID = Client.Self.ActiveGroup
                                         };
            settings = arglist;
            if (args[0]=="hhp")
            {
                args = new string[] { "taskobjs", "nobuf", "all", "spec", "f0a89a9f-3f33-b2aa-2829-eaeec3d08b82" };
            }
            foreach (string s in args)
            {
                arglist.Add(s);
            }
            if (arglist.Contains("error")) return WriteErrors(args);
            if (arglist.Contains("help")) return Success(hlp);
            if (args.Length > 1)
            {
                int specIndex = Array.IndexOf(args, "spec");
                if (specIndex > 0)
                {
                    nargs = Parser.SplitOff(args, specIndex + 1);
                }

                int fnd = Array.IndexOf(args, "move");
                if (fnd > -1 && (fnd + 1 < args.Length))
                {
                    int mv;
                    if (int.TryParse(args[fnd + 1], out mv))
                    {
                        moveSleep = mv;
                        if ((fnd + 2 < args.Length) && int.TryParse(args[fnd + 2], out mv))
                        {
                            maxHeigth = mv;
                        }
                    }
                }
            }
            if (arglist.Contains("move"))
            {
                if (arglist.Contains("wps"))
                {
                    AddRegionWaypoints();
                }

                BeginMoving();
                GiveStatus();
                return Success("Began moving");
            }
            if (arglist.Contains("nomove"))
            {
                StopMoving();
                GiveStatus();
                return Success("Stopped moving");
            }
            quietly = arglist.Contains("quietly");
            if (arglist.Contains("prim"))
            {
                arglist.Add("llsd");
                arglist.Add("dep");
                arglist.Add("link");
            }
            if (arglist.Contains("all"))
            {
                arglist.Add("llsd");
                arglist.Add("task");
                arglist.Add("dep");
                arglist.Add("link");
            }

            needFiles = 0;
            taskobj = arglist.Contains("taskobj");
            forced = arglist.Contains("force") || arglist.Contains("forced");
            if (arglist.Contains("nonincr")) Incremental = false;
            if (arglist.Contains("incr")) Incremental = true;
            bool fileOnly = false;
            lock (fileWriterLock)
            {
                if (arglist.Contains("clear"))
                {
                    KillAllUnpacked(WriteLine, true);
                    PurgeExport();
                    arglist.Add("reset");
                }

                if (!Directory.Exists(dumpDir)) Directory.CreateDirectory(dumpDir);
                if (!Directory.Exists(assetDumpDir)) Directory.CreateDirectory(assetDumpDir);
                if (!Directory.Exists(terrainDir)) Directory.CreateDirectory(terrainDir);
                if (!Directory.Exists(siminfoDir)) Directory.CreateDirectory(siminfoDir);

                if (arglist.Contains("cache"))
                {
                    fileOnly = true;
                    PurgeCache();
                }
            }
            if (arglist.Contains("reset"))
            {
                slowlyExport.Clear();
                lock (ToDownloadAssets) ToDownloadAssets.Clear();
                lock (CompletedAssets) CompletedAssets.Clear();
                lock (PrimWaitingLinkset) PrimWaitingLinkset.Clear();
                lock (AllRelatedAssets) AllRelatedAssets.Clear();
                lock (PrimDepsAssets) PrimDepsAssets.Clear();
                lock (TaskAssetWaiting) TaskAssetWaiting.Clear();
                lock (CompletedTaskItem) CompletedTaskItem.Clear();
#if OBJECTUNPACKER
                lock (TasksRezed) TasksRezed.Clear();
#endif
                GiveStatus();
                return Success("Reset SimExport State");
            }

            if (fileOnly)
            {
                GiveStatus();
                return Success("Manipulated filesystem");
            }

            if (arglist.Contains("cleanup"))
            {
                return CleanupAfterExport(fromAgentID, WriteLine);
            }
            if (arglist.Contains("killtasks"))
            {
                KillAllUnpacked(WriteLine, true);
                return SuccessOrFailure();
            }
            IsExporting = true;
            FolderCalled("TaskInvHolder");
            //string file = args[args.Length - 1];
            int used;
            List<SimObject> PS = WorldSystem.GetPrimitives(nargs, out used);
            if (IsEmpty(PS)) return Failure("Cannot find objects from " + string.Join(" ", args));
            showsStatus = arglist.Contains("statu");
            showPermsOnly = arglist.Contains("perm");
            skipPerms = !arglist.Contains("obeyperm");
            showsMissingOnly = arglist.Contains("todo");
            if (showsMissingOnly) quietly = true;
            verbosely = arglist.Contains("verbose");
            if (verbosely && !arglist.Contains("quietly")) quietly = false;
            int missing = 0;
            var canExport = new List<SimObject>();
            int objects = 0;
            if (arglist.Contains("terrain"))
            {
                SaveTerrainHeight(arglist);
                StartTerrainDownload(arglist);
            }
            if (arglist.Contains("parcel"))
            {
                SaveParcelInfoCommand(arglist);
            }
            bool primsAtAll = arglist.Contains("link") || arglist.Contains("task") || arglist.Contains("llsd") ||
                              arglist.Contains("taskobj") || arglist.Contains("all");
            bool wasShouldBeMoving = shouldBeMoving;
            if (primsAtAll)
            {
                shouldBeMoving = false;
            }
            if (arglist.Contains("nobuf"))
            {
                PSBuf.Clear();
            }
            PSBuf.AddRange(PS);
            lock (Importing.MustExport)
            {
                foreach (UUID id in LockInfo.CopyOf(Importing.MustExport))
                {
                    var o = WorldObjects.GetSimObjectFromUUID(id);
                    if (o != null) PSBuf.Add(o);
                }
            }

            foreach (var P in PSBuf)
            {
                if (!primsAtAll) break;
                if (string.IsNullOrEmpty(IsComplete(P.ID, false, false, arglist))) continue;
                // skip attachments and avatars
                if (IsSkipped(P, arglist)) continue;
                if (!P.HasPrim)
                {
                    if (!quietly) Failure("Missing Prim: " + named(P));
                    continue;
                }
                if (P.RegionHandle != RegionHandle) continue;

                Vector3 sp;
                if (!P.TryGetSimPosition(out sp)) continue;

                objects++;
                string issues = P.MissingData;
                if (!string.IsNullOrEmpty(issues) && !arglist.Allows(issues, P))
                {
                    missing++;
                    if (!quietly) Failure("Issues " + issues + " " + named(P));
                    continue;
                }

                bool exportPossible =
                    checkPerms(Client, P, showPermsOnly ? (OutputDelegate)LocalFailure : SilientFailure, false) || skipPerms;
                if (exportPossible)
                {
                    SnagUsers(P);
                    canExport.Add(P);
                }
            }

            Success("Can export " + canExport.Count + " of " + objects);
            if (showPermsOnly) return Success("Shown perms");

            foreach (var P in canExport)
            {
                if (!primsAtAll) break;
                if (P is SimAvatar) continue;
                // skip attachments
                if (P.Parent is SimAvatar) continue;
                string issues = P.MissingData;
                if (!string.IsNullOrEmpty(issues) && !arglist.Allows(issues, P))
                {
                    continue;
                }
                //if (exportedPrims.Contains(P)) continue;
                LocalFailures = 0;
                PrimDepsAssets.Clear();
                ExportPrim(Client, P, LocalFailure, arglist);
                if (P.IsRoot)
                {
                    float pSimPositionZ = P.SimPosition.Z;
                    if (pSimPositionZ > maxHeigth)
                    {
                        maxHeigth = pSimPositionZ + 10;
                    }
                    seenObjectsAt.AddPoint(P.SimPosition);
                }
                if (LocalFailures == 0)
                {
                    if (!successfullyExportedPrims.Contains(P)) successfullyExportedPrims.Add(P);
                }
            }
            ExportRelatedAssets();
            if (showsStatus)
            {
                arglist.Add("link");
                arglist.Add("task");
                arglist.Add("llsd");
            }

            if (arglist.Contains("link"))
            {
                // lock (PrimWaitingLinkset)
                {
                    foreach (var pa in LockInfo.CopyOf(PrimWaitingLinkset))
                    {
                        var exportPrim = pa.Value.O;
                        if (verbosely) Failure("Awaiting Linkset " + named(exportPrim));
                        if (arglist.Contains("request"))
                        {
                            RequestLinksetInfo(Client, Path.Combine(dumpDir, exportPrim.ID.ToString()), exportPrim,
                                               WriteLine, arglist);
                        }
                    }
                }
            }

            if (arglist.Contains("task"))
            {
                lock (TaskAssetWaiting)
                {
                    foreach (var pa in LockInfo.CopyOf(TaskAssetWaiting))
                    {
                        UUID assetID = pa.Value.SourceItem.AssetUUID;
                        if (!CogbotHelpers.IsNullOrZero(assetID))
                        {
                            if (CompletedAssets.Contains(assetID))
                            {
                                int count = TaskAssetWaiting.Count;
                                TaskAssetWaiting.Remove(pa.Key);
                                if (TaskAssetWaiting.Count != count - 1)
                                {
                                    Failure("VERY BAD!");
                                }
                            }
                        }
                        if (verbosely) Failure("Awaiting TaskAsset " + pa.Value);
                        if (arglist.Contains("request"))
                        {
                            pa.Value.Request();
                        }
                    }
                }
            }
            ExportRelatedAssets();
            foreach (var assetID in LockInfo.CopyOf(ToDownloadAssets))
            {
                PingAssetCache(assetID);
            }

            if (arglist.Contains("dl"))
            {
                foreach (var assetID in LockInfo.CopyOf(ToDownloadAssets))
                {
                    AssetType assetType = assetTypeOf(assetID);
                    if (verbosely) Failure("Awaiting DL " + assetID + " " + assetType);
                    if (arglist.Contains("request"))
                    {
                        StartAssetDownload(null, assetID, assetType);
                    }
                }
            }
            if (arglist.Contains("user"))
            {
                RequestUsersAndGroups();
            }
            if (arglist.Contains("siprim"))
            {
                foreach (SimObject o in LockInfo.CopyOf(SIPrims))
                {
                    if (o.Prim.ParentID == 0)
                    {
                        Client.Inventory.RequestDeRezToInventory(o.LocalID, DeRezDestination.AgentInventoryCopy,
                        FolderCalled("UseSIForCompleteness"), UUID.Random());
                    }
                    else
                    {
                        Failure("Child SIPrim " + o);
                    }
                }
            }
            Success("Missing PrimData: " + missing);
            Success("Started XFERS " + ToDownloadCalledAssets.Count + " assets");
            shouldBeMoving = wasShouldBeMoving;
            GiveStatus();
            if (primsAtAll)
            {
                shouldBeMoving = wasShouldBeMoving;
            }
            return Success("Done");
        }
Esempio n. 3
0
        internal bool ExportPrim0(BotClient Client, SimObject exportPrim, OutputDelegate Failure, ImportSettings settings)
        {
            if (IsSkipped(exportPrim, settings))
            {
                return(false);
            }
            Simulator CurSim = exportPrim.GetSimulator();

            //settings.CurSim = CurSim;
            WorldObjects.EnsureSelected(exportPrim.LocalID, CurSim);
            string pathStem = Path.Combine(dumpDir, exportPrim.ID.ToString());

            if (settings.Contains("task") || showsMissingOnly)
            {
                exportPrim.StartGetTaskInventory();
            }
            if (settings.Contains("wait"))
            {
                var  waitUntil = DateTime.Now.AddSeconds(10);
                bool needsLoop = true;
                while (needsLoop && waitUntil > DateTime.Now)
                {
                    needsLoop = false;
                    if (exportPrim.Properties == null || CogbotHelpers.IsNullOrZero(exportPrim.Properties.OwnerID))
                    {
                        needsLoop = true;
                    }
                    if (settings.Contains("task"))
                    {
                        var ti = exportPrim.TaskInventory;
                        if (ti == null)
                        {
                            needsLoop = true;
                        }
                    }
                }
                if (needsLoop)
                {
                    Success("needs loop " + named(exportPrim));
                    string bissues = exportPrim.MissingData;
                    if (!string.IsNullOrEmpty(bissues) && !settings.Allows(bissues, exportPrim))
                    {
                        Failure("Cant wait out the Issues " + bissues + ": " + named(exportPrim));
                        if (LocalFailures == 0)
                        {
                            LocalFailures++;
                        }
                        //  return;
                    }
                }
            }
            string issues = exportPrim.MissingData;

            if (!string.IsNullOrEmpty(issues) && !settings.Allows(issues, exportPrim))
            {
                Failure("Issues " + issues + " " + named(exportPrim));
                if (LocalFailures == 0)
                {
                    LocalFailures++;
                }
                //return false;
            }
            //ImportCommand.PrimToCreate ptc = ImportCommand.Running.APrimToCreate(exportPrim.ID);
            //ptc._prim = exportPrim.Prim;
            bool passedOK = true;

            if (settings.Contains("llsd"))
            {
                SaveLLSD(Client, pathStem, exportPrim, Failure, settings);
            }
            if (exportPrim.IsRoot && (true || exportPrim.Children.Count > 0))
            {
                if (settings.Contains("link"))
                {
                    SaveLinksetInfo(Client, pathStem, exportPrim, Failure, settings);
                }
                string exportFile = pathStem + ".link";
                //lock (fileWriterLock) if (File.Exists(exportFile))
                {
                    foreach (var c in exportPrim.Children)
                    {
                        var ch = ExportPrim(Client, c, Failure, settings);
                        if (!ch)
                        {
                            passedOK = false;
                        }
                    }
                }
            }
            if (settings.Contains("task"))
            {
                if (!SaveTaskInv(settings, Client, pathStem, exportPrim, Failure))
                {
                    passedOK = false;
                }
                // ImportCommand.PrimToCreate ptc = ImportCommand.Running.APrimToCreate(exportPrim.ID);
                //  if (!ptc.EnsureTaskInv()) return false;
            }
            if (!settings.Contains("dep"))
            {
                return(passedOK);
            }
            AddRelatedTextures(exportPrim);
            SaveRelatedAssets(pathStem, exportPrim, Failure);
            return(passedOK);
        }
        public CmdResult Execute(string[] args, UUID fromAgentID, OutputDelegate WriteLine)
        {
            Client.Self.Movement.Camera.Far = 1023;
            Client.Self.Movement.SendUpdate(true);
            Exporting   = this;
            IsExporting = true;
            var CurSim = Client.Network.CurrentSim;

            RegionHandle = CurSim.Handle;
            haveBeenTo.AddPoint(TheSimAvatar.SimPosition);
            AttemptSitMover();
            WorldObjects.MaintainSimObjectInfoMap          = false;
            SimObjectImpl.AffordinancesGuessSimObjectTypes = false;
            WorldSystem.IgnoreKillObjects = true;
            inventoryHolder.Clear();
            lslScripts.Clear();
            successfullyExportedPrims.Clear();
            const string hlp = @"
            
            Toplevel Directives

            // todo  = shows what must be done for export to be complete (suggest adding verbose)
            // perms  = shows what perms are going to be a problem (suggest adding verbose)
            // clear - clear the export dir
            // reset - reset the exporter state
            // cache - blow away asset cache
            // move - begin moving arround
            // nomove - stop moving arround

            // spec [spec] - do only prims meeting spec (default is 'spec $region') 
            // incr - do only do what is 'todo'
            // nonincr - do things 'todo' but also 'redo' things already done

            // noperms = dont skip things when perms might be a problem
            // quietly = terser output
            // verbose = more verbose
            // request = will rerequest missing things like textures
            // force = will allow unequal LLSD files - this should only be used as last resort

            // users - users files 
            // groups - groups files 
            // terrain - terrain files 
            // parcels - parcels files 
            // estate - estate files (TODO)
            // siminfo - estate files (TODO)
            // llsd - llsd files 
            // links - operate on linset
            // deps - operate on dependant assets
            // dl - operate on dependant downloads
            // tasks - save task files
            // taskobj - task objects
            // all = llsd tasks deps links (dl and taskobj not included)

           
            ";

            if (args == null || args.Length == 0)
            {
                return(Failure(hlp));
            }
            string[]       nargs   = { "$region" };
            ImportSettings arglist = new ImportSettings
            {
                CurSim  = Client.Network.CurrentSim,
                GroupID = Client.Self.ActiveGroup
            };

            settings = arglist;
            if (args[0] == "hhp")
            {
                args = new string[] { "taskobjs", "nobuf", "all", "spec", "f0a89a9f-3f33-b2aa-2829-eaeec3d08b82" };
            }
            foreach (string s in args)
            {
                arglist.Add(s);
            }
            if (arglist.Contains("error"))
            {
                return(WriteErrors(args));
            }
            if (arglist.Contains("help"))
            {
                return(Success(hlp));
            }
            if (args.Length > 1)
            {
                int specIndex = Array.IndexOf(args, "spec");
                if (specIndex > 0)
                {
                    nargs = Parser.SplitOff(args, specIndex + 1);
                }

                int fnd = Array.IndexOf(args, "move");
                if (fnd > -1 && (fnd + 1 < args.Length))
                {
                    int mv;
                    if (int.TryParse(args[fnd + 1], out mv))
                    {
                        moveSleep = mv;
                        if ((fnd + 2 < args.Length) && int.TryParse(args[fnd + 2], out mv))
                        {
                            maxHeigth = mv;
                        }
                    }
                }
            }
            if (arglist.Contains("move"))
            {
                if (arglist.Contains("wps"))
                {
                    AddRegionWaypoints();
                }

                BeginMoving();
                GiveStatus();
                return(Success("Began moving"));
            }
            if (arglist.Contains("nomove"))
            {
                StopMoving();
                GiveStatus();
                return(Success("Stopped moving"));
            }
            quietly = arglist.Contains("quietly");
            if (arglist.Contains("prim"))
            {
                arglist.Add("llsd");
                arglist.Add("dep");
                arglist.Add("link");
            }
            if (arglist.Contains("all"))
            {
                arglist.Add("llsd");
                arglist.Add("task");
                arglist.Add("dep");
                arglist.Add("link");
            }

            needFiles = 0;
            taskobj   = arglist.Contains("taskobj");
            forced    = arglist.Contains("force") || arglist.Contains("forced");
            if (arglist.Contains("nonincr"))
            {
                Incremental = false;
            }
            if (arglist.Contains("incr"))
            {
                Incremental = true;
            }
            bool fileOnly = false;

            lock (fileWriterLock)
            {
                if (arglist.Contains("clear"))
                {
                    KillAllUnpacked(WriteLine, true);
                    PurgeExport();
                    arglist.Add("reset");
                }

                if (!Directory.Exists(dumpDir))
                {
                    Directory.CreateDirectory(dumpDir);
                }
                if (!Directory.Exists(assetDumpDir))
                {
                    Directory.CreateDirectory(assetDumpDir);
                }
                if (!Directory.Exists(terrainDir))
                {
                    Directory.CreateDirectory(terrainDir);
                }
                if (!Directory.Exists(siminfoDir))
                {
                    Directory.CreateDirectory(siminfoDir);
                }

                if (arglist.Contains("cache"))
                {
                    fileOnly = true;
                    PurgeCache();
                }
            }
            if (arglist.Contains("reset"))
            {
                slowlyExport.Clear();
                lock (ToDownloadAssets) ToDownloadAssets.Clear();
                lock (CompletedAssets) CompletedAssets.Clear();
                lock (PrimWaitingLinkset) PrimWaitingLinkset.Clear();
                lock (AllRelatedAssets) AllRelatedAssets.Clear();
                lock (PrimDepsAssets) PrimDepsAssets.Clear();
                lock (TaskAssetWaiting) TaskAssetWaiting.Clear();
                lock (CompletedTaskItem) CompletedTaskItem.Clear();
#if OBJECTUNPACKER
                lock (TasksRezed) TasksRezed.Clear();
#endif
                GiveStatus();
                return(Success("Reset SimExport State"));
            }

            if (fileOnly)
            {
                GiveStatus();
                return(Success("Manipulated filesystem"));
            }

            if (arglist.Contains("cleanup"))
            {
                return(CleanupAfterExport(fromAgentID, WriteLine));
            }
            if (arglist.Contains("killtasks"))
            {
                KillAllUnpacked(WriteLine, true);
                return(SuccessOrFailure());
            }
            IsExporting = true;
            FolderCalled("TaskInvHolder");
            //string file = args[args.Length - 1];
            int used;
            List <SimObject> PS = WorldSystem.GetPrimitives(nargs, out used);
            if (IsEmpty(PS))
            {
                return(Failure("Cannot find objects from " + string.Join(" ", args)));
            }
            showsStatus      = arglist.Contains("statu");
            showPermsOnly    = arglist.Contains("perm");
            skipPerms        = !arglist.Contains("obeyperm");
            showsMissingOnly = arglist.Contains("todo");
            if (showsMissingOnly)
            {
                quietly = true;
            }
            verbosely = arglist.Contains("verbose");
            if (verbosely && !arglist.Contains("quietly"))
            {
                quietly = false;
            }
            int missing   = 0;
            var canExport = new List <SimObject>();
            int objects   = 0;
            if (arglist.Contains("terrain"))
            {
                SaveTerrainHeight(arglist);
                StartTerrainDownload(arglist);
            }
            if (arglist.Contains("parcel"))
            {
                SaveParcelInfoCommand(arglist);
            }
            bool primsAtAll = arglist.Contains("link") || arglist.Contains("task") || arglist.Contains("llsd") ||
                              arglist.Contains("taskobj") || arglist.Contains("all");
            bool wasShouldBeMoving = shouldBeMoving;
            if (primsAtAll)
            {
                shouldBeMoving = false;
            }
            if (arglist.Contains("nobuf"))
            {
                PSBuf.Clear();
            }
            PSBuf.AddRange(PS);
            lock (Importing.MustExport)
            {
                foreach (UUID id in LockInfo.CopyOf(Importing.MustExport))
                {
                    var o = WorldObjects.GetSimObjectFromUUID(id);
                    if (o != null)
                    {
                        PSBuf.Add(o);
                    }
                }
            }

            foreach (var P in PSBuf)
            {
                if (!primsAtAll)
                {
                    break;
                }
                if (string.IsNullOrEmpty(IsComplete(P.ID, false, false, arglist)))
                {
                    continue;
                }
                // skip attachments and avatars
                if (IsSkipped(P, arglist))
                {
                    continue;
                }
                if (!P.HasPrim)
                {
                    if (!quietly)
                    {
                        Failure("Missing Prim: " + named(P));
                    }
                    continue;
                }
                if (P.RegionHandle != RegionHandle)
                {
                    continue;
                }

                Vector3 sp;
                if (!P.TryGetSimPosition(out sp))
                {
                    continue;
                }

                objects++;
                string issues = P.MissingData;
                if (!string.IsNullOrEmpty(issues) && !arglist.Allows(issues, P))
                {
                    missing++;
                    if (!quietly)
                    {
                        Failure("Issues " + issues + " " + named(P));
                    }
                    continue;
                }

                bool exportPossible =
                    checkPerms(Client, P, showPermsOnly ? (OutputDelegate)LocalFailure : SilientFailure, false) || skipPerms;
                if (exportPossible)
                {
                    SnagUsers(P);
                    canExport.Add(P);
                }
            }

            Success("Can export " + canExport.Count + " of " + objects);
            if (showPermsOnly)
            {
                return(Success("Shown perms"));
            }

            foreach (var P in canExport)
            {
                if (!primsAtAll)
                {
                    break;
                }
                if (P is SimAvatar)
                {
                    continue;
                }
                // skip attachments
                if (P.Parent is SimAvatar)
                {
                    continue;
                }
                string issues = P.MissingData;
                if (!string.IsNullOrEmpty(issues) && !arglist.Allows(issues, P))
                {
                    continue;
                }
                //if (exportedPrims.Contains(P)) continue;
                LocalFailures = 0;
                PrimDepsAssets.Clear();
                ExportPrim(Client, P, LocalFailure, arglist);
                if (P.IsRoot)
                {
                    float pSimPositionZ = P.SimPosition.Z;
                    if (pSimPositionZ > maxHeigth)
                    {
                        maxHeigth = pSimPositionZ + 10;
                    }
                    seenObjectsAt.AddPoint(P.SimPosition);
                }
                if (LocalFailures == 0)
                {
                    if (!successfullyExportedPrims.Contains(P))
                    {
                        successfullyExportedPrims.Add(P);
                    }
                }
            }
            ExportRelatedAssets();
            if (showsStatus)
            {
                arglist.Add("link");
                arglist.Add("task");
                arglist.Add("llsd");
            }

            if (arglist.Contains("link"))
            {
                // lock (PrimWaitingLinkset)
                {
                    foreach (var pa in LockInfo.CopyOf(PrimWaitingLinkset))
                    {
                        var exportPrim = pa.Value.O;
                        if (verbosely)
                        {
                            Failure("Awaiting Linkset " + named(exportPrim));
                        }
                        if (arglist.Contains("request"))
                        {
                            RequestLinksetInfo(Client, Path.Combine(dumpDir, exportPrim.ID.ToString()), exportPrim,
                                               WriteLine, arglist);
                        }
                    }
                }
            }

            if (arglist.Contains("task"))
            {
                lock (TaskAssetWaiting)
                {
                    foreach (var pa in LockInfo.CopyOf(TaskAssetWaiting))
                    {
                        UUID assetID = pa.Value.SourceItem.AssetUUID;
                        if (!CogbotHelpers.IsNullOrZero(assetID))
                        {
                            if (CompletedAssets.Contains(assetID))
                            {
                                int count = TaskAssetWaiting.Count;
                                TaskAssetWaiting.Remove(pa.Key);
                                if (TaskAssetWaiting.Count != count - 1)
                                {
                                    Failure("VERY BAD!");
                                }
                            }
                        }
                        if (verbosely)
                        {
                            Failure("Awaiting TaskAsset " + pa.Value);
                        }
                        if (arglist.Contains("request"))
                        {
                            pa.Value.Request();
                        }
                    }
                }
            }
            ExportRelatedAssets();
            foreach (var assetID in LockInfo.CopyOf(ToDownloadAssets))
            {
                PingAssetCache(assetID);
            }

            if (arglist.Contains("dl"))
            {
                foreach (var assetID in LockInfo.CopyOf(ToDownloadAssets))
                {
                    AssetType assetType = assetTypeOf(assetID);
                    if (verbosely)
                    {
                        Failure("Awaiting DL " + assetID + " " + assetType);
                    }
                    if (arglist.Contains("request"))
                    {
                        StartAssetDownload(null, assetID, assetType);
                    }
                }
            }
            if (arglist.Contains("user"))
            {
                RequestUsersAndGroups();
            }
            if (arglist.Contains("siprim"))
            {
                foreach (SimObject o in LockInfo.CopyOf(SIPrims))
                {
                    if (o.Prim.ParentID == 0)
                    {
                        Client.Inventory.RequestDeRezToInventory(o.LocalID, DeRezDestination.AgentInventoryCopy,
                                                                 FolderCalled("UseSIForCompleteness"), UUID.Random());
                    }
                    else
                    {
                        Failure("Child SIPrim " + o);
                    }
                }
            }
            Success("Missing PrimData: " + missing);
            Success("Started XFERS " + ToDownloadCalledAssets.Count + " assets");
            shouldBeMoving = wasShouldBeMoving;
            GiveStatus();
            if (primsAtAll)
            {
                shouldBeMoving = wasShouldBeMoving;
            }
            return(Success("Done"));
        }