text stringlengths 0 234 |
|---|
elsif Arg.Starts_With (Out_Option) then |
Path := Arg.Tail_From (Out_Option'Length + 1); |
elsif Arg.Starts_With (Dir_Option) then |
Input_Path := Arg.Tail_From (Dir_Option'Length + 1); |
elsif Arg.Starts_With (Help_Option) then |
Print_Help; |
elsif Arg.Starts_With (Log_Option) then |
Torrent.Logs.Initialize |
(Arg.Tail_From (Log_Option'Length + 1)); |
end if; |
end loop; |
end Parse_Command_Line; |
---------------- |
-- Print_Help -- |
---------------- |
procedure Print_Help is |
begin |
Ada.Wide_Wide_Text_IO.Put_Line ("Usage: torrent-run <options>"); |
Ada.Wide_Wide_Text_IO.Put_Line ("Options are"); |
Ada.Wide_Wide_Text_IO.Put_Line |
(" " & Port_Option & "int - a port to listen"); |
Ada.Wide_Wide_Text_IO.Put_Line |
(" " & Out_Option & "path - a directory to save downloaded files"); |
Ada.Wide_Wide_Text_IO.Put_Line |
(" " & Dir_Option & "path - a directory with torrent files"); |
Ada.Wide_Wide_Text_IO.Put_Line |
(" " & Log_Option & "path - a trace file, if you need it"); |
end Print_Help; |
begin |
if Cmd.Is_Empty then |
Print_Help; |
return; |
end if; |
League.Application.Set_Application_Name (+"Torrent Client"); |
League.Application.Set_Application_Version (+"0.1"); |
League.Application.Set_Organization_Name (+"Matreshka Project"); |
League.Application.Set_Organization_Domain (+"forge.ada-ru.org"); |
Parse_Command_Line; |
Each_Torrents (Input_Path, Increment_Total'Access); |
declare |
procedure Add (Item : Ada.Directories.Directory_Entry_Type); |
Recycle : aliased Torrent.Connections.Queues.Queue; |
Context : Torrent.Contexts.Context |
(Capacity => Total, |
Port => Port, |
Recycle => Recycle'Unchecked_Access); |
--------- |
-- Add -- |
--------- |
procedure Add (Item : Ada.Directories.Directory_Entry_Type) is |
Meta : constant Torrent.Metainfo_Files.Metainfo_File_Access := |
new Torrent.Metainfo_Files.Metainfo_File; |
begin |
Meta.Read |
(League.Strings.From_UTF_8_String |
(Ada.Directories.Full_Name (Item))); |
Context.Add_Metainfo_File (Meta); |
end Add; |
Peer_Id : Torrent.SHA1; |
Next_Update : Ada.Calendar.Time; |
begin |
Set_Peer_Id (Peer_Id); |
Context.Initialize (Peer_Id, Path); |
Each_Torrents (Input_Path, Add'Access); |
Context.Start (Next_Update); |
loop |
select |
Torrent.Shutdown.Signal.Wait_SIGINT; |
Ada.Wide_Wide_Text_IO.Put_Line ("Ctrl+C!"); |
exit; |
or |
delay until Next_Update; |
Context.Update (Next_Update); |
end select; |
end loop; |
Context.Stop; |
Function Definition: procedure Free is new Ada.Unchecked_Deallocation |
Function Body: (Torrent.Connections.Connection'Class, |
Torrent.Connections.Connection_Access); |
--------------- |
-- Initiator -- |
--------------- |
task body Initiator is |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.